Skip to main content

BitReader

Struct BitReader 

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

A bit-level reader for decoding packed binary data.

All read operations are bounds-checked and return errors on failure. The reader never panics on malformed input.

Implementations§

Source§

impl<'a> BitReader<'a>

Source

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

Creates a new BitReader from a byte slice.

Source

pub const fn bits_remaining(&self) -> usize

Returns the number of bits remaining to read.

Source

pub const fn is_empty(&self) -> bool

Returns true if there are no more bits to read.

Source

pub const fn bit_position(&self) -> usize

Returns the current bit position.

Source

pub fn read_bit(&mut self) -> BitResult<bool>

Reads a single bit as a boolean.

Source

pub fn read_bits(&mut self, bits: u8) -> BitResult<u64>

Reads up to 64 bits as an unsigned integer.

Source

pub fn align_to_byte(&mut self) -> BitResult<()>

Aligns to the next byte boundary.

Source

pub fn read_u8_aligned(&mut self) -> BitResult<u8>

Reads a byte-aligned u8.

Source

pub fn read_u16_aligned(&mut self) -> BitResult<u16>

Reads a byte-aligned u16 (little-endian).

Source

pub fn read_u32_aligned(&mut self) -> BitResult<u32>

Reads a byte-aligned u32 (little-endian).

Source

pub fn read_u64_aligned(&mut self) -> BitResult<u64>

Reads a byte-aligned u64 (little-endian).

Source

pub fn read_varu32(&mut self) -> BitResult<u32>

Reads a byte-aligned varint u32.

Source

pub fn read_vars32(&mut self) -> BitResult<i32>

Reads a byte-aligned zigzag varint i32.

Trait Implementations§

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