Skip to main content

BitWriter

Struct BitWriter 

Source
pub struct BitWriter { /* private fields */ }
Expand description

MSB-first bit writer over an internal byte buffer.

Implementations§

Source§

impl BitWriter

Source

pub fn new() -> Self

Source

pub fn with_capacity(cap: usize) -> Self

Source

pub fn bit_position(&self) -> u64

Total bits written so far (including any in the unflushed accumulator).

Source

pub fn byte_len(&self) -> usize

Bytes of output produced so far (excluding any unflushed partial byte).

Source

pub fn is_byte_aligned(&self) -> bool

True if the writer is currently on a byte boundary.

Source

pub fn write_u32(&mut self, value: u32, n: u32)

Append n bits (0..=32) from the low n bits of value, MSB first.

Source

pub fn write_bits(&mut self, value: u32, n: u32)

Alias of Self::write_u32 — some codec crates historically spell this write_bits.

Source

pub fn write_u64(&mut self, value: u64, n: u32)

Append up to 64 bits.

Source

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.

Source

pub fn write_bit(&mut self, bit: bool)

Source

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.

Source

pub fn write_byte(&mut self, b: u8)

Source

pub fn write_bytes(&mut self, bytes: &[u8])

Append a slice of bytes. Fast path when byte-aligned.

Source

pub fn align_to_byte(&mut self)

Pad to the next byte boundary with zero bits.

Source

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.

Source

pub fn bytes(&self) -> &[u8]

Borrow the bytes accumulated so far (excluding any unflushed partial byte).

Source

pub fn buffer(&self) -> &[u8]

Alias of Self::bytes — some codec crates spell this buffer.

Source

pub fn finish(self) -> Vec<u8>

Pad with zero bits to the next byte boundary, then return the bytes.

Source

pub fn into_bytes(self) -> Vec<u8>

Alias of Self::finish — some codec crates spell this into_bytes.

Trait Implementations§

Source§

impl Default for BitWriter

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.