Skip to main content

TranscodeConvertEngine

Struct TranscodeConvertEngine 

Source
pub struct TranscodeConvertEngine<D, E, H>
where D: Codec, E: Codec<Value = D::Value>, H: TranscodeConvertHooks<D, E>,
{ /* private fields */ }
Expand description

Reusable buffered conversion engine.

The engine owns reusable buffered decode and encode engines plus a small conversion-level hook object. It keeps common converter control flow private: index validation, pending-value retention, pending flush, decode-error policy dispatch, encode planning, output-capacity checks, and progress reporting.

TranscodeConvertEngine is intentionally batch-oriented. Its public transcode method drives a source/output buffer loop and reuses the same unchecked codec and hook primitives as crate::TranscodeDecodeEngine and crate::TranscodeEncodeEngine. It does not call one-value public transcoders in the hot path.

§Type Parameters

  • D: Source-side decoder codec.
  • E: Target-side encoder codec.
  • H: Conversion-level policy hooks.

Implementations§

Source§

impl<D, E, H> TranscodeConvertEngine<D, E, H>
where D: Codec, E: Codec<Value = D::Value>, H: TranscodeConvertHooks<D, E>,

Source

pub fn new(decoder: D, encoder: E, hooks: H) -> Self

Creates a buffered converter engine.

The supplied conversion hooks create the internal decode and encode hook instances. This keeps codec-specific hook initialization with the conversion policy instead of requiring those hook types to implement Default.

§Parameters
  • decoder: Low-level codec used for source decoding.
  • encoder: Low-level codec used for target encoding.
  • hooks: Conversion-level policy hooks.
§Returns

Returns a buffered converter engine.

§Panics

Panics when either codec violates the Codec::min_units_per_value / Codec::max_units_per_value ordering invariant.

Source

pub fn from_parts( decoder: D, encoder: E, hooks: H, decode_hooks: H::DecodeHooks, encode_hooks: H::EncodeHooks, ) -> Self

Builds the engine from already-created component hooks.

Callers that use new do not need to call this directly; this method is provided for advanced cases where decode and encode hooks are constructed externally. It constructs the component decode and encode engines through their public constructors, so both codecs are still validated against the Codec unit-bound invariant.

§Type Parameters
  • D: Source-side decoder codec.
  • E: Target-side encoder codec.
  • H: Conversion-level policy hooks.
§Parameters
  • decoder: Low-level decode codec.
  • encoder: Low-level encode codec.
  • hooks: Conversion-level hook aggregator.
  • decode_hooks: Decode hooks instance created from hooks.
  • encode_hooks: Encode hooks instance created from hooks.
§Returns

Returns an engine assembled from the provided codecs and hooks.

§Panics

Panics when either codec violates the Codec::min_units_per_value / Codec::max_units_per_value ordering invariant.

Source

pub fn max_output_len(&self, input_len: usize) -> Result<usize, CapacityError>

Returns an upper bound for target units produced from input_len units.

Source

pub fn max_reset_output_len(&self) -> Result<usize, CapacityError>

Returns the maximum target units emitted when resetting stream state.

Source

pub fn max_finish_output_len(&self) -> Result<usize, CapacityError>

Returns the maximum target units emitted by finishing retained state.

Source

pub fn transcode( &mut self, input: &[D::Unit], input_index: usize, output: &mut [E::Unit], output_index: usize, ) -> Result<TranscodeProgress, TranscodeError<<H as TranscodeConvertHooks<D, E>>::Error>>

Converts source units into target units.

§Parameters
  • input: Complete input unit slice visible to the converter.
  • input_index: Absolute input index where conversion starts.
  • output: Complete output unit slice visible to the converter.
  • output_index: Absolute output index where writing starts.
§Returns

Returns conversion progress.

§Errors

Returns hook errors when indices are invalid or concrete conversion fails. Invalid output indices are reported through the encode-side error path.

Source

pub fn finish( &mut self, output: &mut [E::Unit], output_index: usize, ) -> Result<usize, TranscodeError<<H as TranscodeConvertHooks<D, E>>::Error>>
where D::Value: Default,

Finishes retained output after EOF.

Finalization drains a pending decoded value first, then lets the source-side decode hooks emit final values, encodes those values through the target-side encode hooks, and finally finishes target-side encode hook state. The decode-finish value buffer used for this cold path requires D::Value: Default; the normal transcode loop does not.

§Parameters
  • output: Complete output unit slice visible to the converter.
  • output_index: Absolute output index where writing starts.
§Returns

Returns the number of target units written during finalization.

§Errors

Returns a converter error when output capacity checks fail or when hook finalization fails.

Source

pub fn reset( &mut self, output: &mut [E::Unit], output_index: usize, ) -> Result<usize, TranscodeError<<H as TranscodeConvertHooks<D, E>>::Error>>

Resets hook-owned and component-owned state and emits stream-start encode output.

§Parameters
  • output: Complete output unit slice visible to the converter.
  • output_index: Absolute output index where writing starts.
§Returns

Returns the number of target units written while resetting stream state.

§Errors

Returns a converter error if reset validation or finalization fails.

Trait Implementations§

Source§

impl<D, E, H> Clone for TranscodeConvertEngine<D, E, H>
where D: Codec + Clone, E: Codec<Value = D::Value> + Clone, H: TranscodeConvertHooks<D, E> + Clone, H::DecodeHooks: Clone, H::EncodeHooks: Clone, D::Value: Clone,

Source§

fn clone(&self) -> TranscodeConvertEngine<D, E, H>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<D, E, H> Debug for TranscodeConvertEngine<D, E, H>
where D: Codec + Debug, E: Codec<Value = D::Value> + Debug, H: TranscodeConvertHooks<D, E> + Debug, H::DecodeHooks: Debug, H::EncodeHooks: Debug, D::Value: Debug,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<D, E, H> Default for TranscodeConvertEngine<D, E, H>
where D: Codec + Default, E: Codec<Value = D::Value> + Default, H: TranscodeConvertHooks<D, E> + Default,

Source§

fn default() -> Self

Creates a default buffered converter engine.

§Returns

Returns a converter engine constructed from default codecs and hooks.

Source§

impl<D, E, H> Eq for TranscodeConvertEngine<D, E, H>
where D: Codec + Eq, E: Codec<Value = D::Value> + Eq, H: TranscodeConvertHooks<D, E> + Eq, H::DecodeHooks: Eq, H::EncodeHooks: Eq, D::Value: Eq,

Source§

impl<D, E, H> Hash for TranscodeConvertEngine<D, E, H>
where D: Codec + Hash, E: Codec<Value = D::Value> + Hash, H: TranscodeConvertHooks<D, E> + Hash, H::DecodeHooks: Hash, H::EncodeHooks: Hash, D::Value: Hash,

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<D, E, H> PartialEq for TranscodeConvertEngine<D, E, H>

Source§

fn eq(&self, other: &TranscodeConvertEngine<D, E, H>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<D, E, H> StructuralPartialEq for TranscodeConvertEngine<D, E, H>

Auto Trait Implementations§

§

impl<D, E, H> Freeze for TranscodeConvertEngine<D, E, H>

§

impl<D, E, H> RefUnwindSafe for TranscodeConvertEngine<D, E, H>

§

impl<D, E, H> Send for TranscodeConvertEngine<D, E, H>
where H: Send, D: Send, <H as TranscodeConvertHooks<D, E>>::DecodeHooks: Send, E: Send, <H as TranscodeConvertHooks<D, E>>::EncodeHooks: Send, <D as Codec>::Value: Send,

§

impl<D, E, H> Sync for TranscodeConvertEngine<D, E, H>
where H: Sync, D: Sync, <H as TranscodeConvertHooks<D, E>>::DecodeHooks: Sync, E: Sync, <H as TranscodeConvertHooks<D, E>>::EncodeHooks: Sync, <D as Codec>::Value: Sync,

§

impl<D, E, H> Unpin for TranscodeConvertEngine<D, E, H>
where H: Unpin, D: Unpin, <H as TranscodeConvertHooks<D, E>>::DecodeHooks: Unpin, E: Unpin, <H as TranscodeConvertHooks<D, E>>::EncodeHooks: Unpin, <D as Codec>::Value: Unpin,

§

impl<D, E, H> UnsafeUnpin for TranscodeConvertEngine<D, E, H>

§

impl<D, E, H> UnwindSafe for TranscodeConvertEngine<D, E, H>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.