Expand description
GFF binary container support. GFF V3.2 binary reader and writer.
GFF is a typed, table-backed binary graph format used for most KotOR game
data objects (UTC, UTI, ARE, DLG, and others).
§Shape of the container
A 56-byte header carrying an offset-and-count pair for each of six sections: structs, fields, labels, the field data blob, and two index arrays. Every section is located by its own header entry.
One trap worth knowing before reading the header: the last three counts are byte lengths while the first three are element counts.
§The overloaded word
Both struct and field records carry a data_or_offset that means different
things by context, with no discriminator stored beside it. On a field it is
the value itself when the type fits in four bytes and an offset into the data
blob or an index array otherwise. On a struct it is a field index directly
when field_count is exactly one, and a byte offset into the field indices
array for any other count.
Getting that wrong does not fail loudly, it reads a plausible number out of the wrong region, which is why this module validates every range before decoding rather than trusting the arithmetic.
§Logical Data Model
Gff
`-- root GffStruct
`-- [GffField(label, GffValue)]
`-- nested structs/lists recursively reference tablesOffsets in struct and field records reference table locations or blob offsets depending on field type. This module keeps those rules explicit and validates all ranges before decoding.
Macros§
Structs§
- Change
- What happened at one address, from open until now.
- Gff
- In-memory representation of a binary GFF file.
- GffDocument
- One open GFF file: its bytes, its tree, and what has happened to it.
- GffField
- One labeled GFF field.
- GffLabel
- Canonicalized GFF field label.
- GffLocalized
String - CExoLocString payload.
- GffLocalized
Substring - One localized substring entry.
- GffPath
- An address into a GFF tree, such as
ClassList[0].Class. - GffStruct
- One GFF struct node.
- GffWalk
- Every value in a GFF tree, in the order the file carries them.
Enums§
- GffBinary
Error - Errors produced while parsing or writing binary GFF data.
- GffDocument
Error - A path that does not parse, or does not name one field of this tree.
- GffLabel
Error - Error returned when constructing a
GffLabelfails validation. - GffPath
Error - A path that does not resolve, or an edit the tree will not take.
- GffPath
Parse Error - A path string that does not describe an address.
- GffPath
Segment - One step of a
GffPath. - GffValue
- Runtime value for one GFF field.
Constants§
- GENERIC_
FILE_ TYPE - The magic a GFF carries when it claims no format of its own.
- MAX_
GFF_ LABEL_ LEN - Maximum number of ASCII characters for a GFF field label.
Functions§
- get_
binary - Reads a
VOIDfield’s bytes. - get_
bool - Reads a boolean from numeric fields (non-zero is true).
- get_f32
- Reads an
f32from single/double fields. - get_i8
- Reads an
i8from compatible integer field encodings. - get_i16
- Reads an
i16from compatible integer field encodings. - get_i32
- Reads an
i32from compatible integer field encodings. - get_
locstring - Reads a localized-string field by reference.
- get_
resref - Reads a
ResReffield. - get_
string - Reads a string field.
- get_u8
- Reads a
u8from compatible integer field encodings. - get_u16
- Reads a
u16from compatible integer field encodings. - get_u32
- Reads a
u32from canonical integer encodings. - get_u64
- Reads a
u64from compatible integer field encodings. - get_
u32_ extended_ signed - Reads a
u32with additional signed-narrow coercions for compatibility. - read_
gff - Reads a binary GFF file from a reader.
- read_
gff_ from_ bytes - Reads a binary GFF file from bytes.
- upsert_
field - Updates an existing field value or inserts a new field when missing.
- write_
gff - Writes a GFF in binary V3.2 format.
- write_
gff_ to_ vec - Serializes a GFF to a byte vector.