pub struct BackwardBitWriter { /* private fields */ }Expand description
Backward bitstream writer for FSE sequence encoding.
Produces a byte array compatible with the FseBitReader:
- The last byte contains a sentinel (highest set bit) and the first data bits.
- Preceding bytes contain subsequent data bits, with byte at index N-2 being read after the sentinel byte, N-3 after that, etc.
The encoder writes bits in the same order the decoder reads them (first written = first decoded).
Internally, bits are accumulated into a Vec<u8> from MSB of the highest
byte down to LSB of byte 0. At finish(), a sentinel is added and the
output is ready for the decoder.
Implementations§
Source§impl BackwardBitWriter
impl BackwardBitWriter
Sourcepub fn with_capacity(byte_capacity: usize) -> Self
pub fn with_capacity(byte_capacity: usize) -> Self
Create a new backward bitstream writer with a capacity hint.
Sourcepub fn write_bits(&mut self, value: u64, num_bits: u8)
pub fn write_bits(&mut self, value: u64, num_bits: u8)
Write num_bits bits from value into the backward stream.
The lowest num_bits bits of value are appended. The first call’s
bits will be the first bits the decoder reads.
Sourcepub fn finish(self) -> Vec<u8> ⓘ
pub fn finish(self) -> Vec<u8> ⓘ
Finalize the backward bitstream.
Produces a byte array where:
- The last byte contains the sentinel and the first data bits.
- Preceding bytes (read from index N-2 down to 0) contain later data bits.
The FseBitReader loads the sentinel byte’s data bits first (into the
accumulator’s LSB), then loads byte N-2, N-3, …, 0 into successively
higher accumulator positions.
Returns the finalized byte vector. If no bits were written, returns [0x01].