Trait dsi_bitstream::traits::BitRead
source · pub trait BitRead<E: Endianness> {
type Error: Error + Send + Sync + 'static;
type PeekWord: CastableInto<u64>;
// Required methods
fn read_bits(&mut self, n: usize) -> Result<u64, Self::Error>;
fn peek_bits(&mut self, n: usize) -> Result<Self::PeekWord, Self::Error>;
fn skip_bits(&mut self, n: usize) -> Result<(), Self::Error>;
fn read_unary(&mut self) -> Result<u64, Self::Error>;
// Provided method
fn copy_to<F: Endianness, W: BitWrite<F>>(
&mut self,
bit_write: &mut W,
n: u64
) -> Result<(), CopyError<Self::Error, W::Error>> { ... }
}
Expand description
Sequential, streaming bit-by-bit reads.
This trait specify basic operation over which codes can be implemented by
traits such as GammaReadParam
.
To read quickly complex codes, such traits may use the
peek_bits
method to read a few bits in advance and
then use a table to decode them. For this to happen correctly,
peek_bits
must return a sufficient number of bits.
It is unfortunately difficult at the time being to check statically that
this is the case, but in test mode an assertion will be triggered if the
number of bits returned by peek_bits
is not
sufficient.
Implementors are invited to call check_tables
at construction time to
provide a warning to the user if the peek word is not large enough.
Please see the documentation of the impls
module for more
details.
Required Associated Types§
type Error: Error + Send + Sync + 'static
sourcetype PeekWord: CastableInto<u64>
type PeekWord: CastableInto<u64>
The type we can read from the stream without advancing.
Required Methods§
sourcefn read_bits(&mut self, n: usize) -> Result<u64, Self::Error>
fn read_bits(&mut self, n: usize) -> Result<u64, Self::Error>
Read n
bits and return them in the lowest bits.
Implementors should check the value of n
when in test mode
and panic if it is greater than 64.
sourcefn peek_bits(&mut self, n: usize) -> Result<Self::PeekWord, Self::Error>
fn peek_bits(&mut self, n: usize) -> Result<Self::PeekWord, Self::Error>
Peeks at n
bits without advancing the stream position.
n
must be nonzero, and at most PeekWord::BITS
.
sourcefn skip_bits(&mut self, n: usize) -> Result<(), Self::Error>
fn skip_bits(&mut self, n: usize) -> Result<(), Self::Error>
Skip n
bits from the stream.
When moving forward by a small amount of bits, this method might be
more efficient than BitSeek::set_bit_pos
.
sourcefn read_unary(&mut self) -> Result<u64, Self::Error>
fn read_unary(&mut self) -> Result<u64, Self::Error>
Read a unary code.