pub struct ArithmeticDecoder<R> { /* private fields */ }Expand description
Range arithmetic decoder reading big-endian bits from a BitInputStream.
Implementations§
Source§impl<R: Read> ArithmeticDecoder<R>
impl<R: Read> ArithmeticDecoder<R>
Sourcepub fn new(
num_state_bits: u32,
input: BitInputStream<R>,
) -> Result<Self, ArithError>
pub fn new( num_state_bits: u32, input: BitInputStream<R>, ) -> Result<Self, ArithError>
Constructs a decoder using num_state_bits and reads the initial code word.
§Errors
Returns ArithError::InvalidStateBits or ArithError::Io on initial reads.
Sourcepub fn read(&mut self, freqs: &[u32]) -> Result<usize, ArithError>
pub fn read(&mut self, freqs: &[u32]) -> Result<usize, ArithError>
Decodes the next symbol using the cumulative frequency table freqs.
§Errors
Returns ArithError if freqs is invalid or reading from the bit stream fails.
Sourcepub fn state(&self) -> DecoderState
pub fn state(&self) -> DecoderState
Captures the minimal exact decoder state for checkpointing.
Sourcepub fn restore_state(&mut self, state: DecoderState) -> Result<(), ArithError>
pub fn restore_state(&mut self, state: DecoderState) -> Result<(), ArithError>
Restores a previously captured DecoderState.
Note that the underlying BitInputStream must also be restored separately.
§Errors
Returns ArithError::StateWidthMismatch if num_state_bits differs.
Sourcepub fn bit_stream(&self) -> &BitInputStream<R>
pub fn bit_stream(&self) -> &BitInputStream<R>
Returns a shared reference to the underlying BitInputStream.
Sourcepub fn bit_stream_mut(&mut self) -> &mut BitInputStream<R>
pub fn bit_stream_mut(&mut self) -> &mut BitInputStream<R>
Returns a mutable reference to the underlying BitInputStream.
Sourcepub fn into_bit_stream(self) -> BitInputStream<R>
pub fn into_bit_stream(self) -> BitInputStream<R>
Consumes this decoder and returns the underlying BitInputStream.