Skip to main content

RansDecoder

Struct RansDecoder 

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

Source

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.

Source

pub fn get(&mut self, table: &FrequencyTable) -> Result<u32, AnsError>

Decode a single symbol from the rANS state.

Equivalent to calling peek followed by advance.

Source

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.

Source

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.

Source

pub fn state(&self) -> u32

Current rANS state (for bits-back interleaving).

Source

pub fn remaining_bytes(&self) -> usize

Number of unread bytes remaining in the buffer (excluding the initial state).

Trait Implementations§

Source§

impl<'a> Debug for RansDecoder<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for RansDecoder<'a>

§

impl<'a> RefUnwindSafe for RansDecoder<'a>

§

impl<'a> Send for RansDecoder<'a>

§

impl<'a> Sync for RansDecoder<'a>

§

impl<'a> Unpin for RansDecoder<'a>

§

impl<'a> UnsafeUnpin for RansDecoder<'a>

§

impl<'a> UnwindSafe for RansDecoder<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.