pub struct BitReader<'a> { /* private fields */ }Expand description
A cursor over a byte slice that reads fields LSB-first at the bit level.
Created with BitReader::new, consumed with read_* methods. Tracks
a byte position and a sub-byte bit offset, plus a recursion depth counter
for safely decoding recursive types.
Sub-byte reads pull individual bits from the current byte. Multi-byte reads
(e.g. read_u16) first align to the next byte boundary,
then interpret the bytes as little-endian.
Implementations§
Source§impl<'a> BitReader<'a>
impl<'a> BitReader<'a>
Sourcepub fn read_bits(&mut self, count: u8) -> Result<u64, DecodeError>
pub fn read_bits(&mut self, count: u8) -> Result<u64, DecodeError>
Read count bits LSB-first into a u64.
Sourcepub fn read_bool(&mut self) -> Result<bool, DecodeError>
pub fn read_bool(&mut self) -> Result<bool, DecodeError>
Read a single bit as bool.
Sourcepub fn flush_to_byte_boundary(&mut self)
pub fn flush_to_byte_boundary(&mut self)
Advance to the next byte boundary, discarding any remaining bits in the current byte. Infallible.
Sourcepub fn read_u8(&mut self) -> Result<u8, DecodeError>
pub fn read_u8(&mut self) -> Result<u8, DecodeError>
Read a u8, aligning to a byte boundary first.
Sourcepub fn read_u16(&mut self) -> Result<u16, DecodeError>
pub fn read_u16(&mut self) -> Result<u16, DecodeError>
Read a little-endian u16, aligning to a byte boundary first.
Sourcepub fn read_u32(&mut self) -> Result<u32, DecodeError>
pub fn read_u32(&mut self) -> Result<u32, DecodeError>
Read a little-endian u32, aligning to a byte boundary first.
Sourcepub fn read_u64(&mut self) -> Result<u64, DecodeError>
pub fn read_u64(&mut self) -> Result<u64, DecodeError>
Read a little-endian u64, aligning to a byte boundary first.
Sourcepub fn read_i8(&mut self) -> Result<i8, DecodeError>
pub fn read_i8(&mut self) -> Result<i8, DecodeError>
Read an i8, aligning to a byte boundary first.
Sourcepub fn read_i16(&mut self) -> Result<i16, DecodeError>
pub fn read_i16(&mut self) -> Result<i16, DecodeError>
Read a little-endian i16, aligning to a byte boundary first.
Sourcepub fn read_i32(&mut self) -> Result<i32, DecodeError>
pub fn read_i32(&mut self) -> Result<i32, DecodeError>
Read a little-endian i32, aligning to a byte boundary first.
Sourcepub fn read_i64(&mut self) -> Result<i64, DecodeError>
pub fn read_i64(&mut self) -> Result<i64, DecodeError>
Read a little-endian i64, aligning to a byte boundary first.
Sourcepub fn read_f32(&mut self) -> Result<f32, DecodeError>
pub fn read_f32(&mut self) -> Result<f32, DecodeError>
Read a little-endian f32, aligning to a byte boundary first.
Sourcepub fn read_f64(&mut self) -> Result<f64, DecodeError>
pub fn read_f64(&mut self) -> Result<f64, DecodeError>
Read a little-endian f64, aligning to a byte boundary first.
Sourcepub fn read_leb128(&mut self, max_bytes: u8) -> Result<u64, DecodeError>
pub fn read_leb128(&mut self, max_bytes: u8) -> Result<u64, DecodeError>
Read a LEB128-encoded u64, consuming at most max_bytes bytes.
Sourcepub fn read_zigzag(
&mut self,
_type_bits: u8,
max_bytes: u8,
) -> Result<i64, DecodeError>
pub fn read_zigzag( &mut self, _type_bits: u8, max_bytes: u8, ) -> Result<i64, DecodeError>
Read a ZigZag + LEB128 encoded signed integer.
Sourcepub fn read_string(&mut self) -> Result<String, DecodeError>
pub fn read_string(&mut self) -> Result<String, DecodeError>
Read a length-prefixed UTF-8 string.
Sourcepub fn read_bytes(&mut self) -> Result<Vec<u8>, DecodeError>
pub fn read_bytes(&mut self) -> Result<Vec<u8>, DecodeError>
Read a length-prefixed byte vector.
Sourcepub fn read_raw_bytes(&mut self, len: usize) -> Result<Vec<u8>, DecodeError>
pub fn read_raw_bytes(&mut self, len: usize) -> Result<Vec<u8>, DecodeError>
Read exactly len raw bytes with no length prefix.
Sourcepub fn read_remaining(&mut self) -> Vec<u8> ⓘ
pub fn read_remaining(&mut self) -> Vec<u8> ⓘ
Read all remaining bytes from the current position to the end. Flushes to byte boundary first. Returns an empty Vec if no bytes remain.
Sourcepub fn enter_recursive(&mut self) -> Result<(), DecodeError>
pub fn enter_recursive(&mut self) -> Result<(), DecodeError>
Increment recursion depth; return error if limit exceeded.
Sourcepub fn leave_recursive(&mut self)
pub fn leave_recursive(&mut self)
Decrement recursion depth.