pub trait Encodeable: Send + Sync {
// Required method
fn encode<W: WriteBytes>(
&mut self,
buffer: &mut W,
extra_data: &Option<EncodeableExtraData<'_>>,
) -> Result<()>;
}Expand description
Generic trait for encoding structured types into binary data.
This trait provides a standardized interface for serializing structured data to any
destination implementing WriteBytes. All Total War file types
in RPFM implement this trait to enable consistent encoding behavior.
§Type Parameters
The trait is object-safe and requires Send + Sync to enable concurrent encoding operations.
§Examples
use rpfm_lib::files::{Encodeable, EncodeableExtraData};
use rpfm_lib::binary::WriteBytes;
let mut buffer = Vec::new();
let extra_data = None;
my_instance.encode(&mut buffer, &extra_data)?;Required Methods§
Sourcefn encode<W: WriteBytes>(
&mut self,
buffer: &mut W,
extra_data: &Option<EncodeableExtraData<'_>>,
) -> Result<()>
fn encode<W: WriteBytes>( &mut self, buffer: &mut W, extra_data: &Option<EncodeableExtraData<'_>>, ) -> Result<()>
Encodes the implementing type into binary data.
This method writes to any destination implementing WriteBytes,
serializing the instance’s data in the appropriate Total War file format.
§Parameters
buffer: A mutable reference to a type implementingWriteBytesextra_data: Optional additional context needed for encoding (schemas, game version, etc.)
§Returns
Returns Ok(()) on successful encoding, or an error if the encoding process fails.
§Errors
This function may return errors if:
- Writing to the buffer fails
- Required schema information is missing from
extra_data - The data contains invalid values that cannot be serialized
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.