pub trait Serialization {
const HEAD: u16;
const TAIL: u16;
const SIZE: usize = 0usize;
// Required method
fn from_bytestream(
bytestream: &Vec<u8>,
pos: &mut usize,
) -> Result<Self, SerializationError>
where Self: Sized;
// Provided methods
fn verify_fixed(
stream: &Vec<u8>,
pos: &mut usize,
) -> Result<(), SerializationError> { ... }
fn from_tofpacket(packet: &TofPacket) -> Result<Self, SerializationError>
where Self: Sized { ... }
fn to_bytestream(&self) -> Vec<u8> { ... }
fn from_slice(
_slice: &[u8],
_start_pos: usize,
) -> Result<Self, SerializationError>
where Self: Sized { ... }
fn to_slice(&self) -> &[u8] ⓘ
where Self: Sized { ... }
}
Expand description
Encode/decode structs to Vec::<u8>
to write to a file or
send over the network
Required Associated Constants§
Provided Associated Constants§
Required Methods§
Sourcefn from_bytestream(
bytestream: &Vec<u8>,
pos: &mut usize,
) -> Result<Self, SerializationError>where
Self: Sized,
fn from_bytestream(
bytestream: &Vec<u8>,
pos: &mut usize,
) -> Result<Self, SerializationError>where
Self: Sized,
Decode a serializable from a bytestream
Provided Methods§
Sourcefn verify_fixed(
stream: &Vec<u8>,
pos: &mut usize,
) -> Result<(), SerializationError>
fn verify_fixed( stream: &Vec<u8>, pos: &mut usize, ) -> Result<(), SerializationError>
Verify that the serialized representation of the struct has the correct size, including header + footer.
Will panic for variable sized structs.
Sourcefn from_tofpacket(packet: &TofPacket) -> Result<Self, SerializationError>where
Self: Sized,
fn from_tofpacket(packet: &TofPacket) -> Result<Self, SerializationError>where
Self: Sized,
Decode a serializable directly from a TofPacket
Sourcefn to_bytestream(&self) -> Vec<u8>
fn to_bytestream(&self) -> Vec<u8>
Encode a serializable to a bytestream
fn from_slice(
_slice: &[u8],
_start_pos: usize,
) -> Result<Self, SerializationError>where
Self: Sized,
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.