Function encode

Source
pub fn encode(data: &[u8], s_chars: SpecialChars) -> Result<Vec<u8>, HDLCError>
Expand description

Produces escaped (encoded) message surrounded with FEND

§Inputs

  • Vec<u8>: A vector of the bytes you want to encode
  • SpecialChars: The special characters you want to swap

§Output

  • Result<Vec<u8>>: Encoded output message

§Error

  • HDLCError::DuplicateSpecialChar: Checks special characters for duplicates, if any of the SpecialChars are duplicate, throw an error. Displays “Duplicate special character”.

§Todo

Catch more errors, like an incomplete packet

§Example

let chars = hdlc::SpecialChars::default();
let input: Vec<u8> = vec![0x01, 0x50, 0x00, 0x00, 0x00, 0x05, 0x80, 0x09];
let op_vec = hdlc::encode(&input.to_vec(), chars);