Crate bitstream_io [] [src]

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 BufRead 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, but others can be added with minimal effort.

Type Sizes

Because both the type sizes and bit counts are variable, it is the responsibity of the programmer to ensure that the capacity of one's variables does not exceed the requested bit count when reading or writing. Otherwise, an overflow error panic may occur.

For example, reading 8 bits from the stream to a 32-bit variable is harmless (the topmost 24 bits are left empty), but reading 32 bits from the stream to an 8-bit variable may result in a panic. Similarly, writing a 32-bit variable to 8 bits is also harmless (the topmost 24 bits are ignored), but writing an 8-bit variable to 32 bits in the stream may cause a panic.

Reexports

pub use read::BitRead;
pub use read::BitReaderBE;
pub use read::BitReaderLE;
pub use write::BitWrite;
pub use write::BitWriterBE;
pub use write::BitWriterLE;

Modules

read

Traits and implementations for reading bits from a stream.

write

Traits and implementations for writing bits to a stream.

Structs

BitQueueBE

A wrapper around some unsigned type to turn it into a big-endian queue.

BitQueueLE

A wrapper around some unsigned type to turn it into a little-endian queue.

Traits

BitQueue

This trait is for treating numeric types as a queue of bits which values can be pushed to and popped from in order to implement bitstream readers and writers.

Numeric

This trait extends many common integer types (both unsigned and signed) with a few trivial methods so that they can be used with the bitstream handling traits.

SignedNumeric

This trait extends many common signed integer types so that they can be used with the bitstream handling traits.