Skip to content

Framing

All integers in frame prefixes use the QUIC variable-length integer encoding (RFC 9000 §16): the two most significant bits of the first byte give the length (1, 2, 4 or 8 bytes); values range up to 2^62−1. Encoders MUST use the shortest encoding. Decoders MUST accept any valid encoding in length fields but MUST reject values exceeding configured limits before allocating.

Frame {
Type (8 bits),
Flags (8 bits),
Length (varint), // length of Payload in bytes
Payload {
HeaderLength (varint), // length of Header in bytes; may be 0
Header (HeaderLength bytes, CBOR map),
Data (Length - size(HeaderLength) - HeaderLength bytes)
}
}
  • Type: see the registry (§5.6).
  • Flags: all bits reserved in v1. Senders MUST set them to 0. Receivers MUST ignore unknown flag bits. Bit 0 is the least significant bit (mask 0x01). Bit 0 is reserved for a future “data compressed” flag (§18, item 1, deferred).
  • Header: a CBOR map (§5.4.1). An empty header is encoded as HeaderLength = 0 (not as an empty map).
  • Data: opaque bytes interpreted per frame type and the session codec. May be empty.
  • max_frame (§7.1, §7.2) bounds the Length field, that is the payload bytes: the HeaderLength varint, the header and the data. The Type, Flags and Length prefix and, on WebSocket, the stream ID (§5.4) are not counted. A receiver checks Length against max_frame before buffering the payload.

Frames are written back-to-back on the stream. A receiver reads Type, Flags, Length, then Length bytes. A stream ending (FIN) in the middle of a frame is a PROTOCOL_ERROR.

WsFrame {
StreamId (varint),
Frame (as §5.2)
}

A WebSocket binary message is a sequence of one or more WsFrames. Leftover bytes that don’t form a complete WsFrame are a PROTOCOL_ERROR.

  • The header is a CBOR map with unsigned integer keys from the key registry (§5.7), except where a field is defined as a nested map with text keys.
  • Senders MUST use CBOR core deterministic encoding (RFC 8949 §4.2.1): definite lengths, shortest integer forms, sorted keys. This makes golden test vectors byte-exact.
  • Receivers MUST reject indefinite-length items in headers, MUST enforce a maximum header size (default 16 KiB) and nesting depth (default 16), and MUST ignore unknown keys.
  • Depth counts nested arrays and maps; the outermost item has depth 1; tags do not add depth. The same counting applies to data sections (§12.3), which also bound the tags along each path separately.
  • A header whose HeaderLength exceeds the remaining payload, that is not exactly one CBOR map, or that contains duplicate keys, indefinite-length items or tags, or that exceeds the size or depth limit, is a PROTOCOL_ERROR. Two keys of one map are duplicates when the rule of §12.3 makes them one key, so 1.0 written as a half and as a single float is one key in a header too.
  • Receivers SHOULD accept non-deterministic but otherwise valid encodings.

The codec is negotiated in the handshake (§7.1-7.2) and applies to every data section in the session.

Codec Requirement Data section
cbor MUST be supported by all implementations; default One CBOR data item
json SHOULD be supported; intended for debugging One JSON value, UTF-8 text

The mapping of contract types to each codec is defined in §12.3, including the encoding order that makes data sections byte-exact across implementations. The header section is always CBOR regardless of codec, so routers, backplanes and logs can parse envelopes without decoding payloads.

Types 0x00-0x7F are must-understand: an unknown type in this range is a PROTOCOL_ERROR. Types 0x80-0xFF are extensions: unknown ones MUST be ignored (the frame is skipped using Length). Type 0x80 is reserved for a future METHOD_BIND extension frame (§18, item 2).

Type Name Stream Direction Section
0x01 HELLO 0 C→S §7.1
0x02 WELCOME 0 S→C §7.2
0x03 REJECT 0 S→C §7.3
0x04 PING 0 both §7.4
0x05 PONG 0 both §7.4
0x06 GOAWAY 0 S→C §7.6
0x07 CLOSE 0 both §7.7
0x08 AUTH_REFRESH 0 C→S §7.5
0x09 AUTH_RESULT 0 S→C §7.5
0x0A ACK 0 both §7.8 (also piggybacked via key 44)
0x0B AUTH_EXPIRING 0 S→C §7.5
0x0C REQUEST_ERROR 0 S→C §7.9
0x10 CALL call both §8.2
0x11 ITEM call both §8.3
0x12 END call both §8.3
0x13 RESULT call callee→caller §8.4
0x14 ERROR call callee→caller §8.4
0x15 CANCEL call caller→callee §8.5
0x16 CREDIT call (WS only) both §6.4
0x20 NOTIFY 0 or lane both §9
0x21 LANE_OPEN lane both §9.2
0x30 SUBSCRIBE 0 C→S §10.2
0x31 SUBSCRIBED 0 S→C §10.2
0x32 UNSUBSCRIBE 0 C→S §10.3
0x33 UNSUBSCRIBED 0 S→C §10.3
0x34 PUBLICATION 0 S→C §10.4
0x35 PRESENCE 0 S→C §10.6
0x40 DATAGRAM 0 (WS) / datagram (WT) both §11
0x41 DGRAM_BIND 0 both §11.2

A frame received on the wrong kind of stream, or in the wrong direction, is a PROTOCOL_ERROR.

Key Name CBOR type Used in
1 rid uint Control requests/responses (§7.9)
2 method text CALL, NOTIFY
3 meta map text → (text / bytes) CALL, RESULT, ERROR, END, NOTIFY, SUBSCRIBE
4 deadline uint (ms, relative) CALL
5 shape uint (§8.1) CALL
6 code uint REJECT, ERROR, CLOSE, GOAWAY, REQUEST_ERROR, UNSUBSCRIBED, AUTH_RESULT
7 msg text same as code
8 lane uint LANE_OPEN
9 channel text channel frames
10 epoch text SUBSCRIBED, SUBSCRIBE since
11 offset uint SUBSCRIBED, PUBLICATION, SUBSCRIBE since
12 seq uint Sequenced frames (§7.8; per lane, per direction), DATAGRAM (per key)
13 token bytes or text auth, resume
14 versions array of uint HELLO
15 version uint WELCOME
16 codecs array of text HELLO
17 codec text WELCOME
18 caps array of text HELLO, WELCOME
19 session text WELCOME, resume map, presence entries
20 resume map {13: token, 19: session, 44: ack, 53: lost?} HELLO
21 limits map uint → uint: {48: max_calls, 49: max_frame, 50: max_subs, 51: max_dgram, 40: window} (§7.2) HELLO, WELCOME
22 hb uint (ms) WELCOME
23 idle uint (ms) WELCOME
24 contract bytes (32) HELLO, WELCOME
25 credit uint (bytes) CREDIT
26 recovered bool SUBSCRIBED
27 presence bool SUBSCRIBE
28 kind uint PRESENCE
29 key uint DGRAM_BIND, DATAGRAM (WS)
30 name text DGRAM_BIND, client map
31 retry uint (ms) REJECT, GOAWAY
32 url text GOAWAY
33 auth map {35: scheme, 13: token} HELLO, AUTH_REFRESH
34 client map {30: name, 52: version} HELLO (e.g. {30: "pavia-ts", 52: "0.3.0"})
35 scheme text inside auth (§7.1), e.g. "bearer"
36 user text WELCOME (optional echo of authenticated user ID)
37 resume_window uint (ms) WELCOME
38 expires uint (ms until expiry) AUTH_RESULT, AUTH_EXPIRING
39 (unassigned) Was last_stream; removed in draft 0.3
40 window uint (bytes) inside limits (§6.4)
41 since map {10: epoch, 11: offset} SUBSCRIBE
43 resumed bool WELCOME
44 ack map uint → uint (lane → highest contiguous seq received) ACK; MAY be piggybacked on any sequenced frame (§7.8)
45 nx bool ERROR: true means the callee guarantees the handler never ran (§8.4)
46 transports array of text ("websocket", "webtransport") WELCOME (§4.4)
48 max_calls uint inside limits
49 max_frame uint (bytes) inside limits
50 max_subs uint inside limits
51 max_dgram uint (bytes) inside limits
52 version (text) text inside client
53 lost array of uint (lane numbers) WELCOME, resume map (§7.8)

Keys 1-1023 are reserved for this specification. Keys ≥ 1024 are available for extensions and MUST be ignored if unknown. Keys 39 and 42 are unassigned; unassigned keys below 1024 MUST NOT be used by extensions.


From the specification: §5.1, §5.2, §5.3, §5.4, §5.5, §5.6, §5.7.