pub struct BitWriter { /* private fields */ }Expand description
Packs bits MSB-first into a growable byte buffer.
The first bit written lands in bit 7 (the most-significant bit) of byte 0, matching the bit order every video/image bitstream uses. Partial trailing bits stay in an internal accumulator until a byte fills or the writer is byte-aligned.
Implementations§
Source§impl BitWriter
impl BitWriter
Sourcepub fn with_capacity(bytes: usize) -> Self
pub fn with_capacity(bytes: usize) -> Self
A writer preallocated for roughly bytes bytes of output.
Sourcepub fn write_bits(&mut self, value: u32, n: u32)
pub fn write_bits(&mut self, value: u32, n: u32)
Append the low n bits of value, MSB-first. n must be <= 32.
Sourcepub fn write_bits64(&mut self, value: u64, n: u32)
pub fn write_bits64(&mut self, value: u64, n: u32)
Append the low n bits of a 64-bit value, MSB-first. n must be <= 64.
Sourcepub fn write_byte(&mut self, b: u8)
pub fn write_byte(&mut self, b: u8)
Append a whole byte. Fast when byte-aligned (the common case for raw PCM samples); falls back to bit-by-bit otherwise.
Sourcepub fn write_ue(&mut self, value: u32)
pub fn write_ue(&mut self, value: u32)
Unsigned Exp-Golomb, ue(v) (H.265 §9.2). Encodes value as
leadingZeros 0s, a 1, then the leadingZeros-bit suffix of
value + 1.
Sourcepub fn write_se(&mut self, value: i32)
pub fn write_se(&mut self, value: i32)
Signed Exp-Golomb, se(v) (H.265 §9.2). Maps value to a ue(v)
codeNum via the standard zig-zag (0→0, 1→1, -1→2, 2→3, -2→4, …).
Sourcepub fn is_byte_aligned(&self) -> bool
pub fn is_byte_aligned(&self) -> bool
Whether the next bit would start a fresh byte.
Sourcepub fn align_zero(&mut self)
pub fn align_zero(&mut self)
Pad to the next byte boundary with 0 bits (no-op if already aligned).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BitWriter
impl RefUnwindSafe for BitWriter
impl Send for BitWriter
impl Sync for BitWriter
impl Unpin for BitWriter
impl UnsafeUnpin for BitWriter
impl UnwindSafe for BitWriter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more