Skip to main content

Module binary

Module binary 

Source
Expand description

The binary form — what the build compiles content to, what the bus carries, and what the runtime and the Java hosts read, like NBT:

"YOGD" version:u8
root value

A value is a tag byte and its payload. A string is written where it’s first used and referred to after that: a varint v, then — when v is odd — v >> 1 bytes of UTF-8, the next entry of the string table; when it’s even, the table’s entry v >> 1. Repeated keys and ids cost one varint each, and the writer never goes back over what it wrote.

TagValuePayload
0null—
1, 2false, true—
3intzigzag varint
4floatf64, little-endian
5stringstring
6listvarint count, values
7mapvarint count, (key string, value) pairs
8refkind string, id string
9tagkind string, id string
10resourceset string, key string
11textstring
12imagestring
13coloru32, little-endian (0xAARRGGBB)
14translation keystring
15bytesvarint length, the bytes
16list of ints, packedvarint count, zigzag varints
17streamu32 byte length, then varint count and values with their own strings
18float, 32-bitf32, little-endian
19list of floats, packedvarint count, f64 each, little-endian
20list of 32-bit floats, packedvarint count, f32 each, little-endian

Nothing is aligned: numbers are read out of the bytes wherever they are, so no padding is ever written.

Varints are LEB128. Decoding checks every length against the input, so malformed bytes are an error, never a panic or a huge allocation.

A crate::Schema writes itself here straight (crate::Schema::encode) and reads itself back the same way (crate::Schema::decode) — no value tree on the way.

Modules§

tag
A value’s first byte: what it is.

Structs§

DecodeError
Malformed binary data.
Decoder
Reads the binary form. The step-by-step reads (Decoder::int, Decoder::map …) answer None for anything but what crate::Schema::encode writes there — the schema then reads the slow way, which says what’s wrong.
Writer
Writes the binary form piece by piece, from data that isn’t a Value — nothing is built or copied on the way. A map or list is given its length, then that many entries (key then a value) or values.

Constants§

MAGIC
MAX_DEPTH
Nested deeper than this is malformed.
VERSION

Functions§

decode
Reads the binary form.
decode_ref
Reads the binary form borrowed: every string points into bytes, lists and maps go in arena — nothing is copied.
encode
value in the binary form.