pub struct RansDecoder<'a> { /* private fields */ }Expand description
A symbol-at-a-time rANS decoder.
Constructed from a byte stream produced by RansEncoder::finish or encode.
Decode symbols with get, or use the bits-back primitives
peek + advance.
Implementations§
Source§impl<'a> RansDecoder<'a>
impl<'a> RansDecoder<'a>
Sourcepub fn new(bytes: &'a [u8]) -> Result<Self, AnsError>
pub fn new(bytes: &'a [u8]) -> Result<Self, AnsError>
Initialize a decoder from an encoded byte stream.
Returns an error if the stream is too short (< 4 bytes) or the
initial state is below RANS_L.
Sourcepub fn peek(&self, table: &FrequencyTable) -> u32
pub fn peek(&self, table: &FrequencyTable) -> u32
Peek at the next symbol without advancing the state.
Returns the symbol whose frequency interval contains the current slot.
Use with advance for bits-back coding, where the
caller needs the slot value before deciding how to advance.
§Validity
The returned symbol is guaranteed to be in-range only when the decoder
state is valid, i.e. the decoder was just constructed via new
or the most recent advance call succeeded. If advance
returned an error (truncated input), the state may be partially updated
and peek results are undefined.
Sourcepub fn advance(
&mut self,
sym: u32,
table: &FrequencyTable,
) -> Result<(), AnsError>
pub fn advance( &mut self, sym: u32, table: &FrequencyTable, ) -> Result<(), AnsError>
Advance the decoder state after a peek.
sym must be the symbol returned by peek (or a valid symbol whose
frequency interval contains the current slot). Passing the wrong symbol
will silently corrupt the state.
Sourcepub fn remaining_bytes(&self) -> usize
pub fn remaining_bytes(&self) -> usize
Number of unread bytes remaining in the buffer (excluding the initial state).