pub struct CodecValueEncoder<C> { /* private fields */ }Expand description
Encodes one borrowed value into owned units by using a Codec.
CodecValueEncoder is the default bridge from the low-level unchecked
Codec contract to the convenience-layer ValueEncoder contract. Each
call emits stream-start output through Codec::encode_reset, encodes one
value through Codec::encode, finishes encode-side state through
Codec::encode_finish, and returns the owned output truncated to the
units actually written.
§Type Parameters
C: Low-level codec used to encode one value.
Implementations§
Source§impl<C> CodecValueEncoder<C>where
C: Codec,
impl<C> CodecValueEncoder<C>where
C: Codec,
Sourcepub fn new(codec: C) -> Self
pub fn new(codec: C) -> Self
Creates an encoder backed by codec.
§Parameters
codec: Low-level codec used to encode one value.
§Returns
Returns a value encoder adapter for the supplied codec.
§Compile-Time Checks
Fails to compile when the supplied codec declares a zero decode unit
bound or when Codec::MIN_UNITS_PER_VALUE exceeds
Codec::MAX_DECODE_UNITS_PER_VALUE. The encode bound may be zero for
a fully buffered 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 encode_into(
&mut self,
input: &C::Value,
output: &mut Vec<C::Unit>,
) -> Result<usize, TranscodeEncodeErrorOf<C>>
pub fn encode_into( &mut self, input: &C::Value, output: &mut Vec<C::Unit>, ) -> Result<usize, TranscodeEncodeErrorOf<C>>
Encodes one borrowed value and appends the emitted units to output.
This method is the reusable-buffer counterpart of
ValueEncoder::encode. It emits stream-start output through
Codec::encode_reset, encodes input through Codec::encode, and
finishes encode-side state through Codec::encode_finish, appending
only the units actually written. When encoding fails, the vector length
is restored to its original value.
§Parameters
input: Value to encode.output: Destination vector receiving appended encoded units.
§Returns
Returns the number of units appended to output.
§Errors
Returns the wrapped codec’s encode error when reset output, input, or
finish output cannot be represented. Returns a framework error when
output length arithmetic overflows.
§Panics
Panics when the wrapped codec reports more reset or finish output than
its declared bounds, when Codec::encode_len exceeds
Codec::MAX_ENCODE_UNITS_PER_VALUE, or when encoding writes a
different value width than Codec::encode_len.
Trait Implementations§
Source§impl<C> Debug for CodecValueEncoder<C>
impl<C> Debug for CodecValueEncoder<C>
Source§impl<C> Default for CodecValueEncoder<C>
impl<C> Default for CodecValueEncoder<C>
Source§impl<C> ValueEncoder<<C as Codec>::Value> for CodecValueEncoder<C>
impl<C> ValueEncoder<<C as Codec>::Value> for CodecValueEncoder<C>
Source§fn encode(&mut self, input: &C::Value) -> Result<Self::Output, Self::Error>
fn encode(&mut self, input: &C::Value) -> Result<Self::Output, Self::Error>
Encodes one borrowed value into owned units.
§Parameters
input: Value to encode.
§Returns
Returns stream-start output followed by the units written for input
and any encode-finish output.
§Errors
Returns the wrapped codec’s encode error when reset output, input, or
finish output cannot be represented.
§Panics
Panics when the wrapped codec reports more reset or finish output than
its declared bounds, or a value width different from
Codec::encode_len.