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§
Sourceconst SERIALIZED_SIZE: usize
const SERIALIZED_SIZE: usize
the size of this type when serialized to a packed binary format.
Required Associated Types§
Sourcetype RecursiveArray: RecursiveArray<u8>
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§
Sourcefn binary_serialize(&self, buf: &mut [u8], endianness: Endianness)
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.
Sourcefn binary_deserialize(
buf: &[u8],
endianness: Endianness,
) -> Result<Self, DeserializeError>
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§
Sourcefn binary_serialize_to_array(
&self,
endianness: Endianness,
) -> Self::RecursiveArray
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.