#little-endian #big-endian #bitstream #endian #read-write #binary

bitstream-io

Library for reading/writing un-aligned values from/to streams in big-endian and little-endian formats

33 releases (14 stable)

2.2.0 Dec 12, 2023
1.10.0 Nov 27, 2023
1.7.0 Jul 5, 2023
1.6.0 Nov 17, 2022
0.6.1 Mar 27, 2017

#73 in Encoding

Download history 13893/week @ 2023-11-27 10367/week @ 2023-12-04 13829/week @ 2023-12-11 13439/week @ 2023-12-18 6730/week @ 2023-12-25 10569/week @ 2024-01-01 14240/week @ 2024-01-08 11195/week @ 2024-01-15 14408/week @ 2024-01-22 12471/week @ 2024-01-29 13333/week @ 2024-02-05 13002/week @ 2024-02-12 14164/week @ 2024-02-19 13345/week @ 2024-02-26 14283/week @ 2024-03-04 11608/week @ 2024-03-11

54,343 downloads per month
Used in 82 crates (40 directly)

MIT/Apache

130KB
2K SLoC

bitstream-io

A Rust library for reading or writing binary values to or from streams which may not be aligned at a whole byte.

This library is intended to be flexible enough to wrap around any stream which implements the Read or Write traits. It also supports a wide array of integer data types as containers for those binary values.

Documentation


lib.rs:

Traits and helpers for bitstream handling functionality

Bitstream readers are for reading signed and unsigned integer values from a stream whose sizes may not be whole bytes. Bitstream writers are for writing signed and unsigned integer values to a stream, also potentially un-aligned at a whole byte.

Both big-endian and little-endian streams are supported.

The only requirement for wrapped reader streams is that they must implement the Read trait, and the only requirement for writer streams is that they must implement the Write trait.

In addition, reader streams do not consume any more bytes from the underlying reader than necessary, buffering only a single partial byte as needed. Writer streams also write out all whole bytes as they are accumulated.

Readers and writers are also designed to work with integer types of any possible size. Many of Rust's built-in integer types are supported by default.

Migrating From Pre 1.0.0

There are now BitRead and BitWrite traits for bitstream reading and writing (analogous to the standard library's Read and Write traits) which you will also need to import. The upside to this approach is that library consumers can now make functions and methods generic over any sort of bit reader or bit writer, regardless of the underlying stream byte source or endianness.

No runtime deps