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§

source

type Error: Error + Send + Sync + 'static

source

type PeekWord: CastableInto<u64>

The type we can read from the stream without advancing.

Required Methods§

source

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.

source

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.

source

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.

source

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

Read a unary code.

Provided Methods§

source

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

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<E: Error + Send + Sync + 'static, WR: WordRead<Error = E, Word = u64> + WordSeek<Error = E>, RP: ReadParams> BitRead<BigEndian> for BitReader<BE, WR, RP>

§

type Error = <WR as WordRead>::Error

§

type PeekWord = u32

source§

impl<E: Error + Send + Sync + 'static, WR: WordRead<Error = E, Word = u64> + WordSeek<Error = E>, RP: ReadParams> BitRead<LittleEndian> for BitReader<LE, WR, RP>

§

type Error = <WR as WordRead>::Error

§

type PeekWord = u32

source§

impl<E: Endianness, BR: BitRead<E>, const PRINT: bool> BitRead<E> for CountBitReader<E, BR, PRINT>

§

type Error = <BR as BitRead<E>>::Error

§

type PeekWord = <BR as BitRead<E>>::PeekWord

source§

impl<E: Endianness, R: BitRead<E>> BitRead<E> for DbgBitReader<E, R>
where R::PeekWord: Display,

§

type Error = <R as BitRead<E>>::Error

§

type PeekWord = <R as BitRead<E>>::PeekWord

source§

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

§

type Error = <WR as WordRead>::Error

§

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

source§

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

§

type Error = <WR as WordRead>::Error

§

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