[−][src]Function hdlc::encode
pub fn encode(
data: &Vec<u8>,
s_chars: SpecialChars
) -> Result<Vec<u8>, 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<Vec
> : 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
extern crate hdlc; 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);