Rust implementation of a High-level Data Link Control (HDLC) library with support of the IEEE standard.
Add hdlc
to Cargo.toml
toml
[dependencies]
hdlc = "^0.2.2"
or
toml
[dependencies.hdlc]
git = "https://github.com/CLomanno/hdlc"
Add this to crate root
rust
extern crate hdlc;
```rust extern crate hdlc; use hdlc::{SpecialChars, encode};
// Set up your vector of bytes and generate your Special Characters
let msg: Vec
// Encode your message let result = encode(&msg, SpecialChars::default());
assert!(result.isok()); asserteq!(result.unwrap(), cmp); ```
```rust extern crate hdlc; use hdlc::{SpecialChars, encode};
// Set up your vector of bytes and generate your Special Characters
let msg: Vec
// Encode your message let result = encode(&msg, chars);
assert!(result.isok()); asserteq!(result.unwrap(), cmp) ```
```rust extern crate hdlc; use hdlc::{SpecialChars, decode};
// Set up your vector of bytes and generate your Special Characters
let msg: Vec
// Decode your message let result = decode(&msg, chars);
assert!(result.isok()); asserteq!(result.unwrap(), cmp); ```
```rust extern crate hdlc; use hdlc::{SpecialChars, decode_slice};
// Set up your mutable slice of bytes and generate your Special Characters 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];
// Decode your slice let result = decode_slice(&mut msg, chars);
assert!(result.isok()); asserteq!(result.unwrap(), cmp); ```
Bencher is currently not available in Rust stable releases.
cargo bench
with 2.2 GHz Intel Core i7 results ~430MB/s throughput.
```rust cargo bench Running target\release\deps\bench-f7077ac294c24273.exe
running 4 tests test benchdecodemegabyte ... bench: 2,236,451 ns/iter (+/- 179,942) test benchdecodespecialchars2megabytes ... bench: 2,768,507 ns/iter (+/- 642,225) test benchencodemegabyte ... bench: 2,572,386 ns/iter (+/- 582,359) test benchencodespecialchars_megabyte ... bench: 6,010,429 ns/iter (+/- 1,087,538)
test result: ok. 0 passed; 0 failed; 0 ignored; 4 measured; 0 filtered out ```
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.