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![126, 1, 80, 0, 0, 0, 5, 128, 9, 126];
let chars = SpecialChars::default();

let result = encode(msg, chars);

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, 0x7D, 0x00, 0x05, 0x80, 0x09];
let cmp: Vec<u8> = vec![0x71, 1, 126, 112, 80, 125, 0, 5, 128, 9, 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![1, 80, 0, 0, 0, 5, 128, 9];

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

Enums

HDLCError

Common error for HDLC actions.

Constants

FEND

Sync byte that wraps the data packet

FESC

Substitution character

TFEND

Substituted for FEND

TFESC

Substituted for FESC

Functions

decode

Produces unescaped (decoded) message without FEND characters.

encode

Produces escaped (encoded) message surrounded with FEND