Crate hdlc[][src]

hdlc

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);

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 FEND characters.

encode

Produces escaped (encoded) message surrounded with FEND