pub trait FeagiSerializable: Debug + Any {
// Required methods
fn get_type(&self) -> FeagiByteStructureType;
fn get_version(&self) -> u8;
fn get_number_of_bytes_needed(&self) -> usize;
fn try_serialize_struct_to_byte_slice(
&self,
byte_destination: &mut [u8],
) -> Result<(), FeagiDataError>;
fn try_deserialize_and_update_self_from_byte_slice(
&mut self,
byte_reading: &[u8],
) -> Result<(), FeagiDataError>;
fn as_any(&self) -> &dyn Any;
// Provided methods
fn verify_byte_slice_is_of_correct_type(
&self,
byte_source: &[u8],
) -> Result<(), FeagiDataError> { ... }
fn verify_byte_slice_is_of_correct_version(
&self,
byte_source: &[u8],
) -> Result<(), FeagiDataError> { ... }
}Expand description
Trait for structures that can be serialized to and from FEAGI byte format.
Implementations must provide methods for determining their type, version, size requirements, and serialization/deserialization logic. The trait includes default validation methods for type and version checking.
Required Methods§
Sourcefn get_type(&self) -> FeagiByteStructureType
fn get_type(&self) -> FeagiByteStructureType
Returns the structure type identifier.
Sourcefn get_version(&self) -> u8
fn get_version(&self) -> u8
Returns the version number of this structure format.
Sourcefn get_number_of_bytes_needed(&self) -> usize
fn get_number_of_bytes_needed(&self) -> usize
Returns the total number of bytes needed for serialization.
Sourcefn try_serialize_struct_to_byte_slice(
&self,
byte_destination: &mut [u8],
) -> Result<(), FeagiDataError>
fn try_serialize_struct_to_byte_slice( &self, byte_destination: &mut [u8], ) -> Result<(), FeagiDataError>
Serializes this structure into the provided byte slice.
The slice must be exactly the size returned by get_number_of_bytes_needed.
Sourcefn try_deserialize_and_update_self_from_byte_slice(
&mut self,
byte_reading: &[u8],
) -> Result<(), FeagiDataError>
fn try_deserialize_and_update_self_from_byte_slice( &mut self, byte_reading: &[u8], ) -> Result<(), FeagiDataError>
Deserializes data from a byte slice and updates this structure.
Provided Methods§
Sourcefn verify_byte_slice_is_of_correct_type(
&self,
byte_source: &[u8],
) -> Result<(), FeagiDataError>
fn verify_byte_slice_is_of_correct_type( &self, byte_source: &[u8], ) -> Result<(), FeagiDataError>
Verifies that a byte slice contains data of the correct type.
Sourcefn verify_byte_slice_is_of_correct_version(
&self,
byte_source: &[u8],
) -> Result<(), FeagiDataError>
fn verify_byte_slice_is_of_correct_version( &self, byte_source: &[u8], ) -> Result<(), FeagiDataError>
Verifies that a byte slice contains data of the correct version.