Skip to main content

ForwardBitWriter

Struct ForwardBitWriter 

Source
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

Source

pub fn new() -> Self

Create a new forward bitstream writer.

Source

pub fn with_capacity(byte_capacity: usize) -> Self

Create a new forward bitstream writer with a capacity hint.

Source

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.

Source

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

Write a single bit (0 or 1).

Source

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.

Source

pub fn bit_position(&self) -> usize

Current bit position (total number of bits written so far).

Source

pub fn byte_len(&self) -> usize

Current byte length of the output (not counting partial byte).

Source

pub fn is_empty(&self) -> bool

Whether no bits have been written yet.

Source

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

Get a reference to the bytes written so far (not including partial byte).

Trait Implementations§

Source§

impl Default for ForwardBitWriter

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.