BigEndianReader

Struct BigEndianReader 

Source
pub struct BigEndianReader<'a>(/* private fields */);
Expand description

Reads bits in the big-endian format

use bitter::{BitReader, BigEndianReader};
let mut bebits = BigEndianReader::new(&[0b1000_0000]);
assert_eq!(bebits.read_bit(), Some(true));

Implementations§

Source§

impl<'a> BigEndianReader<'a>

Source

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

Create a big endian reader from the given byte slice.

Trait Implementations§

Source§

impl BitReader for BigEndianReader<'_>

Source§

fn read_bit(&mut self) -> Option<bool>

Consume a bit and return if the bit was enabled Read more
Source§

fn read_u8(&mut self) -> Option<u8>

Consume 8 bits and return the deserialized byte Read more
Source§

fn read_i8(&mut self) -> Option<i8>

Consume 8 bits and return the deserialized byte Read more
Source§

fn read_u16(&mut self) -> Option<u16>

Consume 16 bits and return the deserialized short Read more
Source§

fn read_i16(&mut self) -> Option<i16>

Consume 16 bits and return the deserialized short Read more
Source§

fn read_u32(&mut self) -> Option<u32>

Consume 32 bits and return the deserialized int Read more
Source§

fn read_i32(&mut self) -> Option<i32>

Consume 32 bits and return the deserialized int Read more
Source§

fn read_f32(&mut self) -> Option<f32>

Consume 32 bits and return the deserialized floating point Read more
Source§

fn read_u64(&mut self) -> Option<u64>

Consume 64 bits and return the deserialized int Read more
Source§

fn read_i64(&mut self) -> Option<i64>

Consume 64 bits and return the deserialized int Read more
Source§

fn read_f64(&mut self) -> Option<f64>

Consume 64 bits and return the deserialized floating point Read more
Source§

fn read_bits(&mut self, bits: u32) -> Option<u64>

Reads an arbitrary number of bits in the range of [0, 64] and returns the unsigned result Read more
Source§

fn read_signed_bits(&mut self, bits: u32) -> Option<i64>

Reads an arbitrary number of bits in the range of [0, 64] and returns the signed result. Read more
Source§

fn bytes_remaining(&self) -> usize

Returns how many complete bytes are left in the bitstream. Read more
Source§

fn unbuffered_bytes_remaining(&self) -> usize

Returns how many bytes are still left in the passed in buffer. Read more
Source§

fn bits_remaining(&self) -> Option<usize>

Returns the exact number of bits remaining in the bitstream if the number of bits can fit within a usize. For large byte slices, calculating the number of bits can cause an overflow, hence an Option is returned. See has_bits_remaining for a more robust, performant, and ergonomic alternative. Read more
Source§

fn has_bits_remaining(&self, bits: usize) -> bool

Returns true if at least bits number of bits are left in the stream. A more robust, performant, and ergonomic way than bits_remaining. Read more
Source§

fn read_bytes(&mut self, buf: &mut [u8]) -> bool

Read the number of bytes needed to fill the provided buffer. Returns whether the read was successful and the buffer has been filled. If there aren’t enough bytes remaining, then the bit stream and buffer remains unchanged Read more
Source§

fn is_empty(&self) -> bool

Returns if the bitstream has no bits left Read more
Source§

fn peek(&self, count: u32) -> u64

Peeks at the given number of bits in the lookahead buffer Read more
Source§

fn consume(&mut self, count: u32)

Consumes the number of bits from the lookahead buffer Read more
Source§

fn lookahead_bits(&self) -> u32

Returns the number of bits in the lookahead buffer Read more
Source§

fn refill_lookahead(&mut self)

Refills the lookahead buffer. Read more
Source§

unsafe fn refill_lookahead_unchecked(&mut self)

Refills the lookahead buffer without bounds checking Read more
Source§

fn byte_aligned(&self) -> bool

Returns true if the reader is not partway through a byte Read more
Source§

fn remainder(&self) -> Remainder<'_>

Returns the remainder of unread data. Read more
Source§

impl<'a> Clone for BigEndianReader<'a>

Source§

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

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for BigEndianReader<'a>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'a> Copy for BigEndianReader<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for BigEndianReader<'a>

§

impl<'a> RefUnwindSafe for BigEndianReader<'a>

§

impl<'a> Send for BigEndianReader<'a>

§

impl<'a> Sync for BigEndianReader<'a>

§

impl<'a> Unpin for BigEndianReader<'a>

§

impl<'a> UnwindSafe for BigEndianReader<'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.