bitbuffer
Tools for reading and writing data types of arbitrary bit length and might not be byte-aligned in the source data
The main way of reading the binary data is to first create a BitReadBuffer
,wrap it into a BitReadStream and then read from the stream.
Once you have a BitStream, there are 2 different approaches of reading data
- read primitives, Strings and byte arrays, using
read_bool,read_int,read_float,read_bytesandread_string - read any type implementing the
BitReadorBitReadSizedtraits usingreadandread_sizedBitReadis for types that can be read without requiring any size info (e.g. null-terminal strings, floats, whole integers, etc)BitReadSizedis for types that require external sizing information to be read (fixed length strings, arbitrary length integers
The BitRead and BitReadSized traits can be used with #[derive] if all
fields implement BitRead or BitReadSized.
For writing the data you wrap the output Vec into a BitWriteStream which can
then be used in a manner similar to the BitReadStream
- write primitives, Strings and byte arrays, using
write_bool,write_int,write_float,write_bytesandwrite_string - write any type implementing the
BitWriteorBitWriteSizedtraits usingwriteandwrite_sizedBitWriteis for types that can be written without requiring any size info (e.g. null-terminal strings, floats, whole integers, etc)BitWriteSizedis for types that require external sizing information to be written (fixed length strings, arbitrary length integers
Just like the read counterparts, BitWrite and BitWriteSized traits can be
used with #[derive] if all fields implement BitWrite or BitWriteSized.
Examples
use ;
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Contribution
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.