bits-io
bits-io provides types which mimic those in std::io
except which operate on
the bit level instead of the byte level.
BitCursor
Mimics std::io::Cursor
but tracks a bit-level position instead of a
byte-level position. In addition to the standard Seek
implementation which
allows seeking by a number of bytes, it also provides BitSeek
which allows
seeking by a number of bits.
let data: = vec!
BitRead
BitRead
mimics the
std::io::Read
trait, but
its API is defined in terms of reading from "bit slices" instead of u8
slices
(&[u8]
) like std::io::Read
. It leverages the BitSlice
type defined in
the bitvec crate.
BitWrite
BitWrite
mimics the
std::io::Read
trait, but
its API is defined in terms of reading from "bit slices" instead of u8
slices
(&[u8]
) like std::io::Read
. It leverages the BitSlice
type defined in
the bitvec crate.
BitCursor is similar to std::io::Cursor, but allows reading non-standard-width types (e.g. u3, u7, u14) from a given buffer in addition to byte-sized chunks. It's built on top of the nsw_types crate for non-standard-width types and leverages bitvec to provide a more complete implementation.
Examples
let data: = vec!;
let mut cursor = from_vec;
// Read any non-standard-width type from the cursor
let u3_val = cursor.read_u3.unwrap;
assert_eq!;
// Sizes larger than 8 bits require a byte order argument
let u13_val = cursor
.
.unwrap;
assert_eq!;
Design
Traits
Types
BitCursor
BitCursor
is analogous to the std::io::Cursor
type, but its API is defined in terms of bits instead of bytes.