bin-proto
Simple and fast bit-level protocol definitions in Rust.
An improved and modernized fork of protocol. A more efficient but (slightly) less feature-rich alternative to deku.
This crate adds a trait (and a custom derive for ease-of-use) that can be
implemented on types, allowing structured data to be sent and received from any
binary stream. It is recommended to use
bitstream_io if you need
bit streams, as their BitRead and BitWrite traits are being used internally.
Example
Add this to your Cargo.toml:
[]
= "0.2"
And then define a type with the #[derive(bin_proto::Protocol)] attribute.
use Protocol;
assert_eq!;
You can implement Protocol on your own types, and parse with context:
use Protocol;
;
;
Performance / Alternatives
This crate's main alternative is deku, and binrw for byte-level protocols.
bin-proto is significantly faster than deku in all of the tested scenarios.
The units for the below table are ns/iter, taken from
github CI.
You can find the benchmarks in the bench directory.
Read enum |
Write enum |
Read Vec |
Write Vec |
Read IPv4 header | Write IPv4 header | |
|---|---|---|---|---|---|---|
bin-proto |
28 | 100 | 1,374 | 1,679 | 174 | 208 |
deku |
67 | 226 | 2,963 | 9,296 | 2,734 | 1,013 |
Roadmap
The following features are planned:
no_stdsupport- bit/byte alignment