pub fn decode(frame: &[u8], output: &mut [u8]) -> Result<usize, SerialError>Expand description
Decodes a single SLIP frame, recovering the original payload.
A leading END (RFC 1055’s flush byte) and any empty run before the payload are
skipped; decoding stops at the END that closes the frame, or at the end of the
slice if it carries no trailing delimiter.
§Arguments
frame- the framed bytes, with or without the trailingEND.output- the buffer the payload is written into; it never needs more room thanframe.
§Returns
The number of payload bytes written to output.
§Errors
Returns SerialError::InvalidEscape if an ESC is followed by an unexpected byte,
SerialError::TruncatedFrame if the frame ends in the middle of an escape sequence,
and SerialError::BufferTooSmall if output cannot hold the payload.
§Examples
use pamoja_serial::slip::{self, END};
let mut payload = [0u8; 4];
// A leading END is tolerated and the trailing one closes the frame.
let n = slip::decode(&[END, b'h', b'i', END], &mut payload)?;
assert_eq!(&payload[..n], b"hi");