bin-proto
Simple & fast structured bit-level binary co/dec 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.3"
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 | 110 | 1,293 | 1,261 | 165 | 163 |
deku |
68 | 324 | 3,042 | 9,178 | 2,580 | 696 |
Roadmap
The following features are planned:
- Bit/byte alignment
- Better derive macro error messages
no_stdsupport (only afterbitstream_iosupports it)