Struct Encoder

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

An arithmetic encoder

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

Implementations§

Source§

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

Source

pub fn new(model: M, bitwriter: &'a mut W) -> 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, bitwriter: &'a mut W, 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<'a, M::B, W>, model: M) -> Self

Create an encoder from an existing State.

This is useful for manually chaining a shared buffer through multiple encoders.

Source

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

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>, ) -> Result<(), Error<M::ValueError>>

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) -> 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<'a, M::B, W>)

todo

Source

pub fn chain<X>(self, model: X) -> Encoder<'a, 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<'a, M, W> Debug for Encoder<'a, 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<'a, M, W> Freeze for Encoder<'a, M, W>
where M: Freeze, <M as Model>::B: Freeze,

§

impl<'a, M, W> RefUnwindSafe for Encoder<'a, M, W>

§

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

§

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

§

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

§

impl<'a, M, W> !UnwindSafe for Encoder<'a, M, W>

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.