Function hdlc::decode_slice [−][src]
pub fn decode_slice(
input: &mut [u8],
s_chars: SpecialChars
) -> Result<&[u8], HDLCError>
Produces slice (&[u8]
) unescaped (decoded) message without FEND
characters.
Inputs
- &mut u8: A mutable slice of the bytes you want to decode
- SpecialChars: The special characters you want to swap
Output
- Result<&u8>: Decoded output message
Error
- HDLCError::DuplicateSpecialChar: Checks special characters for duplicates, if any of
the
SpecialChars
are duplicate, throw an error. Displays "Duplicate special character". - HDLCError::FendCharInData: Checks to make sure the full decoded message is the full
length. Found the
SpecialChars::fend
inside the message. - HDLCError::MissingTradeChar: Checks to make sure every frame escape character
fesc
is followed by either atfend
or atfesc
. - HDLCError::MissingFinalFend: Input vector is missing a final
SpecialChars::fend
Todo
Catch more errors, like an incomplete packet
Example
extern crate hdlc; let chars = hdlc::SpecialChars::default(); let mut input = [ 0x7E, 0x01, 0x50, 0x00, 0x00, 0x00, 0x05, 0x80, 0x09, 0x7E]; let op_vec = hdlc::decode_slice(&mut input, chars);