pub struct BitWriter { /* private fields */ }Expand description
MSB-first bit writer over an internal byte buffer.
Implementations§
Source§impl BitWriter
impl BitWriter
pub fn new() -> Self
pub fn with_capacity(cap: usize) -> Self
Sourcepub fn bit_position(&self) -> u64
pub fn bit_position(&self) -> u64
Total bits written so far (including any in the unflushed accumulator).
Sourcepub fn byte_len(&self) -> usize
pub fn byte_len(&self) -> usize
Bytes of output produced so far (excluding any unflushed partial byte).
Sourcepub fn is_byte_aligned(&self) -> bool
pub fn is_byte_aligned(&self) -> bool
True if the writer is currently on a byte boundary.
Sourcepub fn write_u32(&mut self, value: u32, n: u32)
pub fn write_u32(&mut self, value: u32, n: u32)
Append n bits (0..=32) from the low n bits of value, MSB first.
Sourcepub fn write_bits(&mut self, value: u32, n: u32)
pub fn write_bits(&mut self, value: u32, n: u32)
Alias of Self::write_u32 — some codec crates historically
spell this write_bits.
Sourcepub fn write_i32(&mut self, value: i32, n: u32)
pub fn write_i32(&mut self, value: i32, n: u32)
Append n bits interpreted as a signed integer. Only the low
n bits of the 2’s-complement representation are written.
pub fn write_bit(&mut self, bit: bool)
Sourcepub fn write_unary(&mut self, n: u32)
pub fn write_unary(&mut self, n: u32)
Emit a unary-coded value: n zero bits followed by a single 1.
Inverse of BitReader::read_unary.
pub fn write_byte(&mut self, b: u8)
Sourcepub fn write_bytes(&mut self, bytes: &[u8])
pub fn write_bytes(&mut self, bytes: &[u8])
Append a slice of bytes. Fast path when byte-aligned.
Sourcepub fn align_to_byte(&mut self)
pub fn align_to_byte(&mut self)
Pad to the next byte boundary with zero bits.
Sourcepub fn align_to_byte_zero(&mut self)
pub fn align_to_byte_zero(&mut self)
Alias of Self::align_to_byte — MPEG-4 video spells it
align_to_byte_zero since the spec also defines alternate
align-with-ones tails in other contexts.
Sourcepub fn bytes(&self) -> &[u8] ⓘ
pub fn bytes(&self) -> &[u8] ⓘ
Borrow the bytes accumulated so far (excluding any unflushed partial byte).
Sourcepub fn buffer(&self) -> &[u8] ⓘ
pub fn buffer(&self) -> &[u8] ⓘ
Alias of Self::bytes — some codec crates spell this buffer.
Sourcepub fn finish(self) -> Vec<u8> ⓘ
pub fn finish(self) -> Vec<u8> ⓘ
Pad with zero bits to the next byte boundary, then return the bytes.
Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
Alias of Self::finish — some codec crates spell this into_bytes.