Expand description
In-memory table implementation with import/export capabilities.
This module provides TableInMemory, the primary concrete implementation of the
Table trait. It stores all table data in memory and supports multiple serialization
formats for data exchange.
§TableInMemory
TableInMemory is the standard table implementation used throughout RPFM. It holds:
- Complete table data as
Vec<Vec<DecodedData>> - Schema definition and patches
- Metadata (table name, altered flag)
§Creation and Loading
Tables can be created in several ways:
// Create empty table from definition
let table = TableInMemory::new(definition, None, "units_tables");
// Decode from binary data (most common)
// let table = TableInMemory::decode(&mut data, definition, &patches, Some(entry_count), false, "units_tables")?;§Supported Formats
§Binary Encoding
- decode/encode: Native Total War binary format
- Used for reading/writing binary files in PackFiles
- Compact, optimized for game performance
§TSV (Tab-Separated Values)
- tsv_import/tsv_export: Human-readable text format
- First line: metadata (
#table_name;version;path) - Second line: column names
- Remaining lines: data rows
- Handles special characters via escape sequences
- Key columns can be exported first for readability
§SQLite Database (optional, feature-gated)
- db_to_sql/sql_to_db: Store tables in SQLite for complex queries
- Each table version gets its own SQL table (
tablename_v123) - Tracks pack name, file name, vanilla status
- Useful for cross-table analysis and searching
§Schema Migration
The set_definition method enables schema version migration:
- Columns are mapped by name (not position)
- New columns get default values
- Removed columns are dropped
- Type changes trigger automatic conversion
- Data integrity is preserved where possible
This allows tables from older game versions to be updated to newer schemas.
§Data Integrity
The altered flag tracks if data was modified during decoding:
- Set to
trueif invalid numeric values were clamped - Set to
trueif type conversions occurred - Used to warn users about potential data corruption
§Implementation Details
- Uses
getsetfor accessor generation - Implements
Clone,Debug,PartialEqfor testability - Serializable via serde for IPC and caching
- Thread-safe through
Tabletrait’sSend + Syncrequirement
Structs§
- Table
InMemory - In-memory representation of a decoded table with full data and schema.