Skip to main content

BitReader

Struct BitReader 

Source
pub struct BitReader<'a> { /* private fields */ }
Expand description

MSB-first bit reader over a borrowed byte slice.

Implementations§

Source§

impl<'a> BitReader<'a>

Source

pub fn new(bytes: &'a [u8]) -> Self

Create a fresh reader positioned at bit 0 of bytes.

Source

pub fn total_bits(&self) -> usize

Total number of payload bits in the reader.

Source

pub fn bit_pos(&self) -> usize

Current absolute bit offset.

Source

pub fn bits_remaining(&self) -> usize

Number of unread bits (saturating at zero).

Source

pub fn at_end(&self) -> bool

True if the next read would fall past the end of the buffer.

Source

pub fn byte_aligned(&self) -> bool

True if the reader is currently byte-aligned.

Source

pub fn skip(&mut self, n: usize)

Skip forward by n bits.

Source

pub fn align_to_byte(&mut self)

Skip forward to the next byte boundary if not already aligned.

Source

pub fn read_bit(&mut self) -> u32

Read one bit. Returns 0 past the end.

Source

pub fn u(&mut self, n: u32) -> u32

Read n bits MSB first into a u32. Past-the-end bits are 0. n must be ≤ 32 (the upper limit covers every fixed-width field used by H.264 / HEVC / AV1 OBU headers).

Source

pub fn u64(&mut self, n: u32) -> u64

Read n bits MSB first into a u64 (for AV1’s 64-bit reference_frame_id-class fields).

Source

pub fn ue(&mut self) -> Result<u32, BitstreamError>

Unsigned Exp-Golomb (ue(v)). H.264 9.1 / H.265 9.2. Returns an error if more than 32 leading zeros are seen (would overflow a u32).

Source

pub fn se(&mut self) -> Result<i32, BitstreamError>

Signed Exp-Golomb (se(v)). H.264 9.1.1 / H.265 9.2.2.

Auto Trait Implementations§

§

impl<'a> Freeze for BitReader<'a>

§

impl<'a> RefUnwindSafe for BitReader<'a>

§

impl<'a> Send for BitReader<'a>

§

impl<'a> Sync for BitReader<'a>

§

impl<'a> Unpin for BitReader<'a>

§

impl<'a> UnsafeUnpin for BitReader<'a>

§

impl<'a> UnwindSafe for BitReader<'a>

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.