Skip to main content

BufferedConvertEngine

Struct BufferedConvertEngine 

Source
pub struct BufferedConvertEngine<D, E, H>
where D: Codec, E: Codec<Value = D::Value>, H: BufferedConvertHooks<D, E>,
{ /* 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>
where D: Codec, E: Codec<Value = D::Value>, H: BufferedConvertHooks<D, E>,

Source

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.

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.

Source

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

Returns the maximum target units emitted by finishing retained state.

Source

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.

Source

pub fn finish( &mut self, output: &mut [E::Unit], output_index: usize, ) -> Result<usize, FinishError<<H as BufferedConvertHooks<D, E>>::Error>>
where D::Value: Default,

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.

Source

pub fn reset(&mut self)

Resets hook-owned and component-owned state.

§Parameters
  • self: Converter instance whose retained state is cleared.
§Returns

Returns unit ().

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,

Source§

fn clone(&self) -> BufferedConvertEngine<D, E, H>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

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§

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

Formats the value using the given formatter. Read more
Source§

impl<D, E, H> Default for BufferedConvertEngine<D, E, H>
where D: Codec + Default, E: Codec<Value = D::Value> + Default, H: BufferedConvertHooks<D, E> + Default,

Source§

fn default() -> Self

Creates a default buffered converter engine.

§Returns

Returns a converter engine constructed from default codecs and hooks.

Source§

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,

Source§

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

Feeds this value into the given Hasher. Read more
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, H> PartialEq for BufferedConvertEngine<D, E, H>

Source§

fn eq(&self, other: &BufferedConvertEngine<D, E, H>) -> bool

Tests for self and other values to be equal, and is used by ==.
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.
Source§

impl<D, E, H> StructuralPartialEq for BufferedConvertEngine<D, E, H>
where D: Codec, E: Codec<Value = D::Value>, H: BufferedConvertHooks<D, E>,

Auto Trait Implementations§

§

impl<D, E, H> Freeze for BufferedConvertEngine<D, E, H>

§

impl<D, E, H> RefUnwindSafe for BufferedConvertEngine<D, E, H>

§

impl<D, E, H> Send for BufferedConvertEngine<D, E, H>
where H: Send, D: Send, <H as BufferedConvertHooks<D, E>>::DecodeHooks: Send, E: Send, <H as BufferedConvertHooks<D, E>>::EncodeHooks: Send, <D as Codec>::Value: Send,

§

impl<D, E, H> Sync for BufferedConvertEngine<D, E, H>
where H: Sync, D: Sync, <H as BufferedConvertHooks<D, E>>::DecodeHooks: Sync, E: Sync, <H as BufferedConvertHooks<D, E>>::EncodeHooks: Sync, <D as Codec>::Value: Sync,

§

impl<D, E, H> Unpin for BufferedConvertEngine<D, E, H>
where H: Unpin, D: Unpin, <H as BufferedConvertHooks<D, E>>::DecodeHooks: Unpin, E: Unpin, <H as BufferedConvertHooks<D, E>>::EncodeHooks: Unpin, <D as Codec>::Value: Unpin,

§

impl<D, E, H> UnsafeUnpin for BufferedConvertEngine<D, E, H>

§

impl<D, E, H> UnwindSafe for BufferedConvertEngine<D, E, H>

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.