Struct dsi_bitstream::impls::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.
Implementations§
source§impl<E: Endianness, WR: WordRead, RP: ReadParams> BufBitReader<E, WR, RP>where
WR::Word: DoubleType,
impl<E: Endianness, WR: WordRead, RP: ReadParams> BufBitReader<E, WR, RP>where
WR::Word: DoubleType,
sourcepub fn new(backend: WR) -> Self
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);
Trait Implementations§
source§impl<WR: WordRead, RP: ReadParams> BitRead<BigEndian> for BufBitReader<BE, WR, RP>where
WR::Word: DoubleType + UpcastableInto<u64>,
<<WR as WordRead>::Word as DoubleType>::DoubleType: CastableInto<u64>,
impl<WR: WordRead, RP: ReadParams> BitRead<BigEndian> for BufBitReader<BE, WR, RP>where
WR::Word: DoubleType + UpcastableInto<u64>,
<<WR as WordRead>::Word as DoubleType>::DoubleType: CastableInto<u64>,
type Error = <WR as WordRead>::Error
§type PeekWord = <<WR as WordRead>::Word as DoubleType>::DoubleType
type PeekWord = <<WR as WordRead>::Word as DoubleType>::DoubleType
source§fn peek_bits(&mut self, n_bits: usize) -> Result<Self::PeekWord, Self::Error>
fn peek_bits(&mut self, n_bits: usize) -> Result<Self::PeekWord, Self::Error>
n
bits without advancing the stream position.
n
must be nonzero, and at most PeekWord::BITS
.source§fn skip_bits(&mut self, n_bits: usize) -> Result<(), Self::Error>
fn skip_bits(&mut self, n_bits: usize) -> Result<(), Self::Error>
n
bits from the stream.source§fn read_bits(&mut self, n_bits: usize) -> Result<u64, Self::Error>
fn read_bits(&mut self, n_bits: usize) -> Result<u64, Self::Error>
n
bits and return them in the lowest bits. Read moresource§impl<WR: WordRead, RP: ReadParams> BitRead<LittleEndian> for BufBitReader<LE, WR, RP>where
WR::Word: DoubleType + UpcastableInto<u64>,
<<WR as WordRead>::Word as DoubleType>::DoubleType: CastableInto<u64>,
impl<WR: WordRead, RP: ReadParams> BitRead<LittleEndian> for BufBitReader<LE, WR, RP>where
WR::Word: DoubleType + UpcastableInto<u64>,
<<WR as WordRead>::Word as DoubleType>::DoubleType: CastableInto<u64>,
type Error = <WR as WordRead>::Error
§type PeekWord = <<WR as WordRead>::Word as DoubleType>::DoubleType
type PeekWord = <<WR as WordRead>::Word as DoubleType>::DoubleType
source§fn skip_bits(&mut self, n_bits: usize) -> Result<(), Self::Error>
fn skip_bits(&mut self, n_bits: usize) -> Result<(), Self::Error>
n
bits from the stream.source§fn read_bits(&mut self, n_bits: usize) -> Result<u64, Self::Error>
fn read_bits(&mut self, n_bits: usize) -> Result<u64, Self::Error>
n
bits and return them in the lowest bits. Read moresource§fn peek_bits(&mut self, n_bits: usize) -> Result<Self::PeekWord, Self::Error>
fn peek_bits(&mut self, n_bits: usize) -> Result<Self::PeekWord, Self::Error>
n
bits without advancing the stream position.
n
must be nonzero, and at most PeekWord::BITS
.