pub struct Encoder<M, W>where
    M: Model,
    W: BitWrite,{
    pub model: M,
    /* private fields */
}
Expand description

An arithmetic encoder

An arithmetic decoder converts a stream of symbols into a stream of bits, using a predictive Model.

Fields§

§model: M

The model used for the encoder

Implementations§

source§

impl<M, W> Encoder<M, W>where M: Model, W: BitWrite,

source

pub fn new(model: M) -> Self

Construct a new Encoder.

The ‘precision’ of the encoder is maximised, based on the number of bits needed to represent the Model::denominator. ‘precision’ bits is equal to BitStore::BITS - Model::denominator bits. If you need to set the precision manually, use Encoder::with_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 fn with_precision(model: M, precision: u32) -> Self

Construct a new Encoder 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, W>, model: M) -> Self

todo

source

pub fn encode_all( &mut self, symbols: impl IntoIterator<Item = M::Symbol>, output: &mut W ) -> Result<(), Error>

Encode a stream of symbols into the provided output.

This method will encode all the symbols in the iterator, followed by EOF (None), and then call Encoder::flush.

Errors

This method can fail if the underlying BitWrite cannot be written to.

source

pub fn encode( &mut self, symbol: Option<&M::Symbol>, output: &mut W ) -> Result<(), Error>

Encode a symbol into the provided output.

When you finish encoding symbols, you must manually encode an EOF symbol by calling Encoder::encode with None.

The internal buffer must be manually flushed using Encoder::flush.

Errors

This method can fail if the underlying BitWrite cannot be written to.

source

pub fn flush(&mut self, output: &mut W) -> Result<()>

Flush any pending bits from the buffer

This method must be called when you finish writing symbols to a stream of bits. This is called automatically when you use Encoder::encode_all.

Errors

This method can fail if the underlying BitWrite cannot be written to.

source

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

todo

source

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

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

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

Trait Implementations§

source§

impl<M, W> Debug for Encoder<M, W>where M: Model + Debug, W: BitWrite + 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, W> RefUnwindSafe for Encoder<M, W>where M: RefUnwindSafe, W: RefUnwindSafe, <M as Model>::B: RefUnwindSafe,

§

impl<M, W> Send for Encoder<M, W>where M: Send, W: Send, <M as Model>::B: Send,

§

impl<M, W> Sync for Encoder<M, W>where M: Sync, W: Sync, <M as Model>::B: Sync,

§

impl<M, W> Unpin for Encoder<M, W>where M: Unpin, W: Unpin, <M as Model>::B: Unpin,

§

impl<M, W> UnwindSafe for Encoder<M, W>where M: UnwindSafe, W: UnwindSafe, <M as Model>::B: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.