BinarySerde

Trait BinarySerde 

Source
pub trait BinarySerde: Sized {
    type RecursiveArray: RecursiveArray<u8>;

    const SERIALIZED_SIZE: usize;

    // Required methods
    fn binary_serialize(&self, buf: &mut [u8], endianness: Endianness);
    fn binary_deserialize(
        buf: &[u8],
        endianness: Endianness,
    ) -> Result<Self, DeserializeError>;

    // Provided method
    fn binary_serialize_to_array(
        &self,
        endianness: Endianness,
    ) -> Self::RecursiveArray { ... }
}
Expand description

a trait for serializing and deserializing a type into a packed binary format.

Required Associated Constants§

Source

const SERIALIZED_SIZE: usize

the size of this type when serialized to a packed binary format.

Required Associated Types§

Source

type RecursiveArray: RecursiveArray<u8>

the fixed size recursive array type that is returned when serializing this type to an array. the length of this array is guaranteed to be equal to Self::SERIALIZED_SIZE.

Required Methods§

Source

fn binary_serialize(&self, buf: &mut [u8], endianness: Endianness)

serialize this value into the given buffer using the given endianness.

§Panics

this function panics if the length of buf is not exactly equal to Self::SERIALIZED_SIZE.

Source

fn binary_deserialize( buf: &[u8], endianness: Endianness, ) -> Result<Self, DeserializeError>

deserializes the given buffer using the given endianness into a value of this type.

§Errors

this function return an error if the given bytes do not represent a valid value of this type. this can only ever happen if during deserialization we got an enum value that does not match any of the enum’s variants.

§Panics

this function panics if the length of buf is not exactly equal to Self::SERIALIZED_SIZE.

Provided Methods§

Source

fn binary_serialize_to_array( &self, endianness: Endianness, ) -> Self::RecursiveArray

serialize this value to a fixed size array using the given endianness.

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 BinarySerde for bool

Source§

impl BinarySerde for f32

Source§

const SERIALIZED_SIZE: usize = 4usize

Source§

type RecursiveArray = RecursiveArrayArrayWrapper<{$size}, u8>

Source§

fn binary_serialize(&self, buf: &mut [u8], endianness: Endianness)

Source§

fn binary_deserialize( buf: &[u8], endianness: Endianness, ) -> Result<Self, DeserializeError>

Source§

impl BinarySerde for f64

Source§

const SERIALIZED_SIZE: usize = 8usize

Source§

type RecursiveArray = RecursiveArrayArrayWrapper<{$size}, u8>

Source§

fn binary_serialize(&self, buf: &mut [u8], endianness: Endianness)

Source§

fn binary_deserialize( buf: &[u8], endianness: Endianness, ) -> Result<Self, DeserializeError>

Source§

impl BinarySerde for i8

Source§

impl BinarySerde for i16

Source§

const SERIALIZED_SIZE: usize = 2usize

Source§

type RecursiveArray = RecursiveArrayArrayWrapper<{$size}, u8>

Source§

fn binary_serialize(&self, buf: &mut [u8], endianness: Endianness)

Source§

fn binary_deserialize( buf: &[u8], endianness: Endianness, ) -> Result<Self, DeserializeError>

Source§

impl BinarySerde for i32

Source§

const SERIALIZED_SIZE: usize = 4usize

Source§

type RecursiveArray = RecursiveArrayArrayWrapper<{$size}, u8>

Source§

fn binary_serialize(&self, buf: &mut [u8], endianness: Endianness)

Source§

fn binary_deserialize( buf: &[u8], endianness: Endianness, ) -> Result<Self, DeserializeError>

Source§

impl BinarySerde for i64

Source§

const SERIALIZED_SIZE: usize = 8usize

Source§

type RecursiveArray = RecursiveArrayArrayWrapper<{$size}, u8>

Source§

fn binary_serialize(&self, buf: &mut [u8], endianness: Endianness)

Source§

fn binary_deserialize( buf: &[u8], endianness: Endianness, ) -> Result<Self, DeserializeError>

Source§

impl BinarySerde for i128

Source§

const SERIALIZED_SIZE: usize = 16usize

Source§

type RecursiveArray = RecursiveArrayArrayWrapper<{$size}, u8>

Source§

fn binary_serialize(&self, buf: &mut [u8], endianness: Endianness)

Source§

fn binary_deserialize( buf: &[u8], endianness: Endianness, ) -> Result<Self, DeserializeError>

Source§

impl BinarySerde for u8

Source§

impl BinarySerde for u16

Source§

const SERIALIZED_SIZE: usize = 2usize

Source§

type RecursiveArray = RecursiveArrayArrayWrapper<{$size}, u8>

Source§

fn binary_serialize(&self, buf: &mut [u8], endianness: Endianness)

Source§

fn binary_deserialize( buf: &[u8], endianness: Endianness, ) -> Result<Self, DeserializeError>

Source§

impl BinarySerde for u32

Source§

const SERIALIZED_SIZE: usize = 4usize

Source§

type RecursiveArray = RecursiveArrayArrayWrapper<{$size}, u8>

Source§

fn binary_serialize(&self, buf: &mut [u8], endianness: Endianness)

Source§

fn binary_deserialize( buf: &[u8], endianness: Endianness, ) -> Result<Self, DeserializeError>

Source§

impl BinarySerde for u64

Source§

const SERIALIZED_SIZE: usize = 8usize

Source§

type RecursiveArray = RecursiveArrayArrayWrapper<{$size}, u8>

Source§

fn binary_serialize(&self, buf: &mut [u8], endianness: Endianness)

Source§

fn binary_deserialize( buf: &[u8], endianness: Endianness, ) -> Result<Self, DeserializeError>

Source§

impl BinarySerde for u128

Source§

const SERIALIZED_SIZE: usize = 16usize

Source§

type RecursiveArray = RecursiveArrayArrayWrapper<{$size}, u8>

Source§

fn binary_serialize(&self, buf: &mut [u8], endianness: Endianness)

Source§

fn binary_deserialize( buf: &[u8], endianness: Endianness, ) -> Result<Self, DeserializeError>

Source§

impl BinarySerde for ()

Source§

impl<T> BinarySerde for PhantomData<T>

Source§

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

Implementors§

Source§

impl<const PADDING_LENGTH: usize, const PADDING_VALUE: u8> BinarySerde for BinarySerdePadding<PADDING_LENGTH, PADDING_VALUE>