Transform GFF (Generic File Format) files from/to native python types.
Python representation is (Struct) and (List) objects, which can be nested. They behave just like native python dictionaries and lists, but with some additional methods and properties to make life easier.
Since GFF has strong typing beyond what python offers natively, the module provides a number of custom types to represent the various field types that can be found in a GFF file.
All field types are subclasses of the native python types, and are used to enforce the GFF type system.
Module | _impl |
Undocumented |
Module | _reader |
Undocumented |
Module | _types |
Undocumented |
Module | _writer |
Undocumented |
From __init__.py
:
Class |
|
Undocumented |
Class |
|
Represents a localized string in the NWN engine. |
Class |
|
Undocumented |
Class |
|
Undocumented |
Class |
|
Undocumented |
Class |
|
Undocumented |
Class |
|
Undocumented |
Class |
|
Undocumented |
Class |
|
Undocumented |
Class |
|
Undocumented |
Class |
|
GFF Lists are just python lists of Structs. They carry no metadata. |
Class |
|
Undocumented |
Class |
|
Undocumented |
Class |
|
GFF Structs are just python dicts with .attr access and some metadata. |
Class | VOID |
Undocumented |
Class |
|
Undocumented |
Function | read |
Read a GFF data from a binary stream. |
Function | write |
Write a GFF data structure to a binary stream. |
Read a GFF data from a binary stream.
Example
>>> with open("file.gff", "rb") as f: ... root, file_type = gff.read(f) ... print(root)
Parameters | |
file:BinaryIO | The binary stream to read from. |
Returns | |
A tuple containing the root struct and the file type. |
Write a GFF data structure to a binary stream.
The structure must only use supported GFF types, as GFF is a strongly typed format and deviation from these will make the game fail to read them (e.g. storing a byte as a int will make the game not see it).
Example
>>> root = gff.Struct(0, Byte=gff.Byte(255), SomeStruct=gff.Struct(SomeKey=gff.CExoString("5"))) ... out = BytesIO() ... gff.write(out, root, "TEST")
Parameters | |
file:BinaryIO | The binary stream to write to. |
root:Struct | The root structure of the GFF file. |
filestr | The file type identifier (4 characters). |