Skip to main content

CodecTranscodeConverter

Struct CodecTranscodeConverter 

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

Converts source units to target units through a decoded value by using codecs.

The converter decodes one source value with the decoder codec, then encodes that value with the encoder codec. If the current output buffer cannot hold the encoded value, the already decoded value is retained by the common converter engine and must be drained before more source input is consumed. Incomplete source tails are left in the caller-provided input slice; callers own input-buffer refill and EOF incomplete-tail policy.

Because finalization receives no source input, the source codec should have locally decidable decode boundaries for the default converter bridge. Source formats that require EOF-aware maximal-munch parsing or delayed boundary decisions should implement that source-side policy in a custom transcoder or facade before conversion.

§Type Parameters

  • D: Low-level codec used to decode source units.
  • E: Low-level codec used to encode target units.

Implementations§

Source§

impl<D, E> CodecTranscodeConverter<D, E>
where D: Codec, E: Codec<Value = D::Value>,

Source

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

Creates a buffered converter backed by decoder and encoder codecs.

§Parameters
  • decoder: Low-level codec used to decode source units.
  • encoder: Low-level codec used to encode target units.
§Returns

Returns a buffered converter adapter for the supplied codecs.

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.

This concrete adapter method is available even when D::Value does not implement Default.

§Parameters
  • input_len: Source units the caller plans to convert.
§Returns

Returns a conservative upper bound for produced target units.

Source

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

Returns the maximum target units emitted by finishing internal state.

§Returns

Returns a conservative upper bound for remaining converter-final output.

Source

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

Returns the maximum target units emitted when resetting stream state.

Source

pub fn reset( &mut self, output: &mut [E::Unit], output_index: usize, ) -> Result<usize, TranscodeError<CodecConvertError<<D as Codec>::DecodeError, <E as Codec>::EncodeError>>>
where D::Value: Default,

Clears retained pending output and hook state and emits stream-start encode output.

D::Value: Default is required so the engine can allocate scratch storage for any stream-start values the source decoder emits through Codec::decode_reset before they are piped through the target encoder. Stateless decoders never reach the allocating path; the bound is consulted only when Codec::MAX_DECODE_RESET_VALUES is non-zero.

Source

pub fn transcode( &mut self, input: &[D::Unit], input_index: usize, output: &mut [E::Unit], output_index: usize, ) -> Result<TranscodeProgress, TranscodeError<CodecConvertError<<D as Codec>::DecodeError, <E as Codec>::EncodeError>>>

Converts source units into target units.

This is the main streaming operation and does not require D::Value to implement Default.

§Parameters
  • input: Source unit slice.
  • input_index: Absolute source index where conversion starts.
  • output: Target unit slice.
  • output_index: Absolute target index where writing starts.
§Returns

Returns conversion progress for consumed/produced counters and stop reason.

§Errors

Returns converter error when source or target indices are invalid, or when decoding/encoding fails under current policy.

Source

pub fn finish( &mut self, output: &mut [E::Unit], output_index: usize, ) -> Result<usize, TranscodeError<CodecConvertError<<D as Codec>::DecodeError, <E as Codec>::EncodeError>>>
where D::Value: Default,

Finishes internally retained output after EOF.

Finalization delegates to the reusable converter engine. It drains retained pending output, encodes source-side decode flush values, and then finishes target-side encode hook state.

§Parameters
  • output: Target unit slice for finalization output.
  • output_index: Absolute target output index where writing starts.
§Returns

Returns the number of target units written by finalization.

§Errors

Returns a finish error for pending output that cannot be finalized.

Trait Implementations§

Source§

impl<D, E> Debug for CodecTranscodeConverter<D, E>
where D: Codec, E: Codec<Value = D::Value>, TranscodeConvertEngine<D, E, CodecTranscodeDecodeHooks, CodecTranscodeEncodeHooks>: Debug,

Source§

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

Formats the wrapped converter engine for debugging.

§Parameters
  • f: Destination formatter.
§Returns

Returns fmt::Result from the formatter.

Source§

impl<D, E> Default for CodecTranscodeConverter<D, E>
where D: Codec, E: Codec<Value = D::Value>, TranscodeConvertEngine<D, E, CodecTranscodeDecodeHooks, CodecTranscodeEncodeHooks>: Default,

Source§

fn default() -> Self

Creates a default codec-backed buffered converter.

§Returns

Returns a converter with default codecs and hooks.

Source§

impl<D, E> TranscodeConverter<<D as Codec>::Unit, <E as Codec>::Unit> for CodecTranscodeConverter<D, E>
where D: Codec, E: Codec<Value = D::Value>, D::Value: Default,

Source§

impl<D, E> Transcoder<<D as Codec>::Unit, <E as Codec>::Unit> for CodecTranscodeConverter<D, E>
where D: Codec, E: Codec<Value = D::Value>, D::Value: Default,

Source§

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

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

§Parameters
  • input_len: Source units the caller plans to convert.
§Returns

Returns a conservative upper bound for produced target units.

Source§

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

Returns the maximum target units emitted by finishing internal state.

§Returns

Returns a conservative upper bound for remaining converter-final output.

Source§

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

Returns the maximum target units emitted when resetting stream state.

Source§

fn reset( &mut self, output: &mut [E::Unit], output_index: usize, ) -> Result<usize, TranscodeError<Self::Error>>

Clears retained pending output, resets component state, and emits stream-start encode output.

Source§

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

Converts source units into target units.

§Parameters
  • input: Source unit slice.
  • input_index: Absolute source index where conversion starts.
  • output: Target unit slice.
  • output_index: Absolute target index where writing starts.
§Returns

Returns conversion progress for consumed/produced counters and stop reason.

§Errors

Returns converter error when source or target indices are invalid, or when decoding/encoding fails under current policy.

Source§

fn finish( &mut self, output: &mut [E::Unit], output_index: usize, ) -> Result<usize, TranscodeError<Self::Error>>

Finishes internally retained output after EOF.

§Parameters
  • output: Target unit slice for finalization output.
  • output_index: Absolute target output index where writing starts.
§Returns

Returns the number of target units written by finalization.

§Errors

Returns a finish error for pending output that cannot be finalized.

Source§

type Error = CodecConvertError<<D as Codec>::DecodeError, <E as Codec>::EncodeError>

Domain error reported by semantic conversion failures.

Auto Trait Implementations§

§

impl<D, E> Freeze for CodecTranscodeConverter<D, E>
where D: Freeze, E: Freeze, <D as Codec>::Value: Freeze,

§

impl<D, E> RefUnwindSafe for CodecTranscodeConverter<D, E>

§

impl<D, E> Send for CodecTranscodeConverter<D, E>
where D: Send, E: Send, <D as Codec>::Value: Send,

§

impl<D, E> Sync for CodecTranscodeConverter<D, E>
where D: Sync, E: Sync, <D as Codec>::Value: Sync,

§

impl<D, E> Unpin for CodecTranscodeConverter<D, E>
where D: Unpin, E: Unpin, <D as Codec>::Value: Unpin,

§

impl<D, E> UnsafeUnpin for CodecTranscodeConverter<D, E>

§

impl<D, E> UnwindSafe for CodecTranscodeConverter<D, E>
where D: UnwindSafe, E: UnwindSafe, <D as Codec>::Value: 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 = 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.