Skip to main content

BitRead

Trait BitRead 

Source
pub trait BitRead<E: Endianness> {
    type Error: Error + Send + Sync + 'static;
    type PeekWord: AsPrimitive<u64>;

    const PEEK_BITS: usize;

    // Required methods
    fn read_bits(&mut self, num_bits: 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 specifies basic operations over which codes can be implemented by traits such as GammaReadParam.

To quickly read 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. Each table module provides a check_read_table const fn that can be used in a const { } block to verify at compile time that the peek word is large enough.

Please see the documentation of the impls module for more details.

Required Associated Constants§

Source

const PEEK_BITS: usize

The number of bits that peek_bits is guaranteed to return successfully (with zero-extended EOF).

Required Associated Types§

Source

type Error: Error + Send + Sync + 'static

Source

type PeekWord: AsPrimitive<u64>

The type we can read from the stream without advancing.

Required Methods§

Source

fn read_bits(&mut self, num_bits: usize) -> Result<u64, Self::Error>

Reads num_bits bits and returns them in the lowest bits.

Implementors should check the value of num_bits 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 Self::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>

Reads a unary code.

Implementations are required to support the range [0 . . 2⁶⁴ – 1).

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>>

Copy bits from self to a BitWrite stream.

§Errors

This method can return a CopyError if the source stream returns an error while reading, or if the destination stream returns an error while writing.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

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

Source§

const PEEK_BITS: usize = BR::PEEK_BITS

Source§

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

Source§

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

Source§

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

Source§

const PEEK_BITS: usize = R::PEEK_BITS

Source§

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

Source§

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

Source§

impl<WR: WordRead<Word = u64> + WordSeek<Error = <WR as WordRead>::Error>, RP: ReadParams> BitRead<BigEndian> for BitReader<BE, WR, RP>

Source§

impl<WR: WordRead<Word = u64> + WordSeek<Error = <WR as WordRead>::Error>, RP: ReadParams> BitRead<LittleEndian> for BitReader<LE, WR, RP>

Source§

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

Source§

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