pub struct BitReader<'a> { /* private fields */ }Expand description
MSB-first bit unpacker over a borrowed byte slice.
Implementations§
Source§impl<'a> BitReader<'a>
impl<'a> BitReader<'a>
Sourcepub fn new(bytes: &'a [u8]) -> Self
pub fn new(bytes: &'a [u8]) -> Self
Reader that consumes exactly bytes.len() * 8 bits (used by tests
where the bit count is byte-aligned).
Sourcepub fn with_bit_limit(bytes: &'a [u8], bit_limit: usize) -> Self
pub fn with_bit_limit(bytes: &'a [u8], bit_limit: usize) -> Self
Reader that consumes at most bit_limit bits — required when the
payload’s exact bit length is shorter than the byte buffer (zero-padding).
Per spec §3.7, the TLV section ends when total bits are exhausted; the
decoder must know bit_limit to avoid reading padding bits as TLV data.
Sourcepub fn read_bits(&mut self, count: usize) -> Result<u64, Error>
pub fn read_bits(&mut self, count: usize) -> Result<u64, Error>
Read count bits MSB-first; returns the value LSB-aligned.
Sourcepub fn remaining_bits(&self) -> usize
pub fn remaining_bits(&self) -> usize
Bits remaining unread (within the configured bit limit).
Sourcepub fn is_exhausted(&self) -> bool
pub fn is_exhausted(&self) -> bool
Whether the stream is exhausted.
Sourcepub fn save_position(&self) -> usize
pub fn save_position(&self) -> usize
Snapshot the current bit position for rollback. Used by the TLV decoder loop to handle graceful end-of-stream when trailing codex32-padding bits look like a partial TLV.
Sourcepub fn restore_position(&mut self, saved: usize)
pub fn restore_position(&mut self, saved: usize)
Restore a previously saved bit position.