Skip to main content

Module twoda

Module twoda 

Source
Expand description

2DA binary table support. 2DA V2.b binary reader and writer.

2DA is a compact table format used for gameplay metadata. The binary form stores column headers, row labels, a cell-offset matrix, and a shared string table.

§Shape of the binary form

Six blocks and no offsets to any of them: signature, column headers, a row count, row labels, a cell offset matrix, and a shared string table. Parsing is strictly sequential, so a malformed block does not cause one bad lookup, it invalidates everything after it.

Cell offsets are u16, which caps the string table at 64 KiB. Deduplication is what keeps real tables inside that, since a 2DA column is typically a few distinct values repeated down thousands of rows – which is why this writer deduplicates rather than merely producing deterministic output. Writing each cell’s string separately can overflow a table the game ships happily.

Block contents and the text form’s differences are in docs/src/formats/text/2da.md, with the engine’s own load sequence.

Structs§

TwoDa
In-memory representation of a binary 2DA table.
TwoDaBinaryOptions
Encoding options for binary 2DA reader/writer operations.
TwoDaRow
One row in a 2DA table.

Enums§

TwoDaBinaryError
Errors produced while parsing or serializing binary 2DA data.

Functions§

read_twoda
Reads a binary 2DA from a reader.
read_twoda_auto
Auto-detects the format from file extension and reads accordingly.
read_twoda_from_bytes
Reads a binary 2DA (2DA V2.b) from in-memory bytes.
read_twoda_from_bytes_with_options
Reads a binary 2DA (2DA V2.b) from in-memory bytes with explicit text options.
read_twoda_with_options
Reads a binary 2DA from a reader with explicit text options.
write_twoda
Writes a binary 2DA (2DA V2.b) to a writer.
write_twoda_to_vec
Serializes a binary 2DA to a byte vector.
write_twoda_to_vec_with_options
Serializes a binary 2DA to a byte vector with explicit text options.
write_twoda_with_options
Writes a binary 2DA (2DA V2.b) to a writer with explicit text options.