pub struct TranscodeConvertEngine<D, E, H>{ /* 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>
impl<D, E, H> TranscodeConvertEngine<D, E, H>
Sourcepub fn new(decoder: D, encoder: E, hooks: H) -> Self
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.
Sourcepub fn from_parts(
decoder: D,
encoder: E,
hooks: H,
decode_hooks: H::DecodeHooks,
encode_hooks: H::EncodeHooks,
) -> Self
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 fromhooks.encode_hooks: Encode hooks instance created fromhooks.
§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.
Sourcepub fn max_output_len(&self, input_len: usize) -> Result<usize, CapacityError>
pub fn max_output_len(&self, input_len: usize) -> Result<usize, CapacityError>
Returns an upper bound for target units produced from input_len units.
Sourcepub fn max_reset_output_len(&self) -> Result<usize, CapacityError>
pub fn max_reset_output_len(&self) -> Result<usize, CapacityError>
Returns the maximum target units emitted when resetting stream state.
Sourcepub fn max_finish_output_len(&self) -> Result<usize, CapacityError>
pub fn max_finish_output_len(&self) -> Result<usize, CapacityError>
Returns the maximum target units emitted by finishing retained state.
Sourcepub 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>>
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.
Sourcepub fn finish(
&mut self,
output: &mut [E::Unit],
output_index: usize,
) -> Result<usize, TranscodeError<<H as TranscodeConvertHooks<D, E>>::Error>>
pub fn finish( &mut self, output: &mut [E::Unit], output_index: usize, ) -> Result<usize, TranscodeError<<H as TranscodeConvertHooks<D, E>>::Error>>
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.
Sourcepub fn reset(
&mut self,
output: &mut [E::Unit],
output_index: usize,
) -> Result<usize, TranscodeError<<H as TranscodeConvertHooks<D, E>>::Error>>
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,
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>
fn clone(&self) -> TranscodeConvertEngine<D, E, H>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§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,
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§impl<D, E, H> Default for TranscodeConvertEngine<D, E, H>
impl<D, E, H> Default for TranscodeConvertEngine<D, E, H>
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,
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§impl<D, E, H> PartialEq for TranscodeConvertEngine<D, E, H>where
D: Codec + PartialEq,
E: Codec<Value = D::Value> + PartialEq,
H: TranscodeConvertHooks<D, E> + PartialEq,
H::DecodeHooks: PartialEq,
H::EncodeHooks: PartialEq,
D::Value: PartialEq,
impl<D, E, H> PartialEq for TranscodeConvertEngine<D, E, H>where
D: Codec + PartialEq,
E: Codec<Value = D::Value> + PartialEq,
H: TranscodeConvertHooks<D, E> + PartialEq,
H::DecodeHooks: PartialEq,
H::EncodeHooks: PartialEq,
D::Value: PartialEq,
Source§fn eq(&self, other: &TranscodeConvertEngine<D, E, H>) -> bool
fn eq(&self, other: &TranscodeConvertEngine<D, E, H>) -> bool
self and other values to be equal, and is used by ==.