Skip to main content

TokenEncoder

Struct TokenEncoder 

Source
pub struct TokenEncoder { /* private fields */ }
Expand description

Phase-2 token-block encoder handle.

A thin wrapper around the §13 encode_coeff_block free function that owns its own BoolEncoder + resolved coeff_probs table and exposes a stateful encode_block method. Useful for the higher-level encoder rounds that will emit many blocks into the same partition.

The encoder is stateless across blocks in the §13.3 sense — the ctx3 rollover lives entirely inside encode_coeff_block and the neighbour predictors are passed in per call. What the wrapper owns is the underlying entropy-coder byte stream + the (large) probability table.

Implementations§

Source§

impl TokenEncoder

Source

pub fn new(coeff_probs: CoeffProbs) -> Self

Build an encoder against the supplied resolved coefficient probabilities. Pass crate::DEFAULT_COEFF_PROBS (or the merge_default_token_probs(&updates) result) to match the decode_block path callers go through on the other side.

Source

pub fn encode_block( &mut self, block_type: BlockType, above_has_nonzero: bool, left_has_nonzero: bool, coeffs: &[i16; 16], ) -> Result<usize, TokenEncodeError>

Encode one 16-coefficient sub-block. See encode_coeff_block for the parameter semantics.

Source

pub fn finish(self) -> Vec<u8> ⓘ

Finalise the underlying BoolEncoder and return the byte stream the decoder should consume.

Source

pub fn bytes_written(&self) -> usize

Number of bytes committed so far (excludes the §7.3 4-byte flush trailer that finish will append).

Trait Implementations§

Source§

impl Debug for TokenEncoder

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Forget for TokenEncoder

§

impl Freeze for TokenEncoder
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze,

§

impl Move for TokenEncoder

§

impl RefUnwindSafe for TokenEncoder

§

impl Send for TokenEncoder
where RawVecInner: Send,

§

impl Sync for TokenEncoder
where RawVecInner: Sync,

§

impl Unpin for TokenEncoder
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for TokenEncoder

§

impl UnwindSafe for TokenEncoder
where RawVecInner: 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.