Skip to main content

Module key

Module key 

Source
Expand description

KEY index support. KEY binary reader and writer.

KEY files are global resource indexes that map (resref, type) pairs to a packed resource_id that identifies both:

  • which BIF file contains the resource, and
  • which entry inside that BIF file to load.

§Shape of the container

A fixed 64-byte header, a BIF file table and a key table each located by their own header offset, and a region of BIF filenames that is not a located block at all: every file entry carries its own offset and length into it, so the strings are addressed one at a time.

§Resolving a resource

The resource_id on a key entry is two numbers packed into one word, and unpacking it is the whole job of this format:

  • bits 31..20 index the BIF file table
  • bits 19..0 index the resource within that BIF

So a lookup is: match the resref and type in the key table, split the resource_id, pick the BIF with the high bits and the entry inside it with the low bits. That split is also where the format’s ceilings come from, 4,096 BIFs and about a million resources in each.

Byte-level field maps for the header, the file entry and the key entry live in docs/src/formats/archives/key.md, with the engine’s own load sequence.

Structs§

Key
In-memory KEY container.
KeyBifEntry
One BIF file-table entry in a KEY index.
KeyReadOptions
KEY reader option set.
KeyResourceEntry
One resource entry in the KEY key table.

Enums§

KeyBinaryError
Errors produced while parsing or serializing KEY binary data.
KeyReadMode
KEY reader input policy.

Functions§

pack_resource_id
Packs (bif_index, resource_index) into KEY resource_id format.
read_key
Reads a KEY index from a reader.
read_key_from_bytes
Reads a KEY index from bytes.
read_key_from_bytes_with_options
Reads a KEY index from bytes with explicit options.
read_key_with_options
Reads a KEY index from a reader with explicit options.
write_key
Writes a KEY index to a writer.
write_key_to_vec
Serializes a KEY index to bytes.