Trait dsi_bitstream::traits::BitRead
source · pub trait BitRead<E: Endianness> {
type Error: Error;
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_param<const USE_TABLE: bool>(
&mut self
) -> Result<u64, Self::Error>;
// Provided methods
fn read_unary(&mut self) -> Result<u64, Self::Error> { ... }
fn skip_unary(&mut self) -> Result<(), Self::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
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 the checks
feature is
enabled 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 read_unary_param<const USE_TABLE: bool>(
&mut self
) -> Result<u64, Self::Error>
fn read_unary_param<const USE_TABLE: bool>( &mut self ) -> Result<u64, Self::Error>
Read a unary code.
This version of the method has a constant parameter
deciding whether to use a decoding table. You should rather use
BitRead::read_unary
, which uses the default
choice of the implementing type.
Provided Methods§
sourcefn read_unary(&mut self) -> Result<u64, Self::Error>
fn read_unary(&mut self) -> Result<u64, Self::Error>
Read a unary code.
This version of the method uses the version of
of BitRead::read_unary_param
selected as default by
the implementing type. The default implementation does
not use a table.
sourcefn skip_unary(&mut self) -> Result<(), Self::Error>
fn skip_unary(&mut self) -> Result<(), Self::Error>
Skip a unary code.