pub struct BitReader<'a> { /* private fields */ }Expand description
Reads packed bits from a borrowed byte slice, most-significant-bit first.
§Example
use wire_codec::BitReader;
// 0b1010_1100 = 0xAC. Read 3 bits, then 5 bits.
let mut r = BitReader::new(&[0xAC]);
assert_eq!(r.read_bits(3).unwrap(), 0b101);
assert_eq!(r.read_bits(5).unwrap(), 0b01100);Implementations§
Source§impl<'a> BitReader<'a>
impl<'a> BitReader<'a>
Sourcepub const fn new(bytes: &'a [u8]) -> Self
pub const fn new(bytes: &'a [u8]) -> Self
Wrap bytes in a new bit cursor positioned at the first bit.
Sourcepub const fn bits_consumed(&self) -> usize
pub const fn bits_consumed(&self) -> usize
Number of bits already consumed.
Sourcepub const fn bits_remaining(&self) -> usize
pub const fn bits_remaining(&self) -> usize
Number of bits still available to read.
Sourcepub fn align_to_byte(&mut self)
pub fn align_to_byte(&mut self)
Advance the cursor to the next byte boundary.
Sourcepub fn read_bits(&mut self, n: u32) -> Result<u64>
pub fn read_bits(&mut self, n: u32) -> Result<u64>
Read the next n bits as the low-order bits of a u64.
§Errors
Error::BitOverflowifnis0or greater thanMAX_BIT_WIDTH.Error::UnexpectedEofif fewer thannbits remain in the input.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more