Frame format
[ message_id : 1 byte, only when the schema set has more than one message ]
[ sequence : 1 byte, wrapping mod 256 ]
[ ticks : 2 bytes, little-endian, wrapping mod 65,536 ]
[ presence : ceil(2 * n_pred / 8) bytes ]
[ payload : bit-packed, padded with zero bits to a byte boundary ]
[ crc16 : 2 bytes, little-endian, over every preceding byte ]
n_pred is the number of fields with a predictor, counted in schema order.
Fields without a predictor have no presence bits and are always in the payload.
Presence codes
Each predictor field has a two-bit code at bits 2k and 2k+1, counting
least-significant bit first across the presence bytes:
| Code | Name | Meaning |
|---|---|---|
| 0 | Predicted | Field omitted; receiver uses its predictor. |
| 1 | Included | True value is present in the payload. |
| 2 | Refresh | True value is present; receiver checks it against its prediction. |
| 3 | Reset | True value is present; receiver resets predictor state, then updates it. |
Unused high bits are zero. For a one-message set with sequence 5, wire ticks
0x0102, and three predictor fields with codes [Reset, Included, Predicted],
the bytes before the payload are 05 02 01 07: the presence byte is
3 | (1 << 2) | (0 << 4) = 0x07.
Payload order
All fields appear in schema order. A field is present if it has no predictor or
its presence code is not Predicted. Variable-length fields carry their own
16-bit length, so the payload length depends on the values. plan computes the
exact frame length from the proposed presence codes; commit writes into the
caller’s buffer.
CRC and message ID
The CRC is CRC-16/IBM-SDLC (X.25): polynomial 0x1021, reflected input and
output, initial value 0xFFFF, final XOR 0xFFFF. The check value for the
ASCII bytes 123456789 is 0x906E.
The message ID is computed from FNV-1a 32-bit over the UTF-8 qualified name:
h = fnv1a32(name)
id = (h ^ (h >> 8) ^ (h >> 16) ^ (h >> 24)) & 0xFF
Minimum frame
The shortest valid frame is header (1 or 2) + 2 ticks + presence + 2 CRC
bytes. Frames shorter than that are rejected as TooShort. Unknown message IDs,
bad CRCs and malformed payloads are rejected before any predictor state changes.