Skip to main content

CodecValueExt

Trait CodecValueExt 

Source
pub trait CodecValueExt: Codec {
    // Provided methods
    fn max_encode_value_units(&self) -> Result<usize, CapacityError> { ... }
    fn encode_value_with_reset(
        &mut self,
        value: &Self::Value,
        output: &mut [Self::Unit],
        output_index: usize,
    ) -> CodecEncodeValueResult<Self::EncodeError> { ... }
    fn decode_value_with_flush(
        &mut self,
        input: &[Self::Unit],
        input_index: usize,
        flush_output: &mut [Self::Value],
        flush_output_index: usize,
    ) -> CodecDecodeValueWithFlushResult<Self::Value, Self::DecodeError> { ... }
    fn decode_exact_value_with_flush(
        &mut self,
        input: &[Self::Unit],
        flush_output: &mut [Self::Value],
        flush_output_index: usize,
    ) -> CodecDecodeExactValueWithFlushResult<Self::Value, Self::DecodeError> { ... }
}
Expand description

Extension trait for checked one-value codec operations.

CodecValueExt keeps convenience operations out of the low-level Codec contract while still making them available to all codec implementations. The methods compose primitive reset, encode, decode, and flush hooks with capacity checks and adapter-level error wrapping.

Provided Methods§

Source

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

Returns the maximum unit count emitted by one reset-prefixed value encode.

This is the checked sum of Codec::MAX_ENCODE_RESET_UNITS and Codec::MAX_UNITS_PER_VALUE. It is useful for callers that want to reuse scratch storage for repeated one-value encodes.

§Returns

Returns the maximum reset-plus-value output length.

§Errors

Returns CapacityError::OutputLengthOverflow when the sum cannot be represented as usize.

Source

fn encode_value_with_reset( &mut self, value: &Self::Value, output: &mut [Self::Unit], output_index: usize, ) -> CodecEncodeValueResult<Self::EncodeError>

Encodes one value after emitting reset output into a caller buffer.

The method validates the output index and the combined reset-plus-value capacity before calling the unchecked codec hooks. It is a convenience wrapper for code paths that need one complete value and want to reuse caller-owned storage.

§Parameters
  • value: Value to encode.
  • output: Destination unit buffer.
  • output_index: Start index in output.
§Returns

Returns the total number of reset and value units written.

§Errors

Returns TranscodeError when output bounds are invalid, when output capacity is insufficient, when output length arithmetic overflows, or when the codec cannot encode value.

§Panics

Panics when the codec writes or reports more units than its declared reset or value bound.

Source

fn decode_value_with_flush( &mut self, input: &[Self::Unit], input_index: usize, flush_output: &mut [Self::Value], flush_output_index: usize, ) -> CodecDecodeValueWithFlushResult<Self::Value, Self::DecodeError>

Decodes one value and flushes decode-side state into caller storage.

The method validates input and flush-output bounds before entering the unchecked codec hooks. It returns the decoded value, the consumed input count, and the number of flushed values written to flush_output.

§Parameters
  • input: Source unit buffer.
  • input_index: Start index in input.
  • flush_output: Destination value buffer for decode-flush output.
  • flush_output_index: Start index in flush_output.
§Returns

Returns (value, consumed, flushed).

§Errors

Returns TranscodeError when input or output bounds are invalid, when flush output capacity is insufficient, or when decoding or flushing fails.

§Panics

Panics when the codec consumes beyond available input or flushes more values than its declared bound.

Source

fn decode_exact_value_with_flush( &mut self, input: &[Self::Unit], flush_output: &mut [Self::Value], flush_output_index: usize, ) -> CodecDecodeExactValueWithFlushResult<Self::Value, Self::DecodeError>

Decodes exactly one value and then flushes decode-side state.

Unlike decode_value_with_flush, this helper requires the supplied input slice to contain exactly one encoded value. It validates trailing input before calling Codec::decode_flush, preserving whole-value decoder semantics while still centralizing flush scratch-buffer handling.

§Parameters
  • input: Source units for exactly one encoded value.
  • flush_output: Destination value buffer for decode-flush output.
  • flush_output_index: Start index in flush_output.
§Returns

Returns (value, flushed).

§Errors

Returns TranscodeError when flush output bounds are invalid or insufficient, when decoding fails, or when exact-value decode semantics are not satisfied.

§Panics

Panics when the codec consumes beyond available input or flushes more values than its declared bound.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<C> CodecValueExt for C
where C: Codec + ?Sized,