Skip to main content

BitReader

Struct BitReader 

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

A most-significant-bit-first reader over an AV1 byte slice.

Position is tracked in bits so byte_alignment and the byte-granular primitives (leb128, le) can assert and act on alignment.

Implementations§

Source§

impl<'a> BitReader<'a>

Source

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

Wrap a byte slice. Reading starts at its first bit.

Source

pub fn bit_position(&self) -> usize

The current position, in bits from the start.

Source

pub fn bit_len(&self) -> usize

The total length of the underlying slice, in bits.

Source

pub fn bits_left(&self) -> usize

Bits remaining before the end of the slice.

Source

pub fn is_byte_aligned(&self) -> bool

Whether the reader sits exactly on a byte boundary.

Source

pub fn byte_position(&self) -> usize

The current position in whole bytes — only meaningful when byte-aligned.

Source

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

f(n) — read n bits as an unsigned integer, MSB first (§4.10.2).

n is at most 32; the AV1 syntax never reads a wider f(n) in one call.

Source

pub fn flag(&mut self) -> Result<bool>

Read a boolean flag — f(1) reported as bool.

Source

pub fn uvlc(&mut self) -> Result<u32>

uvlc() — unsigned variable-length code (§4.10.3).

A run of zero bits terminated by a one, then that many value bits. A run of 32 or more leading zeros is the spec’s saturation case and yields u32::MAX.

Source

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

le(n) — an n-byte little-endian unsigned integer (§4.10.4).

Must be byte-aligned, which the syntax guarantees at every call site.

Source

pub fn leb128(&mut self) -> Result<u64>

leb128() — a little-endian base-128 unsigned integer (§4.10.5).

At most eight bytes; a ninth continuation bit is malformed. Returns the value and the number of bytes consumed so callers can bound a payload.

Source

pub fn su(&mut self, n: u32) -> Result<i32>

su(n) — a signed integer in n+1 bits, sign last (§4.10.6).

Source

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

ns(n) — a non-symmetric unsigned integer over [0, n) (§4.10.7).

Uses one fewer bit for the smaller half of the range, so it is not a plain f. n == 0 reads nothing and yields 0.

Source

pub fn byte_alignment(&mut self) -> Result<()>

Advance to the next byte boundary, requiring the skipped bits be zero (byte_alignment(), §5.3.5). AV1 mandates the padding be zero.

Source

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

Skip n bits without interpreting them.

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.