Expand description
§hdlc
Frames the data or parses a frame. Rust implementation of a High-level Data Link Control (HDLC) library with support of the IEEE standard.
§Usage
§Encode packet
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
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
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
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§
- Frame
Reader - A struct representing a reader for HDLC frames.
It reads data from a source that implements the
std::io::Read
trait. The reader can be used to read frames from a stream of bytes. It will ignore the first bytes until the start of a frame. - Special
Chars - Special Character structure for holding the encode and decode values. IEEE standard values are defined below in Default.
Enums§
- HDLC
Error - Common error for HDLC actions.
Functions§
- decode
- Produces unescaped (decoded) message without
FEND
characters. - decode_
slice - Produces slice (
&[u8]
) unescaped (decoded) message withoutFEND
characters. - encode
- Produces escaped (encoded) message surrounded with
FEND