Struct BufBitReader

Source
pub struct BufBitReader<E: Endianness, WR: WordRead, RP: ReadParams = DefaultReadParams>
where WR::Word: DoubleType,
{ /* private fields */ }
Expand description

An implementation of BitRead and BitSeek for a WordRead and a WordSeek.

This implementation uses a bit buffer to store bits that are not yet read. The buffer is sized as twice the word size of the underlying WordRead. Typically, the best choice is to have a buffer that is sized as usize, which means that the word of the underlying WordRead should be half of that (i.e., u32 for a 64-bit architecture). However, results will vary depending on the CPU.

The peek word is equal to the bit buffer. The value returned by peek_bits contains at least as many bits as the word size plus one (extended with zeros beyond end of stream).

This implementation is usually faster than BitReader.

The additional type parameter RP is used to select the parameters for the instantanous codes, but the casual user should be happy with the default value. See ReadParams for more details.

For additional flexibility, this structures implements std::io::Read. Note that because of coherence rules it is not possible to implement std::io::Read for a generic BitRead.

Implementations§

Source§

impl<E: Endianness, WR: WordRead, RP: ReadParams> BufBitReader<E, WR, RP>
where WR::Word: DoubleType,

Source

pub fn new(backend: WR) -> Self

Create a new BufBitReader around a WordRead.

§Example
use dsi_bitstream::prelude::*;
let words: [u32; 2] = [0x0043b59f, 0xccf16077];
let word_reader = MemWordReader::new(&words);
let mut buf_bit_reader = <BufBitReader<BE, _>>::new(word_reader);
Source

pub fn into_inner(self) -> Result<WR, Infallible>

Return the backend, consuming this reader.

Trait Implementations§

Source§

impl<WR: WordRead, RP: ReadParams> BitRead<BigEndian> for BufBitReader<BE, WR, RP>

Source§

type Error = <WR as WordRead>::Error

Source§

type PeekWord = <<WR as WordRead>::Word as DoubleType>::DoubleType

The type we can read from the stream without advancing.
Source§

fn peek_bits(&mut self, n_bits: usize) -> Result<Self::PeekWord, Self::Error>

Peeks at n bits without advancing the stream position. n must be nonzero, and at most PeekWord::BITS.
Source§

fn read_bits(&mut self, n_bits: usize) -> Result<u64, Self::Error>

Read n bits and return them in the lowest bits. Read more
Source§

fn read_unary(&mut self) -> Result<u64, Self::Error>

Read a unary code.
Source§

fn skip_bits(&mut self, n_bits: usize) -> Result<(), Self::Error>

Skip n bits from the stream. Read more
Source§

fn copy_to<F: Endianness, W: BitWrite<F>>( &mut self, bit_write: &mut W, n: u64, ) -> Result<(), CopyError<Self::Error, W::Error>>

Source§

impl<WR: WordRead, RP: ReadParams> BitRead<LittleEndian> for BufBitReader<LE, WR, RP>

Source§

type Error = <WR as WordRead>::Error

Source§

type PeekWord = <<WR as WordRead>::Word as DoubleType>::DoubleType

The type we can read from the stream without advancing.
Source§

fn peek_bits(&mut self, n_bits: usize) -> Result<Self::PeekWord, Self::Error>

Peeks at n bits without advancing the stream position. n must be nonzero, and at most PeekWord::BITS.
Source§

fn read_bits(&mut self, n_bits: usize) -> Result<u64, Self::Error>

Read n bits and return them in the lowest bits. Read more
Source§

fn read_unary(&mut self) -> Result<u64, Self::Error>

Read a unary code.
Source§

fn skip_bits(&mut self, n_bits: usize) -> Result<(), Self::Error>

Skip n bits from the stream. Read more
Source§

fn copy_to<F: Endianness, W: BitWrite<F>>( &mut self, bit_write: &mut W, n: u64, ) -> Result<(), CopyError<Self::Error, W::Error>>

Source§

impl<E: Error + Send + Sync + 'static, WR: WordRead<Error = E> + WordSeek<Error = E>, RP: ReadParams> BitSeek for BufBitReader<BE, WR, RP>
where WR::Word: DoubleType,

Source§

type Error = <WR as WordSeek>::Error

Source§

fn bit_pos(&mut self) -> Result<u64, Self::Error>

Get the current position in bits from the start of the stream.
Source§

fn set_bit_pos(&mut self, bit_index: u64) -> Result<(), Self::Error>

Set the current position in bits from the start of the stream to bit_pos. Read more
Source§

impl<E: Error + Send + Sync + 'static, WR: WordRead<Error = E> + WordSeek<Error = E>, RP: ReadParams> BitSeek for BufBitReader<LE, WR, RP>
where WR::Word: DoubleType,

Source§

type Error = <WR as WordSeek>::Error

Source§

fn bit_pos(&mut self) -> Result<u64, Self::Error>

Get the current position in bits from the start of the stream.
Source§

fn set_bit_pos(&mut self, bit_index: u64) -> Result<(), Self::Error>

Set the current position in bits from the start of the stream to bit_pos. Read more
Source§

impl<E: Endianness, WR: WordRead + Clone, RP: ReadParams> Clone for BufBitReader<E, WR, RP>
where WR::Word: DoubleType,

Source§

fn clone(&self) -> Self

Returns a copy 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<E: Endianness, WR, RP: ReadParams> CopyType for BufBitReader<E, WR, RP>

Source§

impl<E: Debug + Endianness, WR: Debug + WordRead, RP: Debug + ReadParams> Debug for BufBitReader<E, WR, RP>
where WR::Word: DoubleType,

Source§

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

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

impl<WR: WordRead> DeltaRead<BigEndian> for BufBitReader<BigEndian, WR, DefaultReadParams>

Source§

fn read_delta(&mut self) -> Result<u64, Self::Error>

Source§

impl<WR: WordRead> DeltaRead<LittleEndian> for BufBitReader<LittleEndian, WR, DefaultReadParams>

Source§

fn read_delta(&mut self) -> Result<u64, Self::Error>

Source§

impl<WR: WordRead> GammaRead<BigEndian> for BufBitReader<BigEndian, WR, DefaultReadParams>

Source§

fn read_gamma(&mut self) -> Result<u64, Self::Error>

Source§

impl<WR: WordRead> GammaRead<LittleEndian> for BufBitReader<LittleEndian, WR, DefaultReadParams>

Source§

fn read_gamma(&mut self) -> Result<u64, Self::Error>

Source§

impl<E: Endianness, WR, RP: ReadParams> MemDbgImpl for BufBitReader<E, WR, RP>

Source§

fn _mem_dbg_rec_on( &self, _memdbg_writer: &mut impl Write, _memdbg_total_size: usize, _memdbg_max_depth: usize, _memdbg_prefix: &mut String, _memdbg_is_last: bool, _memdbg_flags: DbgFlags, ) -> Result

Source§

fn _mem_dbg_depth_on( &self, writer: &mut impl Write, total_size: usize, max_depth: usize, prefix: &mut String, field_name: Option<&str>, is_last: bool, padded_size: usize, flags: DbgFlags, ) -> Result<(), Error>

Source§

impl<E: Endianness, WR, RP: ReadParams> MemSize for BufBitReader<E, WR, RP>

Source§

fn mem_size(&self, _memsize_flags: SizeFlags) -> usize

Returns the (recursively computed) overall memory size of the structure in bytes.
Source§

impl<WR: WordRead, RP: ReadParams> Read for BufBitReader<BE, WR, RP>

Source§

fn read(&mut self, buf: &mut [u8]) -> Result<usize>

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
1.36.0 · Source§

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>

Like read, except that it reads into a slice of buffers. Read more
Source§

fn is_read_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
1.0.0 · Source§

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>

Reads all bytes until EOF in this source, placing them into buf. Read more
1.0.0 · Source§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>

Reads all bytes until EOF in this source, appending them to buf. Read more
1.6.0 · Source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

Reads the exact number of bytes required to fill buf. Read more
Source§

fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
Source§

fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Reads the exact number of bytes required to fill cursor. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adaptor for this instance of Read. Read more
1.0.0 · Source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
1.0.0 · Source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where R: Read, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
1.0.0 · Source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more
Source§

impl<WR: WordRead, RP: ReadParams> Read for BufBitReader<LE, WR, RP>

Source§

fn read(&mut self, buf: &mut [u8]) -> Result<usize>

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
1.36.0 · Source§

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>

Like read, except that it reads into a slice of buffers. Read more
Source§

fn is_read_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
1.0.0 · Source§

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>

Reads all bytes until EOF in this source, placing them into buf. Read more
1.0.0 · Source§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>

Reads all bytes until EOF in this source, appending them to buf. Read more
1.6.0 · Source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

Reads the exact number of bytes required to fill buf. Read more
Source§

fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
Source§

fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Reads the exact number of bytes required to fill cursor. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adaptor for this instance of Read. Read more
1.0.0 · Source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
1.0.0 · Source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where R: Read, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
1.0.0 · Source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more
Source§

impl<WR: WordRead> ZetaRead<BigEndian> for BufBitReader<BigEndian, WR, DefaultReadParams>

Source§

fn read_zeta(&mut self, k: usize) -> Result<u64, Self::Error>

Source§

fn read_zeta3(&mut self) -> Result<u64, Self::Error>

Source§

impl<WR: WordRead> ZetaRead<LittleEndian> for BufBitReader<LittleEndian, WR, DefaultReadParams>

Source§

fn read_zeta(&mut self, k: usize) -> Result<u64, Self::Error>

Source§

fn read_zeta3(&mut self) -> Result<u64, Self::Error>

Auto Trait Implementations§

§

impl<E, WR, RP> Freeze for BufBitReader<E, WR, RP>
where <WR as WordRead>::Word: Sized, WR: Freeze, <<WR as WordRead>::Word as DoubleType>::DoubleType: Freeze,

§

impl<E, WR, RP> RefUnwindSafe for BufBitReader<E, WR, RP>

§

impl<E, WR, RP> Send for BufBitReader<E, WR, RP>
where <WR as WordRead>::Word: Sized, WR: Send, RP: Send,

§

impl<E, WR, RP> Sync for BufBitReader<E, WR, RP>
where <WR as WordRead>::Word: Sized, WR: Sync, RP: Sync,

§

impl<E, WR, RP> Unpin for BufBitReader<E, WR, RP>
where <WR as WordRead>::Word: Sized, WR: Unpin, <<WR as WordRead>::Word as DoubleType>::DoubleType: Unpin, E: Unpin, RP: Unpin,

§

impl<E, WR, RP> UnwindSafe for BufBitReader<E, WR, RP>

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> CastableFrom<T> for T

Source§

fn cast_from(value: T) -> T

Call Self as W
Source§

impl<T, U> CastableInto<U> for T
where U: CastableFrom<T>,

Source§

fn cast(self) -> U

Call W::cast_from(self)
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<B> DeltaReadParam<BigEndian> for B

Source§

fn read_delta_param<const USE_DELTA_TABLE: bool, const USE_GAMMA_TABLE: bool>( &mut self, ) -> Result<u64, <B as BitRead<BigEndian>>::Error>

Source§

impl<B> DeltaReadParam<LittleEndian> for B

Source§

fn read_delta_param<const USE_DELTA_TABLE: bool, const USE_GAMMA_TABLE: bool>( &mut self, ) -> Result<u64, <B as BitRead<LittleEndian>>::Error>

Source§

impl<T> DowncastableFrom<T> for T

Source§

fn downcast_from(value: T) -> T

Truncate the current UnsignedInt to a possibly smaller size
Source§

impl<T, U> DowncastableInto<U> for T
where U: DowncastableFrom<T>,

Source§

fn downcast(self) -> U

Call W::downcast_from(self)
Source§

impl<E, B> ExpGolombRead<E> for B
where E: Endianness, B: BitRead<E> + GammaRead<E>,

Source§

fn read_exp_golomb(&mut self, k: usize) -> Result<u64, Self::Error>

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<B> GammaReadParam<BigEndian> for B
where B: BitRead<BigEndian>,

Source§

fn read_gamma_param<const USE_TABLE: bool>( &mut self, ) -> Result<u64, <B as BitRead<BigEndian>>::Error>

Source§

impl<B> GammaReadParam<LittleEndian> for B

Source§

fn read_gamma_param<const USE_TABLE: bool>( &mut self, ) -> Result<u64, <B as BitRead<LittleEndian>>::Error>

Source§

impl<E, B> GolombRead<E> for B
where E: Endianness, B: BitRead<E>,

Source§

fn read_golomb(&mut self, b: u64) -> Result<u64, Self::Error>

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> MemDbg for T
where T: MemDbgImpl,

Source§

fn mem_dbg(&self, flags: DbgFlags) -> Result<(), Error>

Writes to stderr debug infos about the structure memory usage, expanding all levels of nested structures.
Source§

fn mem_dbg_on( &self, writer: &mut impl Write, flags: DbgFlags, ) -> Result<(), Error>

Writes to a core::fmt::Write debug infos about the structure memory usage, expanding all levels of nested structures.
Source§

fn mem_dbg_depth(&self, max_depth: usize, flags: DbgFlags) -> Result<(), Error>

Writes to stderr debug infos about the structure memory usage as mem_dbg, but expanding only up to max_depth levels of nested structures.
Source§

fn mem_dbg_depth_on( &self, writer: &mut impl Write, max_depth: usize, flags: DbgFlags, ) -> Result<(), Error>

Writes to a core::fmt::Write debug infos about the structure memory usage as mem_dbg_on, but expanding only up to max_depth levels of nested structures.
Source§

impl<E, B> MinimalBinaryRead<E> for B
where E: Endianness, B: BitRead<E>,

Source§

fn read_minimal_binary(&mut self, max: u64) -> Result<u64, Self::Error>

Source§

impl<E, B> OmegaRead<E> for B
where E: Endianness, B: BitRead<E>,

Source§

fn read_omega(&mut self) -> Result<u64, Self::Error>

Source§

impl<E, B> PiRead<E> for B
where E: Endianness, B: BitRead<E> + RiceRead<E> + ?Sized,

Source§

fn read_pi(&mut self, k: usize) -> Result<u64, Self::Error>

Source§

impl<E, B> RiceRead<E> for B
where E: Endianness, B: BitRead<E>,

Source§

fn read_rice(&mut self, log2_b: usize) -> Result<u64, Self::Error>

Source§

impl<T> Splat<T> for T

Source§

fn splat(value: T) -> T

Source§

impl<T> To<T> for T

Source§

fn to(self) -> T

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

impl<T> UpcastableFrom<T> for T

Source§

fn upcast_from(value: T) -> T

Extend the current UnsignedInt to a possibly bigger size.
Source§

impl<T, U> UpcastableInto<U> for T
where U: UpcastableFrom<T>,

Source§

fn upcast(self) -> U

Call W::upcast_from(self)
Source§

impl<E, B> VByteBeRead<E> for B
where E: Endianness, B: BitRead<E>,

Source§

fn read_vbyte_be(&mut self) -> Result<u64, <B as BitRead<E>>::Error>

Source§

impl<E, B> VByteLeRead<E> for B
where E: Endianness, B: BitRead<E>,

Source§

fn read_vbyte_le(&mut self) -> Result<u64, <B as BitRead<E>>::Error>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<B> ZetaReadParam<BigEndian> for B
where B: BitRead<BigEndian>,

Source§

fn read_zeta_param( &mut self, k: usize, ) -> Result<u64, <B as BitRead<BigEndian>>::Error>

Source§

fn read_zeta3_param<const USE_TABLE: bool>( &mut self, ) -> Result<u64, <B as BitRead<BigEndian>>::Error>

Source§

impl<B> ZetaReadParam<LittleEndian> for B

Source§

fn read_zeta_param( &mut self, k: usize, ) -> Result<u64, <B as BitRead<LittleEndian>>::Error>

Source§

fn read_zeta3_param<const USE_TABLE: bool>( &mut self, ) -> Result<u64, <B as BitRead<LittleEndian>>::Error>

Source§

impl<E, B> CodesRead<E> for B