Struct Decoder

Source
pub struct Decoder<M, R>
where M: Model, R: BitRead,
{ /* private fields */ }
Expand description

An arithmetic decoder

An arithmetic decoder converts a stream of bytes into a stream of some output symbol, using a predictive Model.

Implementations§

Source§

impl<M, R> Decoder<M, R>
where M: Model, R: BitRead,

Source

pub fn new(model: M, input: R) -> Self

Construct a new Decoder

The ‘precision’ of the encoder is maximised, based on the number of bits needed to represent the Model::denominator. ‘precision’ bits is equal to u32::BITS - Model::denominator bits.

§Panics

The calculation of the number of bits used for ‘precision’ is subject to the following constraints:

If these constraints cannot be satisfied this method will panic in debug builds

Source

pub fn with_precision(model: M, input: R, precision: u32) -> Self

Construct a new Decoder with a custom precision

§Panics

The calculation of the number of bits used for ‘precision’ is subject to the following constraints:

If these constraints cannot be satisfied this method will panic in debug builds

Source

pub const fn with_state(state: State<M::B, R>, model: M) -> Self

todo

Source

pub fn decode_all(&mut self) -> DecodeIter<'_, M, R>

Return an iterator over the decoded symbols.

The iterator will continue returning symbols until EOF is reached

Source

pub fn decode(&mut self) -> Result<Option<M::Symbol>>

Read the next symbol from the stream of bits

This method will return Ok(None) when EOF is reached.

§Errors

This method can fail if the underlying BitRead cannot be read from.

Source

pub fn chain<X>(self, model: X) -> Decoder<X, R>
where X: Model<B = M::B>,

Reuse the internal state of the Decoder with a new model.

Allows for chaining multiple sequences of symbols from a single stream of bits

Source

pub fn into_inner(self) -> (M, State<M::B, R>)

todo

Trait Implementations§

Source§

impl<M, R> Debug for Decoder<M, R>
where M: Model + Debug, R: BitRead + Debug, M::B: Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<M, R> Freeze for Decoder<M, R>
where M: Freeze, R: Freeze, <M as Model>::B: Freeze,

§

impl<M, R> RefUnwindSafe for Decoder<M, R>

§

impl<M, R> Send for Decoder<M, R>
where M: Send, R: Send, <M as Model>::B: Send,

§

impl<M, R> Sync for Decoder<M, R>
where M: Sync, R: Sync, <M as Model>::B: Sync,

§

impl<M, R> Unpin for Decoder<M, R>
where M: Unpin, R: Unpin, <M as Model>::B: Unpin,

§

impl<M, R> UnwindSafe for Decoder<M, R>
where M: UnwindSafe, R: UnwindSafe, <M as Model>::B: UnwindSafe,

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.