How a schema is applied
A schema is a positional array of type constructors. Entryn encodes argument n.
A schema is a positional list.
schema[1] encodes the first argument, schema[2]
the second, and so on. The number of arguments you pass to Fire has to match the
number of entries in the schema. Passing more arguments than the schema describes
will error when Flux reaches a nil entry, and passing fewer writes a shorter
packet than the receiver expects to read.What you save
- Without a schema
- With a schema
The dynamic encoder already narrows integers to the smallest width that fits, so a
schema’s saving on small integers is mostly the tag byte per value. The bigger wins
are elsewhere: forcing a
Float32 where the encoder would have written an 8-byte
f64, and T.Enum(), which sends a one-byte index instead of the full
"Enum.KeyCode.Space" string.When a schema is worth it
High-frequency unreliable streams
High-frequency unreliable streams
Replicating positions every frame is where per-packet bytes actually add up, and it
is also where
UnreliableRemoteEvent’s size limit bites. A schema with
T.Float32() components is the single most effective change you can make.Floats you do not need at full precision
Floats you do not need at full precision
The dynamic encoder writes every non-integer as an
f64. T.Float32() halves that,
and for world positions or normalised values the precision loss is irrelevant.Enums
Enums
Dynamically encoded
EnumItems are sent as their full string name. T.Enum() sends
a single byte. If you send enums at any volume, schematise them.Not worth it for low-traffic events
Not worth it for low-traffic events
A purchase confirmation fired twice a minute does not need a schema. The dynamic
encoder is convenient, tolerates changing argument shapes, and costs you nothing
measurable at that rate.
Composites
Schema entries nest, so you can describe structured payloads without falling back to the dynamic encoder.Optional
Prefixes the value with a single boolean byte. This is the only correct way to send a value that may benil under a schema.
Array
Writes a varint length followed by each element.Struct
Encodes a dictionary with named fields in a declared order. Entries are{ name, type } pairs.
Only the declared fields are transmitted. Extra keys on the table are ignored, and a
missing key is written as
nil, which will error for a non-optional field type. Field
order is part of the wire format, so both sides have to declare the fields in the same
sequence.Nesting
Composites compose freely:Escaping a schema
T.Any() uses the dynamic encoder for that one entry. Use it when a single argument’s
shape genuinely varies but the rest of the payload is fixed.
Bounded strings and arrays
T.String(maxLen) and T.Array(t, maxLen) assert against the limit.
Next steps
Schema constructors
Every entry in the
Flux.Types namespace.Serialization
How the dynamic encoder decides what to write.
