pub struct ForwardBitWriter { /* private fields */ }Expand description
Forward bitstream writer (LSB first).
Used for writing FSE table descriptions, various headers, and other forward-direction bitstream data in Zstandard frames.
Bits are packed into bytes starting from the least significant bit. When a byte is full, it is flushed to the output buffer and the accumulator resets.
Implementations§
Source§impl ForwardBitWriter
impl ForwardBitWriter
Sourcepub fn with_capacity(byte_capacity: usize) -> Self
pub fn with_capacity(byte_capacity: usize) -> Self
Create a new forward bitstream writer with a capacity hint.
Sourcepub fn write_bits(&mut self, value: u32, num_bits: u8)
pub fn write_bits(&mut self, value: u32, num_bits: u8)
Write num_bits bits from value (LSB first, up to 25 bits).
The lowest num_bits bits of value are written to the stream.
Bits are packed into bytes starting from the least significant bit.
§Panics
Panics if num_bits exceeds 25.
Sourcepub fn finish(self) -> Vec<u8> ⓘ
pub fn finish(self) -> Vec<u8> ⓘ
Flush remaining bits, padding with zeros to the next byte boundary.
Consumes the writer and returns the accumulated output bytes. If there are any pending bits that do not fill a complete byte, they are padded with zeros in the high bits.
Sourcepub fn bit_position(&self) -> usize
pub fn bit_position(&self) -> usize
Current bit position (total number of bits written so far).