Skip to main content

Decodeable

Trait Decodeable 

Source
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§

Source

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 implementing ReadBytes
  • extra_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

Implementors§

Source§

impl Decodeable for Anim

Source§

impl Decodeable for AnimFragmentBattle

Source§

impl Decodeable for AnimPack

Source§

impl Decodeable for AnimsTable

Source§

impl Decodeable for Atlas

Source§

impl Decodeable for Audio

Source§

impl Decodeable for BuildingReference

Source§

impl Decodeable for Flags

Source§

impl Decodeable for Properties

Source§

impl Decodeable for ColourRGB

Source§

impl Decodeable for ColourRGBA

Source§

impl Decodeable for Cube

Source§

impl Decodeable for Outline2d

Source§

impl Decodeable for Outline3d

Source§

impl Decodeable for Point2d

Source§

impl Decodeable for Point3d

Source§

impl Decodeable for Polygon2d

Source§

impl Decodeable for Quaternion

Source§

impl Decodeable for Rectangle

Source§

impl Decodeable for Transform3x4

Source§

impl Decodeable for Transform4x4

Source§

impl Decodeable for Bmd

Source§

impl Decodeable for BmdVegetation

Source§

impl Decodeable for Cs2Collision

Source§

impl Decodeable for Cs2Parsed

Source§

impl Decodeable for Dat

Source§

impl Decodeable for DB

Source§

impl Decodeable for ESF

Source§

impl Decodeable for Font

Source§

impl Decodeable for GroupFormations

Source§

impl Decodeable for HlslCompiled

Source§

impl Decodeable for Image

Source§

impl Decodeable for Loc

Source§

impl Decodeable for MatchedCombat

Source§

impl Decodeable for Pack

Source§

impl Decodeable for PortraitSettings

Source§

impl Decodeable for RigidModel

Source§

impl Decodeable for SoundBank

Source§

impl Decodeable for SoundBankDatabase

Source§

impl Decodeable for SoundEvents

Source§

impl Decodeable for Text

Source§

impl Decodeable for TileDatabase

Source§

impl Decodeable for UIC

Source§

impl Decodeable for UnitVariant

Source§

impl Decodeable for Unknown

Source§

impl Decodeable for Video