pub trait Decodeable: Send + Sync {
// Required method
fn decode<R: ReadBytes>(
data: &mut R,
extra_data: &Option<DecodeableExtraData<'_>>,
) -> Result<Self>
where Self: Sized;
}Expand description
Generic trait for decoding binary data into structured types.
This trait provides a standardized interface for deserializing binary data from any
source implementing ReadBytes. All Total War file types
in RPFM implement this trait to enable consistent decoding behavior.
§Type Parameters
The trait is object-safe and requires Send + Sync to enable concurrent decoding operations.
§Examples
ⓘ
use rpfm_lib::files::{Decodeable, DecodeableExtraData};
use rpfm_lib::binary::ReadBytes;
let data = &[0x01, 0x02, 0x03, 0x04];
let extra_data = None;
let decoded = MyType::decode(&mut data.as_slice(), &extra_data)?;Required Methods§
Sourcefn decode<R: ReadBytes>(
data: &mut R,
extra_data: &Option<DecodeableExtraData<'_>>,
) -> Result<Self>where
Self: Sized,
fn decode<R: ReadBytes>(
data: &mut R,
extra_data: &Option<DecodeableExtraData<'_>>,
) -> Result<Self>where
Self: Sized,
Decodes binary data into the implementing type.
This method reads from any source implementing ReadBytes
and constructs an instance of the implementing type.
§Parameters
data: A mutable reference to a type implementingReadBytesextra_data: Optional additional context needed for decoding (schemas, game version, etc.)
§Returns
Returns Ok(Self) on successful decoding, or an error if the data is malformed or
insufficient context was provided.
§Errors
This function may return errors if:
- The binary data is corrupted or malformed
- Required schema information is missing from
extra_data - The data stream ends unexpectedly