Payload format
How events travel, from your payload bytes to frames, packets and WebSocket messages, and the content types receivers decode by.
There are two layers, and they are independent:
- Your payload: the bytes of your event, in whatever format you choose. JSON is the usual choice. Folkways never parses it.
- The protocol: FlatBuffers frames that carry your payload with its topic, name, type and headers. Clients use it whether the payload is JSON or binary. The JavaScript SDK handles it for you.
You don't need FlatBuffers to send JSON. And labelling a payload as FlatBuffers doesn't make Folkways read it.
Messages, packets and frames
| Layer | What it is | Limit |
|---|---|---|
| Message | One WebSocket binary message, or one HTTP request body | One packet |
| Packet | One FlatBuffers buffer. Client packets have the file identifier RTEC, server packets RTES | 64 KiB |
| Frame | { corr, body }: one request or reply. corr is your request ID, echoed on replies | 1 to 64 per packet |
| Event | Inside Deliver and Snapshot frames: one published item, with its payload | Payload 60 KiB |
HTTP responses carry a sequence of server packets, each prefixed by its length as a little-endian u32:
[u32 length][packet][u32 length][packet]….
The frame reference lists every frame and field.
Content types
Each event carries a content type: a 16-bit label telling receivers how to decode the payload. It is a hint, not validation.
| Name | Value | Use |
|---|---|---|
Unspecified | 0 | No declared format |
Bytes | 1 | Opaque bytes, such as encrypted envelopes |
Json | 2 | Objects and values; the default for most apps |
Text | 3 | UTF-8 text |
FlatBuffers | 4 | Generated binary structures; see FlatBuffers |
Protobuf | 5 | Schema-defined binary messages |
MsgPack | 6 | Compact objects |
Cbor | 7 | Compact objects, common in IoT |
| your own | 1024–65535 | Your own encoding; agree on meanings across your apps |
Values 8 to 1023 are reserved for future standard formats.
Which to choose. JSON is simplest for web apps. FlatBuffers lets readers access fields without unpacking the whole object. Protobuf has mature schemas and bindings everywhere. MessagePack and CBOR are compact object encodings. Measure with your own data before switching for size or speed. Don't base64-encode binary payloads into JSON: it adds about a third to their size.
Headers
Up to 16 string pairs per event, passed to every subscriber unchanged. Use them for metadata such as a schema version or a trace ID, never for secrets: anyone who can read the topic can read them.
The schema
The protocol's FlatBuffers schema is
protocol.fbs in the
JavaScript SDK's repository. Generate bindings for your language with flatc 24.3.25 (--ts, --python, --go,
--java, --kotlin, --swift and others).
The schema evolves without breaking old clients:
| Rule | Effect |
|---|---|
| Fields are only added at the end of a table | Old clients ignore fields they don't know |
| Tags and enum values are never reused | A retired number stays empty |
| Unknown frame types are refused, never guessed | A safe failure instead of a misread |
| Zero is always the cautious default | An unset field behaves the way an old client expects |
| A breaking change would be a new version with new identifiers | It would run beside v1 |
In this section
- FlatBuffers: an application schema, encoding, decoding and cross-language checks.
- Protobuf, MessagePack and CBOR.
- Schemas: validation and evolution.
- Size and compression.