pub struct TableInMemory { /* private fields */ }Expand description
In-memory representation of a decoded table with full data and schema.
This is the primary table implementation in RPFM, storing all table rows in memory
along with their schema definition. Tables are typically accessed through the
Table trait interface rather than directly.
§Fields
- table_name: Identifies the table type (e.g., “units_tables”, “buildings_tables”)
- definition: Complete schema definition including column types and constraints
- definition_patch: Runtime modifications to the base schema for this specific table
- table_data: All table rows as a
Vec<Vec<DecodedData>>(outer vector is rows, inner is columns) - altered: Flag indicating if data was modified during decoding (e.g., invalid values corrected)
§Accessors
The struct uses the getset macro for automatic accessor generation:
table_name()/set_table_name(): Public getters/setters via getset- Schema and data: Accessed through
Tabletrait methods for type safety
§Thread Safety
This struct implements Send + Sync (via the Table trait requirement), allowing
safe concurrent read access and message passing between threads.
Implementations§
Source§impl TableInMemory
impl TableInMemory
Source§impl TableInMemory
impl TableInMemory
Sourcepub fn set_table_name(&mut self, val: String) -> &mut Self
pub fn set_table_name(&mut self, val: String) -> &mut Self
Table type identifier (e.g., “units_tables”).
Sourcepub fn set_altered(&mut self, val: bool) -> &mut Self
pub fn set_altered(&mut self, val: bool) -> &mut Self
Flag indicating data was altered during decoding (e.g., invalid values corrected).
Source§impl TableInMemory
impl TableInMemory
Sourcepub fn new(
definition: &Definition,
definition_patch: Option<&DefinitionPatch>,
table_name: &str,
) -> Self
pub fn new( definition: &Definition, definition_patch: Option<&DefinitionPatch>, table_name: &str, ) -> Self
Creates a new empty table from a schema definition.
Initializes a table with no rows but with a complete schema definition. This is typically used when creating new tables from scratch or before importing data from external sources.
§Parameters
definition: Schema defining column structure, types, and constraintsdefinition_patch: Optional runtime modifications to the base schematable_name: Table type identifier (e.g., “units_tables”)
§Examples
// Create empty table for manual data entry
let mut table = TableInMemory::new(definition, None, "units_tables");
// Add rows using the Table trait methods
let new_row = table.new_row();
table.data_mut().push(new_row);Sourcepub fn decode<R: ReadBytes>(
data: &mut R,
definition: &Definition,
definition_patch: &DefinitionPatch,
entry_count: Option<u32>,
return_incomplete: bool,
table_name: &str,
) -> Result<Self>
pub fn decode<R: ReadBytes>( data: &mut R, definition: &Definition, definition_patch: &DefinitionPatch, entry_count: Option<u32>, return_incomplete: bool, table_name: &str, ) -> Result<Self>
Decodes a table from binary data using the provided schema.
This is the primary method for loading tables from PackFiles. It reads the binary format used by Total War games and converts it into an in-memory representation.
§Parameters
data: Binary data reader positioned at the table startdefinition: Schema definition for interpreting the binary datadefinition_patch: Runtime schema modificationsentry_count: Optional row count (ifNone, reads from data stream)return_incomplete: Iftrue, returns partial data on decode errors instead of failingtable_name: Table type identifier
§Behavior
- Reads entry count from stream if not provided
- Decodes each row according to schema field definitions
- Sets
alteredflag if invalid data is corrected during decoding - Can return incomplete tables for error recovery if requested
§Errors
Returns an error if:
- Binary data is corrupted or truncated
- Data types don’t match schema expectations
- Field decoding fails (unless
return_incompleteis true)
§Examples
// Decode table from binary PackFile data
let table = TableInMemory::decode(
data,
definition,
&HashMap::new(), // No patches
Some(100), // 100 entries
false, // Fail on errors
"units_tables"
)?;Sourcepub fn encode<W: WriteBytes>(&self, data: &mut W) -> Result<()>
pub fn encode<W: WriteBytes>(&self, data: &mut W) -> Result<()>
Encodes the table to binary format for writing to PackFiles.
Converts the in-memory table representation back to the binary format used
by Total War games. This is the inverse of decode.
§Parameters
data: Binary writer to receive the encoded table
§Format
The binary output includes:
- Entry count (u32)
- Row data encoded according to field types
- Applied schema patches are used during encoding
§Errors
Returns an error if:
- Writing to the output stream fails
- Data contains values that cannot be encoded in the target type
§Examples
// Encode table for saving to PackFile
table.encode(output)?;Trait Implementations§
Source§impl Clone for TableInMemory
impl Clone for TableInMemory
Source§fn clone(&self) -> TableInMemory
fn clone(&self) -> TableInMemory
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TableInMemory
impl Debug for TableInMemory
Source§impl<'de> Deserialize<'de> for TableInMemory
impl<'de> Deserialize<'de> for TableInMemory
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<Atlas> for TableInMemory
impl From<Atlas> for TableInMemory
Source§impl From<TableInMemory> for Atlas
impl From<TableInMemory> for Atlas
Source§fn from(value: TableInMemory) -> Self
fn from(value: TableInMemory) -> Self
Source§impl From<TableInMemory> for DB
Implementation to create a DB from a Table.
impl From<TableInMemory> for DB
Implementation to create a DB from a Table.
Source§fn from(table: TableInMemory) -> Self
fn from(table: TableInMemory) -> Self
Source§impl From<TableInMemory> for Loc
Implementation to create a Loc from a Table directly.
impl From<TableInMemory> for Loc
Implementation to create a Loc from a Table directly.
Source§fn from(table: TableInMemory) -> Self
fn from(table: TableInMemory) -> Self
Source§impl PartialEq for TableInMemory
impl PartialEq for TableInMemory
Source§impl Serialize for TableInMemory
impl Serialize for TableInMemory
Source§impl Table for TableInMemory
impl Table for TableInMemory
Source§fn definition(&self) -> &Definition
fn definition(&self) -> &Definition
Source§fn patches(&self) -> &DefinitionPatch
fn patches(&self) -> &DefinitionPatch
Source§fn data_mut(&mut self) -> &mut Vec<Vec<DecodedData>>
fn data_mut(&mut self) -> &mut Vec<Vec<DecodedData>>
Source§fn set_definition(&mut self, new_definition: &Definition)
fn set_definition(&mut self, new_definition: &Definition)
Source§fn set_data(&mut self, data: &[Vec<DecodedData>]) -> Result<()>
fn set_data(&mut self, data: &[Vec<DecodedData>]) -> Result<()>
Source§fn column_position_by_name(&self, column_name: &str) -> Option<usize>
fn column_position_by_name(&self, column_name: &str) -> Option<usize>
impl StructuralPartialEq for TableInMemory
Auto Trait Implementations§
impl Freeze for TableInMemory
impl RefUnwindSafe for TableInMemory
impl Send for TableInMemory
impl Sync for TableInMemory
impl Unpin for TableInMemory
impl UnsafeUnpin for TableInMemory
impl UnwindSafe for TableInMemory
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.