pub struct BufferedConvertEngine<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.
BufferedConvertEngine 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::BufferedDecodeEngine and
crate::BufferedEncodeEngine. 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> BufferedConvertEngine<D, E, H>
impl<D, E, H> BufferedConvertEngine<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.
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_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, <H as BufferedConvertHooks<D, E>>::Error>
pub fn transcode( &mut self, input: &[D::Unit], input_index: usize, output: &mut [E::Unit], output_index: usize, ) -> Result<TranscodeProgress, <H as BufferedConvertHooks<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, FinishError<<H as BufferedConvertHooks<D, E>>::Error>>
pub fn finish( &mut self, output: &mut [E::Unit], output_index: usize, ) -> Result<usize, FinishError<<H as BufferedConvertHooks<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 FinishError when capacity planning overflows, when the caller
provides invalid or insufficient output capacity, or when hook
finalization fails.
Trait Implementations§
Source§impl<D, E, H> Clone for BufferedConvertEngine<D, E, H>where
D: Codec + Clone,
E: Codec<Value = D::Value> + Clone,
H: BufferedConvertHooks<D, E> + Clone,
H::DecodeHooks: Clone,
H::EncodeHooks: Clone,
D::Value: Clone,
impl<D, E, H> Clone for BufferedConvertEngine<D, E, H>where
D: Codec + Clone,
E: Codec<Value = D::Value> + Clone,
H: BufferedConvertHooks<D, E> + Clone,
H::DecodeHooks: Clone,
H::EncodeHooks: Clone,
D::Value: Clone,
Source§fn clone(&self) -> BufferedConvertEngine<D, E, H>
fn clone(&self) -> BufferedConvertEngine<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 BufferedConvertEngine<D, E, H>where
D: Codec + Debug,
E: Codec<Value = D::Value> + Debug,
H: BufferedConvertHooks<D, E> + Debug,
H::DecodeHooks: Debug,
H::EncodeHooks: Debug,
D::Value: Debug,
impl<D, E, H> Debug for BufferedConvertEngine<D, E, H>where
D: Codec + Debug,
E: Codec<Value = D::Value> + Debug,
H: BufferedConvertHooks<D, E> + Debug,
H::DecodeHooks: Debug,
H::EncodeHooks: Debug,
D::Value: Debug,
Source§impl<D, E, H> Default for BufferedConvertEngine<D, E, H>
impl<D, E, H> Default for BufferedConvertEngine<D, E, H>
impl<D, E, H> Eq for BufferedConvertEngine<D, E, H>where
D: Codec + Eq,
E: Codec<Value = D::Value> + Eq,
H: BufferedConvertHooks<D, E> + Eq,
H::DecodeHooks: Eq,
H::EncodeHooks: Eq,
D::Value: Eq,
Source§impl<D, E, H> Hash for BufferedConvertEngine<D, E, H>where
D: Codec + Hash,
E: Codec<Value = D::Value> + Hash,
H: BufferedConvertHooks<D, E> + Hash,
H::DecodeHooks: Hash,
H::EncodeHooks: Hash,
D::Value: Hash,
impl<D, E, H> Hash for BufferedConvertEngine<D, E, H>where
D: Codec + Hash,
E: Codec<Value = D::Value> + Hash,
H: BufferedConvertHooks<D, E> + Hash,
H::DecodeHooks: Hash,
H::EncodeHooks: Hash,
D::Value: Hash,
Source§impl<D, E, H> PartialEq for BufferedConvertEngine<D, E, H>where
D: Codec + PartialEq,
E: Codec<Value = D::Value> + PartialEq,
H: BufferedConvertHooks<D, E> + PartialEq,
H::DecodeHooks: PartialEq,
H::EncodeHooks: PartialEq,
D::Value: PartialEq,
impl<D, E, H> PartialEq for BufferedConvertEngine<D, E, H>where
D: Codec + PartialEq,
E: Codec<Value = D::Value> + PartialEq,
H: BufferedConvertHooks<D, E> + PartialEq,
H::DecodeHooks: PartialEq,
H::EncodeHooks: PartialEq,
D::Value: PartialEq,
Source§fn eq(&self, other: &BufferedConvertEngine<D, E, H>) -> bool
fn eq(&self, other: &BufferedConvertEngine<D, E, H>) -> bool
self and other values to be equal, and is used by ==.