[][src]Function hdlc::decode

pub fn decode(input: &[u8], s_chars: SpecialChars) -> Result<Vec<u8>, HDLCError>

Produces unescaped (decoded) message without FEND characters.

Inputs

  • Vec: A vector of the bytes you want to decode
  • SpecialChars: The special characters you want to swap

Output

  • Result<Vec>: 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 a tfend or a tfesc.
  • HDLCError::MissingFirstFend: Input vector is missing a first SpecialChars::fend
  • 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 input: Vec<u8> = vec![ 0x7E, 0x01, 0x50, 0x00, 0x00, 0x00, 0x05, 0x80, 0x09, 0x7E];
let op_vec = hdlc::decode(&input.to_vec(), chars);