pub trait Serialization {
const HEAD: u16 = 43_690u16;
const TAIL: u16 = 21_845u16;
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_bytestream_alt(
bytestream: &Vec<u8>,
pos: &mut usize,
) -> Result<Self, SerializationError>
where Self: Sized { ... }
fn to_bytestream(&self) -> Vec<u8> ⓘ { ... }
}
Expand description
Encode/decode structs to Vec::<u8>
to write to a file or
send over the network
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
§Arguments:
- bytestream : bytes including the ones which should be decoded
- pos : first byte in the bytestream which is part of the expected payload
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_bytestream_alt(
bytestream: &Vec<u8>,
pos: &mut usize,
) -> Result<Self, SerializationError>where
Self: Sized,
fn from_bytestream_alt(
bytestream: &Vec<u8>,
pos: &mut usize,
) -> Result<Self, SerializationError>where
Self: Sized,
Decode a serializable from a bytestream. This provides an alternative method to get the packet. If not implemented, it will be the same as from_bytestream.
§Arguments:
- bytestream : bytes including the ones which should be decoded
- pos : first byte in the bytestream which is part of the expected payload
Sourcefn to_bytestream(&self) -> Vec<u8> ⓘ
fn to_bytestream(&self) -> Vec<u8> ⓘ
Encode a serializable to a bytestream
This shall return a representation of the struct in such a way that to_bytestream and from_bytestream are inverse operations.
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.