pub struct BitReader<'a> { /* private fields */ }Expand description
High-performance bit-level reader over a byte slice.
Uses safe unaligned 64-bit reads via u64::from_le_bytes for fast
bit extraction. Every read returns Result<T> with overflow checking.
Implementations§
Source§impl<'a> BitReader<'a>
impl<'a> BitReader<'a>
Sourcepub fn bits_remaining(&self) -> usize
pub fn bits_remaining(&self) -> usize
Number of bits between the cursor and the end of the buffer.
Sourcepub fn read_bits(&mut self, n: usize) -> Result<u64>
pub fn read_bits(&mut self, n: usize) -> Result<u64>
Read up to 64 bits. Returns the value right-aligned in a u64.
Sourcepub fn peek_bits(&self, n: usize) -> Result<u64>
pub fn peek_bits(&self, n: usize) -> Result<u64>
Peek at up to 64 bits without advancing the position.
Sourcepub fn read_bytes(&mut self, buf: &mut [u8]) -> Result<()>
pub fn read_bytes(&mut self, buf: &mut [u8]) -> Result<()>
Read N bytes into the provided buffer.
Sourcepub fn read_bits_to_bytes(&mut self, buf: &mut [u8], bits: usize) -> Result<()>
pub fn read_bits_to_bytes(&mut self, buf: &mut [u8], bits: usize) -> Result<()>
Read a specified number of bits into a byte buffer, filling LSB-first.
Sourcepub fn read_uvarint32(&mut self) -> Result<u32>
pub fn read_uvarint32(&mut self) -> Result<u32>
Read an unsigned varint (up to 32 bits).
Sourcepub fn read_uvarint64(&mut self) -> Result<u64>
pub fn read_uvarint64(&mut self) -> Result<u64>
Read an unsigned varint (up to 64 bits).
Sourcepub fn read_varint32(&mut self) -> Result<i32>
pub fn read_varint32(&mut self) -> Result<i32>
Read a signed varint (zigzag encoded, 32-bit).
Sourcepub fn read_varint64(&mut self) -> Result<i64>
pub fn read_varint64(&mut self) -> Result<i64>
Read a signed varint (zigzag encoded, 64-bit).
Sourcepub fn read_ubitvar(&mut self) -> Result<u32>
pub fn read_ubitvar(&mut self) -> Result<u32>
Valve’s variable-length unsigned integer encoding.
Reads 6 bits; bits 4-5 select the total width:
00 → 6 bits, 01 → 4+4, 10 → 4+8, 11 → 4+28.
Sourcepub fn read_ubitvarfp(&mut self) -> Result<u32>
pub fn read_ubitvarfp(&mut self) -> Result<u32>
Field-path variant of ubitvar — cascading 1-bit selectors.
Used exclusively for encoding field path operation indices: 2, 4, 10, 17, or 31 bits depending on which prefix bit is set.
Sourcepub fn read_bitcoord(&mut self) -> Result<f32>
pub fn read_bitcoord(&mut self) -> Result<f32>
Read a coordinate value.
Sourcepub fn read_bitnormal(&mut self) -> Result<f32>
pub fn read_bitnormal(&mut self) -> Result<f32>
Read a normal component (sign + 11-bit fraction).
Sourcepub fn read_bitvec3coord(&mut self) -> Result<[f32; 3]>
pub fn read_bitvec3coord(&mut self) -> Result<[f32; 3]>
Read a 3D coordinate vector.
Sourcepub fn read_bitvec3normal(&mut self) -> Result<[f32; 3]>
pub fn read_bitvec3normal(&mut self) -> Result<[f32; 3]>
Read a 3D normal vector (2 components + derived Z).
Sourcepub fn read_bitangle(&mut self, n: usize) -> Result<f32>
pub fn read_bitangle(&mut self, n: usize) -> Result<f32>
Read an angle encoded as N bits, returning degrees in [0, 360).
Sourcepub fn read_string(&mut self) -> Result<String>
pub fn read_string(&mut self) -> Result<String>
Read a null-terminated string.
Sourcepub fn read_string_into(&mut self, buf: &mut [u8]) -> Result<usize>
pub fn read_string_into(&mut self, buf: &mut [u8]) -> Result<usize>
Read a string into the provided buffer, returning bytes written (excluding null).
Sourcepub fn read_string_raw(&mut self, buf: &mut Vec<u8>) -> Result<usize>
pub fn read_string_raw(&mut self, buf: &mut Vec<u8>) -> Result<usize>
Read a string as raw bytes into a Vec, returning bytes written (excluding null).
Sourcepub fn skip_varint(&mut self) -> Result<()>
pub fn skip_varint(&mut self) -> Result<()>
Skip a varint without decoding it.
Sourcepub fn skip_bitcoord(&mut self) -> Result<()>
pub fn skip_bitcoord(&mut self) -> Result<()>
Skip a bitcoord value.
Sourcepub fn skip_bitnormal(&mut self) -> Result<()>
pub fn skip_bitnormal(&mut self) -> Result<()>
Skip a bitnormal value.
Sourcepub fn skip_bitvec3coord(&mut self) -> Result<()>
pub fn skip_bitvec3coord(&mut self) -> Result<()>
Skip a 3D coordinate vector.
Sourcepub fn skip_bitvec3normal(&mut self) -> Result<()>
pub fn skip_bitvec3normal(&mut self) -> Result<()>
Skip a 3D normal vector.
Sourcepub fn skip_string(&mut self) -> Result<()>
pub fn skip_string(&mut self) -> Result<()>
Skip a null-terminated string.