Trait CRSerializeable

Source
pub trait CRSerializeable {
    const CRHEAD: u16 = 43_690u16;
    const CRTAIL: u16 = 21_845u16;
    const CRSIZE: usize = 0usize;

    // Required methods
    fn deserialize(
        bytestream: &Vec<u8>,
        pos: &mut usize,
    ) -> Result<Self, CRSerializationError>
       where Self: Sized;
    fn serialize(&self) -> Vec<u8> ;

    // Provided method
    fn verify_fixed(
        stream: &Vec<u8>,
        pos: &mut usize,
    ) -> Result<(), CRSerializationError> { ... }
}

Provided Associated Constants§

Source

const CRHEAD: u16 = 43_690u16

Source

const CRTAIL: u16 = 21_845u16

Source

const CRSIZE: usize = 0usize

The SIZE is the size of the serialized bytestream INCLUDING 4 bytes for head and tail bytes. In case the struct does NOT HAVE a fixed size, SIZE will be 0 (so default value of the trait

Required Methods§

Source

fn deserialize( bytestream: &Vec<u8>, pos: &mut usize, ) -> Result<Self, CRSerializationError>
where Self: Sized,

Decode a serializable from a bytestream

Source

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

Encode a serializable to a bytestream

Provided Methods§

Source

fn verify_fixed( stream: &Vec<u8>, pos: &mut usize, ) -> Result<(), CRSerializationError>

Verify that the serialized representation of the struct has the correct size, including header + footer.

Will panic for variable sized structs.

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§