Skip to main content

parse

Function parse 

Source
pub fn parse(s: &str) -> Result<CanFrame, ParseError>
Expand description

Parse a single GridConnect frame. Leading/trailing whitespace is ignored. Only extended (X) frames are meaningful for OpenLCB; standard (S) frames are rejected.

Letters are case-insensitive and R (remote frame) is accepted in place of N, though the RTR distinction is not kept. Identifiers longer than 29 bits are masked.

ยงErrors

  • ParseError::Format if the :/; delimiters, the X or the N are missing, or the frame is a standard frame.
  • ParseError::Hex for a non-hex digit.
  • ParseError::Length for an empty or over-long identifier, an odd number of data digits, or more than 8 data bytes.
use rolcb::{gridconnect, ParseError};

let f = gridconnect::parse("  :x195b4123n0501010122000010;\r\n")?;
assert_eq!(f.id, 0x195B_4123);
assert_eq!(gridconnect::parse(":S123N;"), Err(ParseError::Format("standard frame")));
assert_eq!(gridconnect::parse(":X195B4123N0;"), Err(ParseError::Length));