[][src]Function sensirion_hdlc::encode

pub fn encode(
    data: &[u8],
    s_chars: SpecialChars
) -> Result<ArrayVec<[u8; 1024]>, HDLCError>

Produces escaped (encoded) message surrounded with FEND

Inputs

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

Output

  • Result<ArrayVec<u8;1024>>: Encoded output message

Error

  • HDLCError::TooMuchData: More than 260 bytes to be encoded

Example

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