Trait Decoder

Source
pub trait Decoder: Sized {
    // Required method
    fn decode(reader: &mut Bytes) -> Result<Self>;

    // Provided method
    fn unpack(reader: &mut Bytes) -> Result<Self> { ... }
}
Expand description

Trait for types that can be decoded from the senax binary format.

Implement this trait for your type to enable deserialization. Most users should use #[derive(Decode)] instead of manual implementation.

§Errors

Returns EncoderError if the value cannot be decoded or the data is invalid.

Required Methods§

Source

fn decode(reader: &mut Bytes) -> Result<Self>

Decode the value from the given buffer with schema evolution support.

This method expects field IDs and type tags for forward/backward compatibility. Use this when you need schema evolution support.

§Arguments
  • reader - The buffer to read the encoded bytes from.

Provided Methods§

Source

fn unpack(reader: &mut Bytes) -> Result<Self>

Unpack the value from the given buffer without schema evolution support.

This method expects data packed without field IDs and some type tags. Fields are decoded in declaration order. Use this when you need maximum performance and the data was packed with pack().

§Arguments
  • reader - The buffer to read the packed bytes from.
§Note
  • For structs: Field IDs are not expected, fields are decoded in declaration order
  • For enums: Variant IDs are still expected, but field IDs within variants are not
  • For primitives: Some type tags may be omitted, with relaxed validation

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Decoder for bool

Decodes a bool from a single tag byte.

§Errors

Returns an error if the tag is not TAG_ZERO or TAG_ONE.

Source§

fn unpack(reader: &mut Bytes) -> Result<Self>

Unpacks a bool from a single byte with relaxed validation.

0 is interpreted as false, any non-zero value is interpreted as true. No error checking is performed for invalid values.

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl Decoder for f32

Decodes an f32 from either 4 or 8 bytes (accepts f64 for compatibility with precision loss).

Source§

fn unpack(reader: &mut Bytes) -> Result<Self>

Unpacks an f32 from 4 bytes (little-endian IEEE 754) without expecting a type tag.

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl Decoder for f64

Decodes an f64 from 8 bytes (f32 cross-decoding not supported).

Source§

fn unpack(reader: &mut Bytes) -> Result<Self>

Unpacks an f64 from 8 bytes (little-endian IEEE 754) without expecting a type tag.

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl Decoder for i8

Decodes a i8 from the bit-inverted encoding.

§Errors

Returns an error if the tag is not valid for an i8.

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl Decoder for i16

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl Decoder for i32

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl Decoder for i64

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl Decoder for i128

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl Decoder for isize

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl Decoder for u8

Decodes a u8 from the compact format.

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl Decoder for u16

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl Decoder for u32

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl Decoder for u64

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl Decoder for u128

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl Decoder for ()

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl Decoder for usize

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl Decoder for String

Decodes a String from the senax binary format.

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl Decoder for Bytes

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl<K: Decoder + Eq + Hash, V: Decoder> Decoder for HashMap<K, V>

Decodes a map from the senax binary format.

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl<K: Decoder + Ord, V: Decoder> Decoder for BTreeMap<K, V>

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl<T0: Decoder> Decoder for (T0,)

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl<T0: Decoder, T1: Decoder> Decoder for (T0, T1)

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl<T0: Decoder, T1: Decoder, T2: Decoder> Decoder for (T0, T1, T2)

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl<T0: Decoder, T1: Decoder, T2: Decoder, T3: Decoder> Decoder for (T0, T1, T2, T3)

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl<T0: Decoder, T1: Decoder, T2: Decoder, T3: Decoder, T4: Decoder> Decoder for (T0, T1, T2, T3, T4)

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl<T0: Decoder, T1: Decoder, T2: Decoder, T3: Decoder, T4: Decoder, T5: Decoder> Decoder for (T0, T1, T2, T3, T4, T5)

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl<T0: Decoder, T1: Decoder, T2: Decoder, T3: Decoder, T4: Decoder, T5: Decoder, T6: Decoder> Decoder for (T0, T1, T2, T3, T4, T5, T6)

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl<T0: Decoder, T1: Decoder, T2: Decoder, T3: Decoder, T4: Decoder, T5: Decoder, T6: Decoder, T7: Decoder> Decoder for (T0, T1, T2, T3, T4, T5, T6, T7)

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl<T0: Decoder, T1: Decoder, T2: Decoder, T3: Decoder, T4: Decoder, T5: Decoder, T6: Decoder, T7: Decoder, T8: Decoder> Decoder for (T0, T1, T2, T3, T4, T5, T6, T7, T8)

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl<T0: Decoder, T1: Decoder, T2: Decoder, T3: Decoder, T4: Decoder, T5: Decoder, T6: Decoder, T7: Decoder, T8: Decoder, T9: Decoder> Decoder for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl<T0: Decoder, T1: Decoder, T2: Decoder, T3: Decoder, T4: Decoder, T5: Decoder, T6: Decoder, T7: Decoder, T8: Decoder, T9: Decoder, T10: Decoder> Decoder for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl<T0: Decoder, T1: Decoder, T2: Decoder, T3: Decoder, T4: Decoder, T5: Decoder, T6: Decoder, T7: Decoder, T8: Decoder, T9: Decoder, T10: Decoder, T11: Decoder> Decoder for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl<T: Decoder + 'static> Decoder for Vec<T>

Decodes a Vec<T> from the senax binary format.

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl<T: Decoder + Eq + Hash + 'static> Decoder for HashSet<T>

Decodes a set from the senax binary format.

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl<T: Decoder + Ord + 'static> Decoder for BTreeSet<T>

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl<T: Decoder> Decoder for Option<T>

Decodes an Option<T> from the senax binary format.

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl<T: Decoder> Decoder for Box<T>

Decodes a Box<T> by decoding the inner value and wrapping it in a Box.

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl<T: Decoder> Decoder for Arc<T>

Decodes an Arc<T> by decoding the inner value and wrapping it in an Arc.

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Source§

impl<T: Decoder, const N: usize> Decoder for [T; N]

Decodes a fixed-size array from the senax binary format.

Source§

fn decode(reader: &mut Bytes) -> Result<Self>

Implementors§