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 (extended with
zeros beyond end of stream): a peek is served by at most one refill, so only
one word of peekable bits can be guaranteed.
The convenience functions from_path and from_file (requiring the
std feature) create a BufBitReader around a buffered file reader.
This implementation is usually faster than BitReader.
The additional type parameter RP is used to select the parameters for the
instantaneous codes, but the casual user should be happy with the default
value. See ReadParams for more details.
For additional flexibility, when the std feature is enabled, this
structure 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,
impl<E: Endianness, WR: WordRead, RP: ReadParams> BufBitReader<E, WR, RP>where
WR::Word: DoubleType,
Sourcepub const fn new(backend: WR) -> Self
pub const fn new(backend: WR) -> Self
Creates a new BufBitReader around a WordRead.
§Examples
use dsi_bitstream::prelude::*;
let words: [u32; 2] = [0x0043b59f, 0xccf16077];
let word_reader = MemWordReader::new_inf(&words);
let mut buf_bit_reader = <BufBitReader<BE, _>>::new(word_reader);Sourcepub fn into_inner(self) -> WR
pub fn into_inner(self) -> WR
Consumes this reader and returns the underlying WordRead.
Trait Implementations§
Source§impl<WR: WordRead, RP: ReadParams> BitRead<BigEndian> for BufBitReader<BE, WR, RP>where
WR::Word: DoubleType,
impl<WR: WordRead, RP: ReadParams> BitRead<BigEndian> for BufBitReader<BE, WR, RP>where
WR::Word: DoubleType,
Source§const PEEK_BITS: usize
const PEEK_BITS: usize
peek_bits is guaranteed to return
successfully (with zero-extended EOF).type Error = <WR as WordRead>::Error
Source§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 Self::PEEK_BITS.Source§fn read_bits(&mut self, num_bits: usize) -> Result<u64, Self::Error>
fn read_bits(&mut self, num_bits: usize) -> Result<u64, Self::Error>
num_bits bits and returns them in the lowest bits. Read moreSource§impl<WR: WordRead, RP: ReadParams> BitRead<LittleEndian> for BufBitReader<LE, WR, RP>where
WR::Word: DoubleType,
impl<WR: WordRead, RP: ReadParams> BitRead<LittleEndian> for BufBitReader<LE, WR, RP>where
WR::Word: DoubleType,
Source§const PEEK_BITS: usize
const PEEK_BITS: usize
peek_bits is guaranteed to return
successfully (with zero-extended EOF).type Error = <WR as WordRead>::Error
Source§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 Self::PEEK_BITS.Source§fn read_bits(&mut self, num_bits: usize) -> Result<u64, Self::Error>
fn read_bits(&mut self, num_bits: usize) -> Result<u64, Self::Error>
num_bits bits and returns them in the lowest bits. Read moreSource§impl<WR: WordRead + WordSeek<Error = <WR as WordRead>::Error>, RP: ReadParams> BitSeek for BufBitReader<BE, WR, RP>where
WR::Word: DoubleType,
impl<WR: WordRead + WordSeek<Error = <WR as WordRead>::Error>, RP: ReadParams> BitSeek for BufBitReader<BE, WR, RP>where
WR::Word: DoubleType,
Source§impl<WR: WordRead + WordSeek<Error = <WR as WordRead>::Error>, RP: ReadParams> BitSeek for BufBitReader<LE, WR, RP>where
WR::Word: DoubleType,
impl<WR: WordRead + WordSeek<Error = <WR as WordRead>::Error>, RP: ReadParams> BitSeek for BufBitReader<LE, WR, RP>where
WR::Word: DoubleType,
Source§impl<E: Endianness, WR: WordRead + Clone, RP: ReadParams> Clone for BufBitReader<E, WR, RP>where
WR::Word: DoubleType,
impl<E: Endianness, WR: WordRead + Clone, RP: ReadParams> Clone for BufBitReader<E, WR, RP>where
WR::Word: DoubleType,
Source§impl<E: Debug + Endianness, WR: Debug + WordRead, RP: Debug + ReadParams> Debug for BufBitReader<E, WR, RP>where
WR::Word: DoubleType,
impl<E: Debug + Endianness, WR: Debug + WordRead, RP: Debug + ReadParams> Debug for BufBitReader<E, WR, RP>where
WR::Word: DoubleType,
Source§impl<WR: WordRead<Word: DoubleType>> DeltaRead<BigEndian> for BufBitReader<BigEndian, WR, DefaultReadParams>
impl<WR: WordRead<Word: DoubleType>> DeltaRead<BigEndian> for BufBitReader<BigEndian, WR, DefaultReadParams>
Source§impl<WR: WordRead<Word: DoubleType>> DeltaRead<LittleEndian> for BufBitReader<LittleEndian, WR, DefaultReadParams>
impl<WR: WordRead<Word: DoubleType>> DeltaRead<LittleEndian> for BufBitReader<LittleEndian, WR, DefaultReadParams>
Source§impl<E: Endianness, WR, RP: ReadParams> FlatType for BufBitReader<E, WR, RP>where
WR::Word: DoubleType,
WR: MemSize + FlatType + WordRead,
<<WR as WordRead>::Word as DoubleType>::DoubleType: MemSize + FlatType,
usize: MemSize + FlatType,
PhantomData<(E, RP)>: MemSize + FlatType,
impl<E: Endianness, WR, RP: ReadParams> FlatType for BufBitReader<E, WR, RP>where
WR::Word: DoubleType,
WR: MemSize + FlatType + WordRead,
<<WR as WordRead>::Word as DoubleType>::DoubleType: MemSize + FlatType,
usize: MemSize + FlatType,
PhantomData<(E, RP)>: MemSize + FlatType,
Source§impl<WR: WordRead<Word: DoubleType>> GammaRead<BigEndian> for BufBitReader<BigEndian, WR, DefaultReadParams>
impl<WR: WordRead<Word: DoubleType>> GammaRead<BigEndian> for BufBitReader<BigEndian, WR, DefaultReadParams>
Source§impl<WR: WordRead<Word: DoubleType>> GammaRead<LittleEndian> for BufBitReader<LittleEndian, WR, DefaultReadParams>
impl<WR: WordRead<Word: DoubleType>> GammaRead<LittleEndian> for BufBitReader<LittleEndian, WR, DefaultReadParams>
Source§impl<E: Endianness, WR, RP: ReadParams> MemDbgImpl for BufBitReader<E, WR, RP>where
WR::Word: DoubleType,
WR: MemDbgImpl + FlatType + WordRead,
<<WR as WordRead>::Word as DoubleType>::DoubleType: MemDbgImpl + FlatType,
usize: MemDbgImpl + FlatType,
PhantomData<(E, RP)>: MemDbgImpl + FlatType,
impl<E: Endianness, WR, RP: ReadParams> MemDbgImpl for BufBitReader<E, WR, RP>where
WR::Word: DoubleType,
WR: MemDbgImpl + FlatType + WordRead,
<<WR as WordRead>::Word as DoubleType>::DoubleType: MemDbgImpl + FlatType,
usize: MemDbgImpl + FlatType,
PhantomData<(E, RP)>: MemDbgImpl + FlatType,
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,
_memdbg_refs: &mut HashSet<usize>,
) -> Result
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, _memdbg_refs: &mut HashSet<usize>, ) -> Result
self below the current line. Read moreSource§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,
dbg_refs: &mut HashSet<usize>,
) -> Result<(), Error>
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, dbg_refs: &mut HashSet<usize>, ) -> Result<(), Error>
self at the given depth without any reference-address
annotation; forwards to _mem_dbg_depth_on_impl
with RefDisplay::None.Source§fn _mem_dbg_depth_on_impl(
&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,
dbg_refs: &mut HashSet<usize>,
ref_display: RefDisplay,
) -> Result<(), Error>
fn _mem_dbg_depth_on_impl( &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, dbg_refs: &mut HashSet<usize>, ref_display: RefDisplay, ) -> Result<(), Error>
Source§impl<E: Endianness, WR, RP: ReadParams> MemSize for BufBitReader<E, WR, RP>where
WR::Word: DoubleType,
WR: MemSize + FlatType + WordRead,
<<WR as WordRead>::Word as DoubleType>::DoubleType: MemSize + FlatType,
usize: MemSize + FlatType,
PhantomData<(E, RP)>: MemSize + FlatType,
impl<E: Endianness, WR, RP: ReadParams> MemSize for BufBitReader<E, WR, RP>where
WR::Word: DoubleType,
WR: MemSize + FlatType + WordRead,
<<WR as WordRead>::Word as DoubleType>::DoubleType: MemSize + FlatType,
usize: MemSize + FlatType,
PhantomData<(E, RP)>: MemSize + FlatType,
Source§impl<WR: WordRead<Word: DoubleType>> OmegaRead<BigEndian> for BufBitReader<BigEndian, WR, DefaultReadParams>
impl<WR: WordRead<Word: DoubleType>> OmegaRead<BigEndian> for BufBitReader<BigEndian, WR, DefaultReadParams>
Source§impl<WR: WordRead<Word: DoubleType>> OmegaRead<LittleEndian> for BufBitReader<LittleEndian, WR, DefaultReadParams>
impl<WR: WordRead<Word: DoubleType>> OmegaRead<LittleEndian> for BufBitReader<LittleEndian, WR, DefaultReadParams>
Source§impl<WR: WordRead<Word: DoubleType>> PiRead<BigEndian> for BufBitReader<BigEndian, WR, DefaultReadParams>
impl<WR: WordRead<Word: DoubleType>> PiRead<BigEndian> for BufBitReader<BigEndian, WR, DefaultReadParams>
Source§impl<WR: WordRead<Word: DoubleType>> PiRead<LittleEndian> for BufBitReader<LittleEndian, WR, DefaultReadParams>
impl<WR: WordRead<Word: DoubleType>> PiRead<LittleEndian> for BufBitReader<LittleEndian, WR, DefaultReadParams>
Source§impl<WR: WordRead, RP: ReadParams> Read for BufBitReader<LE, WR, RP>where
WR::Word: DoubleType,
Available on crate feature std only.
impl<WR: WordRead, RP: ReadParams> Read for BufBitReader<LE, WR, RP>where
WR::Word: DoubleType,
std only.Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Note that this implementation transfers data in 8-byte chunks, and a
WordRead backend error is not atomic with respect to the chunk:
near the end of the stream a partial chunk may be consumed and then
discarded, so up to 7 trailing bytes can be unreachable through this
interface when the destination buffer length is a multiple of 8.
Moreover, the backend error type cannot distinguish end of stream
from a backend failure, so reading past the last available byte fails
with std::io::ErrorKind::UnexpectedEof instead of returning
Ok(0).
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(
&mut self,
cursor: BorrowedCursor<'_, u8>,
) -> Result<(), Error>
fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
1.0.0 · Source§fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
limit bytes from it. Read moreSource§fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
read_array)Source§impl<WR: WordRead, RP: ReadParams> Read for BufBitReader<BE, WR, RP>where
WR::Word: DoubleType,
Available on crate feature std only.
impl<WR: WordRead, RP: ReadParams> Read for BufBitReader<BE, WR, RP>where
WR::Word: DoubleType,
std only.Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Note that this implementation transfers data in 8-byte chunks, and a
WordRead backend error is not atomic with respect to the chunk:
near the end of the stream a partial chunk may be consumed and then
discarded, so up to 7 trailing bytes can be unreachable through this
interface when the destination buffer length is a multiple of 8.
Moreover, the backend error type cannot distinguish end of stream
from a backend failure, so reading past the last available byte fails
with std::io::ErrorKind::UnexpectedEof instead of returning
Ok(0).
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(
&mut self,
cursor: BorrowedCursor<'_, u8>,
) -> Result<(), Error>
fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
1.0.0 · Source§fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
limit bytes from it. Read moreSource§fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
read_array)Source§impl<WR: WordRead<Word: DoubleType>> ZetaRead<BigEndian> for BufBitReader<BigEndian, WR, DefaultReadParams>
impl<WR: WordRead<Word: DoubleType>> ZetaRead<BigEndian> for BufBitReader<BigEndian, WR, DefaultReadParams>
Source§impl<WR: WordRead<Word: DoubleType>> ZetaRead<LittleEndian> for BufBitReader<LittleEndian, WR, DefaultReadParams>
impl<WR: WordRead<Word: DoubleType>> ZetaRead<LittleEndian> for BufBitReader<LittleEndian, WR, DefaultReadParams>
Auto Trait Implementations§
impl<E, WR, RP> Freeze for BufBitReader<E, WR, RP>
impl<E, WR, RP> RefUnwindSafe for BufBitReader<E, WR, RP>
impl<E, WR, RP> Send for BufBitReader<E, WR, RP>
impl<E, WR, RP> Sync for BufBitReader<E, WR, RP>
impl<E, WR, RP> Unpin for BufBitReader<E, WR, RP>
impl<E, WR, RP> UnsafeUnpin for BufBitReader<E, WR, RP>
impl<E, WR, RP> UnwindSafe for BufBitReader<E, WR, RP>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<E, B> CodesRead<E> for Bwhere
E: Endianness,
B: BitRead<E> + GammaRead<E> + DeltaRead<E> + ZetaRead<E> + OmegaRead<E> + PiRead<E> + MinimalBinaryRead<E> + GolombRead<E> + RiceRead<E> + ExpGolombRead<E> + VByteBeRead<E> + VByteLeRead<E>,
Source§impl<B> DeltaReadParam<BigEndian> for Bwhere
B: GammaReadParam<BigEndian>,
impl<B> DeltaReadParam<BigEndian> for Bwhere
B: GammaReadParam<BigEndian>,
Source§impl<B> DeltaReadParam<LittleEndian> for Bwhere
B: GammaReadParam<LittleEndian>,
impl<B> DeltaReadParam<LittleEndian> for Bwhere
B: GammaReadParam<LittleEndian>,
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<E, B> ExpGolombRead<E> for Bwhere
E: Endianness,
B: GammaRead<E>,
impl<E, B> ExpGolombRead<E> for Bwhere
E: Endianness,
B: GammaRead<E>,
Source§impl<B> GammaReadParam<BigEndian> for B
impl<B> GammaReadParam<BigEndian> for B
Source§impl<B> GammaReadParam<LittleEndian> for Bwhere
B: BitRead<LittleEndian>,
impl<B> GammaReadParam<LittleEndian> for Bwhere
B: BitRead<LittleEndian>,
fn read_gamma_param<const USE_TABLE: bool>( &mut self, ) -> Result<u64, <B as BitRead<LittleEndian>>::Error>
Source§impl<E, B> GolombRead<E> for Bwhere
E: Endianness,
B: BitRead<E>,
impl<E, B> GolombRead<E> for Bwhere
E: Endianness,
B: BitRead<E>,
Source§impl<T> MemDbg for Twhere
T: MemDbgImpl,
impl<T> MemDbg for Twhere
T: MemDbgImpl,
Source§fn mem_dbg(&self, flags: DbgFlags) -> Result<(), Error>
fn mem_dbg(&self, flags: DbgFlags) -> Result<(), Error>
Source§fn mem_dbg_on(
&self,
writer: &mut impl Write,
flags: DbgFlags,
) -> Result<(), Error>
fn mem_dbg_on( &self, writer: &mut impl Write, flags: DbgFlags, ) -> Result<(), Error>
core::fmt::Write debug info about the structure memory
usage, expanding all levels of nested structures.Source§fn mem_dbg_depth(&self, max_depth: usize, flags: DbgFlags) -> Result<(), Error>
fn mem_dbg_depth(&self, max_depth: usize, flags: DbgFlags) -> Result<(), Error>
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>
fn mem_dbg_depth_on( &self, writer: &mut impl Write, max_depth: usize, flags: DbgFlags, ) -> Result<(), Error>
core::fmt::Write debug info about the structure memory
usage as mem_dbg_on, but expanding only up to
max_depth levels of nested structures.