pub trait Serializedwhere
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§
Sourcefn encode(&self) -> Vec<u8> ⓘ
fn encode(&self) -> Vec<u8> ⓘ
encode the type value into its binary representation.
this function insert the coresponding header at the beginning.
Sourcefn encode_inline(&self, data: &mut Vec<u8>)
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.
Sourcefn decode(data: &[u8]) -> Option<Self>
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.
Sourcefn decode_headless(data: &[u8]) -> Option<Self>
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.
Sourcefn decode_inline(data: &[u8], ind: &mut usize) -> Option<Self>
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.