moqtap-codec
MoQT wire codec — a parser and writer for every MoQT draft from draft-07 through draft-19.
Pure encoding and decoding: no I/O, no async runtime, no network dependencies.
It depends only on bytes and thiserror.
What it does
- Encodes and decodes every MoQT control message type per each supported draft (setup, subscribe, publish, fetch, namespace, track status, goaway)
- Encodes and decodes data stream headers (subgroup, datagram, fetch, object)
- Variable-length integers, in whichever encoding the draft uses: RFC 9000
Section 16 through draft-16, and MoQT's own (Section 1.4.1) from draft-17,
where the length is the number of leading 1 bits in the first byte.
DraftVersion::varint_encodingmaps drafts to encodings - Key-value parameter (KVP) pairs
- Core protocol types:
TrackNamespace,Location,FilterType,GroupOrder,ObjectStatus - Session and request error codes, per-draft
- Runtime draft dispatch via the
dispatchmodule (AnyControlMessage,AnySubgroupHeader,AnyFetchHeader,AnyDatagramHeader,AnyObjectHeader) — one enum variant per enabled draft feature, decode selects the draft at runtime from aDraftVersion - Draft-neutral object framing on the same seam (
AnySubgroupObjectReader,AnySubgroupObjectWriter,AnyFetchObjectReader,AnyFetchObjectWriterand the values they hand back), so a caller frames a data stream into individually addressable objects without naming adraftNNtype. Subgroup and fetch streams on every draft 07-19 - Structured parameter values, rather than opaque bytes: the AUTHORIZATION
TOKEN structure (
auth_token), the subscription filter (subscription_filter), and draft-19's Range Filter parameters (range_filter)
Module layout
Each draft lives in its own module with an independent implementation; no wire-level code is shared across drafts. Shared primitives sit at the crate root.
moqtap_codec::
varint, kvp, types, version, error (shared primitives)
auth_token, subscription_filter,
range_filter (structured parameter values)
dispatch, data_dispatch (runtime Any* enums and object framing)
draft07, draft08, ..., draft19 (per-draft wire format)
Draft selection
Each draft is behind a feature flag. Enable the ones you need. The default is
all-drafts.
# every draft (default)
= "0.4"
# draft-14 only
= { = "0.4", = false, = ["draft14"] }
# draft-07 plus draft-14 for runtime dispatch
= { = "0.4", = false, = ["draft07", "draft14"] }
Usage
Per-draft (compile-time)
use ;
use VarInt;
let msg = ClientSetup;
let mut buf = Vecnew;
msg.encode.unwrap;
let mut cursor = &buf;
let decoded = decode.unwrap;
assert_eq!;
Runtime dispatch across drafts
use AnyControlMessage;
use DraftVersion;
let mut cursor: & = &wire_bytes;
let msg = decode?;
match msg
Benchmarks
Criterion benches in benches/codec.rs cover varint, KVP,
control-message, data-stream header and subgroup decode paths. They need the
draft17 feature, which is on by default.
License
MIT