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 source_codec(&self) -> &D

Returns a shared reference to the source codec.

Source

pub fn source_codec_mut(&mut self) -> &mut D

Returns a mutable reference to the source codec.

Mutating a codec during an active stream can invalidate that stream’s assumptions; reset the adapter before continuing with the new codec configuration.

Source

pub fn target_codec(&self) -> &E

Returns a shared reference to the target codec.

Source

pub fn target_codec_mut(&mut self) -> &mut E

Returns a mutable reference to the target codec.

Mutating a codec during an active stream can invalidate that stream’s assumptions; reset the adapter before continuing with the new codec configuration.

Source

pub fn into_codecs(self) -> (D, E)

Consumes the adapter and returns its source and target codecs.

Any buffered lifecycle state, pending value, and internal hooks are discarded.

Source

pub fn max_transcode_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 global maximum target units emitted by finishing internal state.

§Returns

Returns a conservative upper bound valid for every reachable converter state.

Source

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

Returns the maximum target units emitted when resetting stream state.

§Returns

Returns a conservative upper bound valid for every reachable converter state.

§Errors

Returns CapacityError::OutputLengthOverflow when component-bound arithmetic overflows.

Source

pub fn reset( &mut self, output: &mut [E::Unit], output_index: usize, ) -> Result<usize, TranscodeConvertErrorOf<D, E>>
where D::Value: Default,

Clears retained pending output, resets target state, and then encodes source-side reset values.

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.

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

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

§Errors

Returns a converter error when the output range is invalid or too small, or when decoder or encoder reset processing fails.

Source

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

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 transcode_eof( &mut self, input: &[D::Unit], input_index: usize, output: &mut [E::Unit], output_index: usize, ) -> Result<TranscodeProgress, TranscodeConvertErrorOf<D, E>>

Converts source units after the caller has established end of input.

Source

pub fn finish( &mut self, output: &mut [E::Unit], output_index: usize, ) -> Result<usize, TranscodeConvertErrorOf<D, E>>
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 for CodecTranscodeConverter<D, E>
where D: Codec, E: Codec<Value = D::Value>, D::Value: Default,

Source§

type DecodeError = <D as Codec>::DecodeError

Domain error type produced by source decoding.
Source§

type EncodeError = <E as Codec>::EncodeError

Domain error type produced by target encoding.
Source§

type Value = <D as Codec>::Value

Intermediate logical value type converted between source and target.
Source§

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

Source§

fn max_transcode_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 valid for every reachable converter state.

Source§

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

Returns the maximum target units emitted when resetting stream state.

§Returns

Returns a conservative upper bound valid for every reachable converter state.

§Errors

Returns CapacityError::OutputLengthOverflow when component-bound arithmetic overflows.

Source§

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

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

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

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

§Errors

Returns a converter error when the output range is invalid or too small, or when decoder or encoder reset processing fails.

Source§

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

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, TranscodeConvertErrorOf<D, E>>

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 Input = <D as Codec>::Unit

Input unit type accepted by this transcoder.
Source§

type Output = <E as Codec>::Unit

Output unit type produced by this transcoder.
Source§

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

Complete error type produced by this transcoder.
Source§

fn transcode_eof( &mut self, input: &[D::Unit], input_index: usize, output: &mut [E::Unit], output_index: usize, ) -> Result<TranscodeProgress, TranscodeConvertErrorOf<D, E>>

Converts source units after the caller has established end of input. Read more
Source§

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

Returns an upper bound for a complete reset -> transcode -> finish stream. Read more
Source§

fn transcode_complete_into( &mut self, input: &[Self::Input], output: &mut [Self::Output], ) -> Result<usize, Self::Error>

Runs a complete one-shot reset -> transcode -> finish stream. Read more

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.