Skip to main content

CodecValueDecoder

Struct CodecValueDecoder 

Source
pub struct CodecValueDecoder<C>
where C: Codec,
{ /* private fields */ }
Expand description

Decodes one encoded unit slice into one owned value by using a Codec.

CodecValueDecoder is the default bridge from the low-level unchecked Codec contract to the convenience-layer ValueDecoder contract. The supplied input slice must contain exactly one encoded value. The adapter runs the complete decode lifecycle, including Codec::decode_finish, before returning the decoded value.

§Type Parameters

  • C: Low-level codec used to decode one value.

Implementations§

Source§

impl<C> CodecValueDecoder<C>
where C: Codec,

Source

pub fn new(codec: C) -> Self

Creates a decoder backed by codec.

§Parameters
  • codec: Low-level codec used to decode one value.
§Returns

Returns a value decoder adapter for the supplied codec.

§Panics

Panics when the supplied codec declares invalid unit bounds or an invalid decode unit bounds.

Source

pub const fn codec(&self) -> &C

Returns a shared reference to the wrapped codec.

Source

pub fn codec_mut(&mut self) -> &mut C

Returns a mutable reference to the wrapped codec.

The next value operation starts a fresh codec lifecycle, so mutations are applied to the following operation.

Source

pub fn into_codec(self) -> C

Consumes the adapter and returns its wrapped codec.

Source

pub fn decode( &mut self, input: &[C::Unit], ) -> Result<C::Value, TranscodeDecodeErrorOf<C>>

Decodes exactly one encoded value from input.

§Parameters
  • input: Encoded units for exactly one value.
§Returns

Returns the decoded value.

Codecs that may emit decode reset or finish values must use Self::decode_lifecycle or Self::decode_lifecycle_with_scratch.

§Errors

Returns crate::TranscodeFailure::UnsupportedDecodeLifecycleOutput before inspecting input or running codec hooks when reset or finish may emit values. Returns crate::TranscodeFailure::IncompleteInput when fewer than Codec::MIN_UNITS_PER_VALUE units are available or when crate::DecodeFailure::Incomplete is reported by the codec. In this one-shot API, incomplete input is a terminal error rather than a resumable streaming status. Returns a domain error when the wrapped codec rejects or cannot finish the input. Returns crate::TranscodeFailure::TrailingInput when a value is decoded but extra input remains.

§Panics

Panics when the wrapped codec reports a consumed unit count larger than the input slice length or Codec::MAX_DECODE_UNITS_PER_VALUE.

Source

pub fn decode_lifecycle( &mut self, input: &[C::Unit], ) -> Result<DecodeLifecycleOutput<C::Value>, TranscodeDecodeErrorOf<C>>
where C::Value: Default,

Decodes exactly one value and preserves all lifecycle output.

§Parameters
  • input: Encoded units for exactly one value.
§Returns

Returns reset values, the main decoded value, and finish values in separate owned buffers.

§Errors

Returns a framework error when input is incomplete or has trailing units. Returns a phase-aware domain error when reset, decode, or finish fails.

§Panics

Panics when the wrapped codec violates its declared reset, decode, or finish bounds.

Source

pub fn decode_lifecycle_with_scratch( &mut self, input: &[C::Unit], reset_output: &mut [C::Value], finish_output: &mut [C::Value], ) -> Result<DecodeLifecycleProgress<C::Value>, TranscodeDecodeErrorOf<C>>

Decodes exactly one value into separate lifecycle output buffers.

§Parameters
  • input: Encoded units for exactly one value.
  • reset_output: Destination for values emitted by decode reset.
  • finish_output: Destination for values emitted by decode finish.
§Returns

Returns the main decoded value and the initialized lengths of both lifecycle output buffers.

§Errors

Returns a framework error before running any lifecycle hook when either output buffer is shorter than its corresponding codec bound. Also returns incomplete-input, trailing-input, or phase-aware domain errors.

§Panics

Panics when the wrapped codec violates its declared reset, decode, or finish bounds.

Trait Implementations§

Source§

impl<C> Debug for CodecValueDecoder<C>
where C: Codec + Debug,

Source§

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

Formats the decoder without requiring finished values to be printable.

Source§

impl<C> Default for CodecValueDecoder<C>
where C: Codec + Default,

Source§

fn default() -> Self

Creates a decoder from the default codec.

Source§

impl<C> ValueDecoder<[<C as Codec>::Unit]> for CodecValueDecoder<C>
where C: Codec,

Source§

type Output = <C as Codec>::Value

Decoded output type.
Source§

type Error = TranscodeDecodeError<<C as Codec>::DecodeError>

Decoding error type.
Source§

fn decode(&mut self, input: &[C::Unit]) -> Result<Self::Output, Self::Error>

Decodes input. Read more

Auto Trait Implementations§

§

impl<C> Freeze for CodecValueDecoder<C>
where C: Freeze,

§

impl<C> RefUnwindSafe for CodecValueDecoder<C>
where C: RefUnwindSafe,

§

impl<C> Send for CodecValueDecoder<C>
where C: Send,

§

impl<C> Sync for CodecValueDecoder<C>
where C: Sync,

§

impl<C> Unpin for CodecValueDecoder<C>
where C: Unpin,

§

impl<C> UnsafeUnpin for CodecValueDecoder<C>
where C: UnsafeUnpin,

§

impl<C> UnwindSafe for CodecValueDecoder<C>
where C: 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 = !

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.