moqtap-codec
Zero-dependency MoQT wire codec — draft-conforming parser and writer for every MoQT draft from draft-07 through draft-17.
This crate handles pure encoding and decoding of MoQT protocol messages with no I/O, no async runtime, and no network dependencies. It is the foundational building block that every other moqtap crate depends on.
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)
- QUIC variable-length integer (VarInt) encoding per RFC 9000
- 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
Module layout
Each draft lives in its own module with an independent implementation; no
wire-level code is shared across drafts. Shared primitives (varint, kvp,
types, version, error) sit at the crate root.
moqtap_codec::
varint, kvp, types, version, error (shared)
dispatch (runtime Any* enums)
draft07, draft08, ..., draft17 (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.1"
# draft-14 only
= { = "0.1", = false, = ["draft14"] }
# draft-07 plus draft-14 for runtime dispatch
= { = "0.1", = 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 live in benches/codec.rs and exercise
varint, KVP, control-message, data-stream header, and synthetic subgroup decode
paths. The conformance test vectors under test-vectors/transport/draft17/
provide realistic message bytes; a synthetic generator covers larger
subgroup streams for throughput curves.
# full run (requires draft17 feature — enabled by default)
# quick smoke run
# only one group
# save a baseline, change code, then compare
# … make changes …
HTML reports are written to target/criterion/report/index.html.
License
MIT