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>
impl<'a> BitReader<'a>
Sourcepub fn bit_position(&self) -> usize
pub fn bit_position(&self) -> usize
The current position, in bits from the start.
Sourcepub fn is_byte_aligned(&self) -> bool
pub fn is_byte_aligned(&self) -> bool
Whether the reader sits exactly on a byte boundary.
Sourcepub fn byte_position(&self) -> usize
pub fn byte_position(&self) -> usize
The current position in whole bytes — only meaningful when byte-aligned.
Sourcepub fn f(&mut self, n: u32) -> Result<u32>
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.
Sourcepub fn uvlc(&mut self) -> Result<u32>
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.
Sourcepub fn le(&mut self, n: u32) -> Result<u64>
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.
Sourcepub fn leb128(&mut self) -> Result<u64>
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.
Sourcepub fn su(&mut self, n: u32) -> Result<i32>
pub fn su(&mut self, n: u32) -> Result<i32>
su(n) — a signed integer in n+1 bits, sign last (§4.10.6).
Sourcepub fn ns(&mut self, n: u32) -> Result<u32>
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.
Sourcepub fn byte_alignment(&mut self) -> Result<()>
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.