Skip to main content

BitReader

Struct BitReader 

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

MSB-first bit reader with the same semantics as Prometheus’ chunkenc.bstreamReader.

Bits are consumed from the most significant end of each byte. Every read either succeeds or reports crate::Error::Eof; a truncated chunk never yields partially valid values.

Implementations§

Source§

impl<'a> BitReader<'a>

Source

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

Wraps a chunk body. Nothing is read until the first call.

Source

pub fn bits_left_hint(&self) -> usize

Upper bound on the bits still available, including buffered ones.

Source

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

Reads a single bit.

Source

pub fn read_bits(&mut self, nbits: u8) -> Result<u64>

Reads nbits (0-64) bits into the low bits of the result.

Returns crate::Error::Decode for nbits > 64 and crate::Error::Eof when the stream ends mid-read.

Source

pub fn read_byte(&mut self) -> Result<u8>

Reads a big-endian byte from the bit stream (Go’s ReadByte).

Source

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

Go’s binary.ReadUvarint over the bit stream.

Source

pub fn read_varint(&mut self) -> Result<i64>

Go’s binary.ReadVarint (zig-zag).

Auto Trait Implementations§

§

impl<'a> Forget for BitReader<'a>

§

impl<'a> Freeze for BitReader<'a>
where &'a [u8]: Freeze,

§

impl<'a> Move for BitReader<'a>

§

impl<'a> RefUnwindSafe for BitReader<'a>

§

impl<'a> Send for BitReader<'a>
where &'a [u8]: Send,

§

impl<'a> Sync for BitReader<'a>

§

impl<'a> Unpin for BitReader<'a>
where &'a [u8]: Unpin,

§

impl<'a> UnsafeUnpin for BitReader<'a>
where &'a [u8]: UnsafeUnpin,

§

impl<'a> UnwindSafe for BitReader<'a>
where &'a [u8]: UnwindSafe,

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 = !

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.