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,
impl<C> CodecValueDecoder<C>where
C: Codec,
Sourcepub fn codec_mut(&mut self) -> &mut C
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.
Sourcepub fn into_codec(self) -> C
pub fn into_codec(self) -> C
Consumes the adapter and returns its wrapped codec.
Sourcepub fn decode(
&mut self,
input: &[C::Unit],
) -> Result<C::Value, TranscodeDecodeErrorOf<C>>
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.
Sourcepub fn decode_lifecycle(
&mut self,
input: &[C::Unit],
) -> Result<DecodeLifecycleOutput<C::Value>, TranscodeDecodeErrorOf<C>>
pub fn decode_lifecycle( &mut self, input: &[C::Unit], ) -> Result<DecodeLifecycleOutput<C::Value>, TranscodeDecodeErrorOf<C>>
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.
Sourcepub 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>>
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.