Skip to main content

CodecBufferedConverter

Struct CodecBufferedConverter 

Source
pub struct CodecBufferedConverter<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.

§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> CodecBufferedConverter<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 reset(&mut self)

Clears retained pending output and hook state.

§Returns

Returns unit ().

Source

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

Finishes internally retained output after EOF.

The strict codec-backed converter has no hook-owned final output. Finish drains any retained decoded value through the normal conversion path and then completes without requiring D::Value: Default.

§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> BufferedConverter<<D as Codec>::Unit, <E as Codec>::Unit> for CodecBufferedConverter<D, E>
where D: Codec, E: Codec<Value = D::Value>,

Source§

impl<D, E> BufferedTranscoder<<D as Codec>::Unit, <E as Codec>::Unit> for CodecBufferedConverter<D, E>
where D: Codec, E: Codec<Value = D::Value>,

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 reset(&mut self)

Clears retained pending output.

§Returns

Returns unit ().

Source§

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

Error reported for semantic conversion failures.
Source§

impl<D, E> Clone for CodecBufferedConverter<D, E>
where D: Codec, E: Codec<Value = D::Value>, BufferedConvertEngine<D, E, CodecBufferedConvertHooks>: Clone,

Source§

fn clone(&self) -> Self

Clones the wrapped converter engine.

§Returns

Returns a cloned converter adapter sharing the same inner engine state.

1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<D, E> Debug for CodecBufferedConverter<D, E>
where D: Codec, E: Codec<Value = D::Value>, BufferedConvertEngine<D, E, CodecBufferedConvertHooks>: 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 CodecBufferedConverter<D, E>
where D: Codec, E: Codec<Value = D::Value>, BufferedConvertEngine<D, E, CodecBufferedConvertHooks>: 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> Eq for CodecBufferedConverter<D, E>
where D: Codec, E: Codec<Value = D::Value>, BufferedConvertEngine<D, E, CodecBufferedConvertHooks>: Eq,

Source§

impl<D, E> Hash for CodecBufferedConverter<D, E>
where D: Codec, E: Codec<Value = D::Value>, BufferedConvertEngine<D, E, CodecBufferedConvertHooks>: Hash,

Source§

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

Hashes the wrapped converter engine.

§Parameters
  • state: Output hash state.
§Returns

Returns unit ().

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> PartialEq for CodecBufferedConverter<D, E>
where D: Codec, E: Codec<Value = D::Value>, BufferedConvertEngine<D, E, CodecBufferedConvertHooks>: PartialEq,

Source§

fn eq(&self, other: &Self) -> bool

Compares the wrapped converter engine.

§Parameters
  • other: Another converter to compare with.
§Returns

Returns true when the wrapped engines are equal.

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.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

§

impl<D, E> UnwindSafe for CodecBufferedConverter<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> 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.