Skip to main content

BitReader

Struct BitReader 

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

A big-endian, MSB-first bit reader.

Implementations§

Source§

impl<'a> BitReader<'a>

Source

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

Wraps an RBSP byte slice.

Source

pub fn data(&self) -> &'a [u8]

The underlying RBSP buffer (for handing off to the CABAC engine).

Source

pub fn bit_pos(&self) -> usize

Current bit position.

Source

pub fn bit_len(&self) -> usize

Total number of bits in the buffer.

Source

pub fn bits_left(&self) -> usize

Bits remaining.

Source

pub fn more_rbsp_data(&self) -> bool

more_rbsp_data() (spec §7.2): true while the read position is before the rbsp_stop_one_bit (the last set bit in the buffer). Used to detect the end of slice_data() when a picture is split into multiple slices.

Source

pub fn is_byte_aligned(&self) -> bool

true if the read position sits on a byte boundary.

Source

pub fn align_to_byte(&mut self) -> Result<(), OutOfData>

Advances to the next byte boundary, consuming the intervening bits (e.g. pcm_alignment_zero_bits before an I_PCM payload).

Source

pub fn read_bit(&mut self) -> Result<bool, OutOfData>

Reads a single bit.

Source

pub fn read_bits(&mut self, n: u32) -> Result<u32, OutOfData>

Reads n bits (n <= 32) as an unsigned value, MSB first. u(n).

Source

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

Peeks the next n bits (n ≤ 24) as an MSB-first value without consuming, zero-filling past the end of the buffer. O(1): loads up to 4 bytes. The zero-fill lets a VLC/Exp-Golomb table match be attempted at the stream end; the caller then skip_bitss the matched length, which rejects (OutOfData) if those bits ran past the buffer.

Source

pub fn skip_bits(&mut self, n: u32) -> Result<(), OutOfData>

Consumes n bits (advances the position), after a [peek_bits]. Rejects if the bits run past the end of the buffer — the truncated-stream guard that read_bit’s per-bit bounds check provided.

Source

pub fn read_ue(&mut self) -> Result<u32, OutOfData>

Unsigned Exp-Golomb decode, ue(v).

Source

pub fn read_se(&mut self) -> Result<i32, OutOfData>

Signed Exp-Golomb decode, se(v).

Trait Implementations§

Source§

impl<'a> Clone for BitReader<'a>

Source§

fn clone(&self) -> BitReader<'a>

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<'a> Debug for BitReader<'a>

Source§

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

Formats the value using the given formatter. Read more

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> 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 = 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.