Skip to main content

BitWriter

Struct BitWriter 

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

MSB-first bit writer accumulating into an owned Vec<u8>.

Implementations§

Source§

impl BitWriter

Source

pub fn new() -> Self

Create an empty writer.

Source

pub fn bit_pos(&self) -> usize

Number of bits written so far.

Source

pub fn byte_aligned(&self) -> bool

True if the next write would start on a byte boundary.

Source

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

Append a single bit (only bit 0 of bit is used).

Source

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

Write the low n bits of value MSB-first. n must be ≤ 32; bits above bit n-1 of value are ignored.

Source

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

Write the low n bits of a u64 MSB-first. n must be ≤ 64.

Source

pub fn write_ue(&mut self, value: u32) -> Result<(), BitstreamError>

Write an unsigned Exp-Golomb (ue(v)) code — the inverse of BitReader::ue. Refuses u32::MAX because code_num = value + 1 would overflow.

Source

pub fn write_se(&mut self, value: i32) -> Result<(), BitstreamError>

Write a signed Exp-Golomb (se(v)) code — the inverse of BitReader::se.

Source

pub fn align_to_byte(&mut self)

Pad with zero bits up to the next byte boundary.

Source

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

Consume the writer and return the accumulated bytes. The final byte’s unused low bits (if the bit count is not a multiple of 8) are zero.

Source

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

Borrow the accumulated bytes without consuming the writer.

Trait Implementations§

Source§

impl Clone for BitWriter

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BitWriter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.