[−][src]Crate hdlc
hdlc
Only frames the data. Rust implementation of a High-level Data Link Control (HDLC) library with support of the IEEE standard.
Usage
Encode packet
extern crate hdlc; use hdlc::{SpecialChars, encode}; let msg: Vec<u8> = vec![0x01, 0x50, 0x00, 0x00, 0x00, 0x05, 0x80, 0x09]; let cmp: Vec<u8> = vec![0x7E, 0x01, 0x50, 0x00, 0x00, 0x00, 0x05, 0x80, 0x09, 0x7E]; let result = encode(&msg, SpecialChars::default()); assert!(result.is_ok()); assert_eq!(result.unwrap(), cmp);
Custom Special Characters
extern crate hdlc; use hdlc::{SpecialChars, encode}; let msg: Vec<u8> = vec![0x01, 0x7E, 0x70, 0x50, 0x00, 0x05, 0x80, 0x09]; let cmp: Vec<u8> = vec![0x71, 0x01, 0x7E, 0x70, 0x50, 0x50, 0x00, 0x05, 0x80, 0x09, 0x71]; let chars = SpecialChars::new(0x71, 0x70, 0x51, 0x50); let result = encode(&msg, chars); assert!(result.is_ok()); assert_eq!(result.unwrap(), cmp)
Decode packet
extern crate hdlc; use hdlc::{SpecialChars, decode}; let chars = SpecialChars::default(); let msg: Vec<u8> = vec![ chars.fend, 0x01, 0x50, 0x00, 0x00, 0x00, 0x05, 0x80, 0x09, chars.fend, ]; let cmp: Vec<u8> = vec![0x01, 0x50, 0x00, 0x00, 0x00, 0x05, 0x80, 0x09]; let result = decode(&msg, chars); assert!(result.is_ok()); assert_eq!(result.unwrap(), cmp);
Decode slice packet
extern crate hdlc; use hdlc::{SpecialChars, decode_slice}; let chars = SpecialChars::default(); let mut msg = [ chars.fend, 0x01, 0x50, 0x00, 0x00, 0x00, 0x05, 0x80, 0x09, chars.fend, ]; let cmp = [0x01, 0x50, 0x00, 0x00, 0x00, 0x05, 0x80, 0x09]; let result = decode_slice(&mut msg, chars); assert!(result.is_ok()); assert_eq!(result.unwrap(), cmp);
Structs
SpecialChars | Special Character structure for holding the encode and decode values. IEEE standard values are defined below in Default. |
Enums
HDLCError | Common error for HDLC actions. |
Functions
decode | Produces unescaped (decoded) message without |
decode_slice | Produces slice ( |
encode | Produces escaped (encoded) message surrounded with |