serialplugin_core/cmux/path.rs
1//! Composite path helpers for CMUX virtual channels.
2
3/// Build a managed virtual port path for `dlci` on `physical`.
4pub fn mux_path(physical: &str, dlci: u8) -> String {
5 format!("{physical}#dlci={dlci}")
6}
7
8/// Data DLCIs are 1..=63 (6-bit address field; 0 is the control channel).
9pub fn is_data_dlci(dlci: u8) -> bool {
10 (1..=63).contains(&dlci)
11}
12
13/// Parse `physical#dlci=N` → `(physical, dlci)`.
14pub fn parse_mux_path(path: &str) -> Option<(&str, u8)> {
15 let (base, dlci_str) = path.rsplit_once("#dlci=")?;
16 dlci_str
17 .parse()
18 .ok()
19 .filter(|&d| is_data_dlci(d))
20 .map(|dlci| (base, dlci))
21}