Skip to main content

Serialized

Trait Serialized 

Source
pub trait Serialized
where Self: Sized,
{ // Required methods fn encode(&self) -> Vec<u8> ; fn encode_inline(&self, data: &mut Vec<u8>); fn decode(data: &[u8]) -> Option<Self>; fn decode_headless(data: &[u8]) -> Option<Self>; fn decode_inline(data: &[u8], ind: &mut usize) -> Option<Self>; }
Expand description

trait for types that can be serialized and deserialized.

this trait is automatically implemented for every generated type in generated serialization code.

Required Methods§

Source

fn encode(&self) -> Vec<u8>

encode the type value into its binary representation.

this function insert the coresponding header at the beginning.

Source

fn encode_inline(&self, data: &mut Vec<u8>)

encode the type value into its binary representation into the end of a given buffer.

this function does not insert any header.

Source

fn decode(data: &[u8]) -> Option<Self>

decode a type value from its binary representation.

this function expect the data to only contain the encoded value with its corresponding header.

it returns None on errors.

Source

fn decode_headless(data: &[u8]) -> Option<Self>

decode a type value from its binary representation.

this function is same as decode except that it expect only the encoded data not its header.

Source

fn decode_inline(data: &[u8], ind: &mut usize) -> Option<Self>

decode a type value from its binary representation at an specified index.

this function expect only the encoded data, and allows additional data after the value.

it advances the index, and returns None on errors.

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.

Implementors§