pub struct BitWriter { /* private fields */ }Expand description
A most-significant-bit-first bit writer.
AV1 uncompressed headers and OBU framing are described with f(n) fixed-width fields that a
decoder reads most-significant-bit first (AV1 §8.1, “Parsing process for f(n)”); this writer
is the encoder-side mirror. Bits accumulate into an internal byte buffer; the buffer is byte
aligned exactly when BitWriter::is_byte_aligned returns true.
Implementations§
Source§impl BitWriter
impl BitWriter
Sourcepub fn put_bit(&mut self, bit: u8)
pub fn put_bit(&mut self, bit: u8)
Writes a single bit (f(1)); only the low bit of bit is used.
Sourcepub fn put_bits(&mut self, value: u32, n: u32)
pub fn put_bits(&mut self, value: u32, n: u32)
Writes the low n bits of value, most-significant bit first (f(n)). n must be 0..=32.
Sourcepub fn is_byte_aligned(&self) -> bool
pub fn is_byte_aligned(&self) -> bool
Returns true when the next bit would start a fresh byte.
Sourcepub fn byte_align(&mut self)
pub fn byte_align(&mut self)
Pads with zero bits up to the next byte boundary (a no-op when already aligned).
Sourcepub fn put_bytes(&mut self, data: &[u8])
pub fn put_bytes(&mut self, data: &[u8])
Appends whole bytes verbatim. Requires the writer to be byte aligned.
§Panics
Debug builds assert byte alignment; misuse in release silently misaligns the stream.
Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
Consumes the writer, returning the byte buffer (trailing bits in the final partial byte are zero-filled).