Skip to main content

FixedCodec

Trait FixedCodec 

Source
pub trait FixedCodec {
    type Value<'wire>
       where Self: 'wire;
    type EncodeError: Debug;
    type Plan<'value>: EncodePlan
       where Self: 'value;

    const WIDTH: usize;

    // Required methods
    fn decode<'wire>(bytes: &'wire [u8]) -> Self::Value<'wire>;
    fn plan<'value>(
        value: Self::Value<'value>,
    ) -> Result<Self::Plan<'value>, Self::EncodeError>;
}
Expand description

A codec whose encoded representation always has one fixed width.

Self::WIDTH must be nonzero. Every successful Self::plan must report that exact encoded length. For every such plan, EncodePlan::write_into called with an output slice of exactly Self::WIDTH bytes must write a complete representation whose decoding recovers the same semantic value supplied to Self::plan. Decoding is total for every exact-width byte pattern. A codec that violates these requirements is contract-invalid.

When a layout builder derives a region length through Self::Value<'static>: TryFrom<usize>, the complete conversion and codec round trip must preserve that length: converting the decoded planned representation back to usize must produce the original region length.

Self::plan completes all fallible encoding work before a caller mutates an output buffer. Layout parsing establishes exact-width bounds before calling Self::decode.

Required Associated Constants§

Source

const WIDTH: usize

Number of bytes in every encoded representation.

Required Associated Types§

Source

type Value<'wire> where Self: 'wire

Semantic value represented by an exact-width wire representation.

Source

type EncodeError: Debug

Error returned while preparing an encoded value.

Source

type Plan<'value>: EncodePlan where Self: 'value

Prepared fixed-width encoded bytes.

Required Methods§

Source

fn decode<'wire>(bytes: &'wire [u8]) -> Self::Value<'wire>

Decodes an exact-width encoded representation.

Source

fn plan<'value>( value: Self::Value<'value>, ) -> Result<Self::Plan<'value>, Self::EncodeError>

Prepares the complete encoded representation without mutating a caller buffer.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl FixedCodec for BeI16

Source§

const WIDTH: usize = 2

Source§

type Value<'wire> = i16 where Self: 'wire

Source§

type EncodeError = Infallible

Source§

type Plan<'value> = [u8; 2] where Self: 'value

Source§

impl FixedCodec for BeI32

Source§

const WIDTH: usize = 4

Source§

type Value<'wire> = i32 where Self: 'wire

Source§

type EncodeError = Infallible

Source§

type Plan<'value> = [u8; 4] where Self: 'value

Source§

impl FixedCodec for BeI64

Source§

const WIDTH: usize = 8

Source§

type Value<'wire> = i64 where Self: 'wire

Source§

type EncodeError = Infallible

Source§

type Plan<'value> = [u8; 8] where Self: 'value

Source§

impl FixedCodec for BeI128

Source§

const WIDTH: usize = 16

Source§

type Value<'wire> = i128 where Self: 'wire

Source§

type EncodeError = Infallible

Source§

type Plan<'value> = [u8; 16] where Self: 'value

Source§

impl FixedCodec for BeU16

Source§

const WIDTH: usize = 2

Source§

type Value<'wire> = u16 where Self: 'wire

Source§

type EncodeError = Infallible

Source§

type Plan<'value> = [u8; 2] where Self: 'value

Source§

impl FixedCodec for BeU24

Source§

const WIDTH: usize = 3

Source§

type Value<'wire> = u32 where Self: 'wire

Source§

type EncodeError = U24RangeError

Source§

type Plan<'value> = [u8; 3] where Self: 'value

Source§

impl FixedCodec for BeU32

Source§

const WIDTH: usize = 4

Source§

type Value<'wire> = u32 where Self: 'wire

Source§

type EncodeError = Infallible

Source§

type Plan<'value> = [u8; 4] where Self: 'value

Source§

impl FixedCodec for BeU64

Source§

const WIDTH: usize = 8

Source§

type Value<'wire> = u64 where Self: 'wire

Source§

type EncodeError = Infallible

Source§

type Plan<'value> = [u8; 8] where Self: 'value

Source§

impl FixedCodec for BeU128

Source§

const WIDTH: usize = 16

Source§

type Value<'wire> = u128 where Self: 'wire

Source§

type EncodeError = Infallible

Source§

type Plan<'value> = [u8; 16] where Self: 'value

Source§

impl FixedCodec for I8

Source§

const WIDTH: usize = 1

Source§

type Value<'wire> = i8 where Self: 'wire

Source§

type EncodeError = Infallible

Source§

type Plan<'value> = [u8; 1] where Self: 'value

Source§

impl FixedCodec for LeI16

Source§

const WIDTH: usize = 2

Source§

type Value<'wire> = i16 where Self: 'wire

Source§

type EncodeError = Infallible

Source§

type Plan<'value> = [u8; 2] where Self: 'value

Source§

impl FixedCodec for LeI32

Source§

const WIDTH: usize = 4

Source§

type Value<'wire> = i32 where Self: 'wire

Source§

type EncodeError = Infallible

Source§

type Plan<'value> = [u8; 4] where Self: 'value

Source§

impl FixedCodec for LeI64

Source§

const WIDTH: usize = 8

Source§

type Value<'wire> = i64 where Self: 'wire

Source§

type EncodeError = Infallible

Source§

type Plan<'value> = [u8; 8] where Self: 'value

Source§

impl FixedCodec for LeI128

Source§

const WIDTH: usize = 16

Source§

type Value<'wire> = i128 where Self: 'wire

Source§

type EncodeError = Infallible

Source§

type Plan<'value> = [u8; 16] where Self: 'value

Source§

impl FixedCodec for LeU16

Source§

const WIDTH: usize = 2

Source§

type Value<'wire> = u16 where Self: 'wire

Source§

type EncodeError = Infallible

Source§

type Plan<'value> = [u8; 2] where Self: 'value

Source§

impl FixedCodec for LeU24

Source§

const WIDTH: usize = 3

Source§

type Value<'wire> = u32 where Self: 'wire

Source§

type EncodeError = U24RangeError

Source§

type Plan<'value> = [u8; 3] where Self: 'value

Source§

impl FixedCodec for LeU32

Source§

const WIDTH: usize = 4

Source§

type Value<'wire> = u32 where Self: 'wire

Source§

type EncodeError = Infallible

Source§

type Plan<'value> = [u8; 4] where Self: 'value

Source§

impl FixedCodec for LeU64

Source§

const WIDTH: usize = 8

Source§

type Value<'wire> = u64 where Self: 'wire

Source§

type EncodeError = Infallible

Source§

type Plan<'value> = [u8; 8] where Self: 'value

Source§

impl FixedCodec for LeU128

Source§

const WIDTH: usize = 16

Source§

type Value<'wire> = u128 where Self: 'wire

Source§

type EncodeError = Infallible

Source§

type Plan<'value> = [u8; 16] where Self: 'value

Source§

impl FixedCodec for U8

Source§

const WIDTH: usize = 1

Source§

type Value<'wire> = u8 where Self: 'wire

Source§

type EncodeError = Infallible

Source§

type Plan<'value> = [u8; 1] where Self: 'value

Source§

impl<const N: usize> FixedCodec for Bytes<N>

Source§

const WIDTH: usize

Source§

type Value<'wire> = &'wire [u8] where Self: 'wire

Source§

type EncodeError = ExactWidthError

Source§

type Plan<'value> = &'value [u8] where Self: 'value