Skip to content

Latest commit

 

History

History
113 lines (88 loc) · 5.68 KB

SUPERPACK_SPEC.md

File metadata and controls

113 lines (88 loc) · 5.68 KB

DCF SuperPack — 32-byte container for two DeModFrame quanta

Status: certified across every language with a wire codec — Python (the reference, python/MCP/superpack.py), C, Rust, Go, C++, Perl, Node.js, Java, Kotlin, Swift, Haskell, Lua, and Lisp — each diffed byte-for-byte against the shared golden vectors (Documentation/superpack_vectors.json) in CI (wire-certify.yml). SuperPack is an opt-in option: ordinary single frames remain the default; reach for SuperPack when you are already sending frames in pairs.

Motivation

The 17-byte DeModFrame (see WIRE_QUANTUM_SPEC.md) is the one wire invariant. When frames are emitted in pairs — a descriptor plus its first data fragment, or two fragments of one message — the second header is largely recoverable from context. SuperPack removes that redundancy without ever changing the quantum: the two frames it carries are reconstructed bit-exact on unpack.

Two raw frames cost 2 × 17 = 34 bytes. SuperPack is 32 — a 2-byte (5.9%) saving per pair — and replaces the two independent inner CRCs with a single CRC covering both quanta jointly (strictly stronger integrity).

Lower latency than two single frames

The byte saving is the small win. The real one is one datagram instead of two: a SuperPack ships a frame pair as a single transport packet, so the pair crosses the network with one IP/UDP header (≈ 28 bytes saved on top of the 2 DCF bytes), one send/recv syscall, and one unit of per-packet routing/NIC work — not two. For paired traffic this is strictly lower per-pair overhead and latency than emitting the two frames separately. The trade-off is that SuperPack batches a pair, so it is an option for already-paired sends, not a replacement for the single-frame default (a lone frame should never wait for a partner just to be packed).

Where the bytes go

Per frame, three of the 17 bytes are recoverable, so a pair has 6 redundant bytes:

Redundant in a pair Bytes Why recoverable
inner sync ×2 2 always the constant 0xD3
inner CRC-16 ×2 4 each is a pure function of its frame's other 15 bytes

SuperPack drops all 6 and spends 4 back: a single outer sync, a 1-byte type/version tag, and one joint CRC-16. Net 6 − 4 = 2 bytes saved.

Layout (32 bytes, big-endian)

 [0]      sync   = 0xD3
 [1]      sflags = version[7:4]=1 | type[3:0]=SUPER (0x5)   => 0x15
 [2..15]  frame A core  = A's bytes [1..14]  (flags, seq, src, dst, payload[4], ts24)
 [16..29] frame B core  = B's bytes [1..14]
 [30..31] CRC-16/CCITT-FALSE over bytes [0..29]

A core is a full frame minus its sync byte ([0]) and its CRC ([15..16]).

Operations

pack(A, B): validate each input is a 17-byte frame with good sync, version nibble = 1, and a correct inner CRC (never pack a corrupt frame); concatenate 0xD3 | sflags | core(A) | core(B); append CRC-16 over [0..29].

unpack(S): require len == 32, S[0] == 0xD3, version nibble = 1, type == SUPER, and CRC over [0..29] matches. For each core, rebuild the frame as 0xD3 | core | CRC16(0xD3 | core); both reconstructed frames must decode() cleanly. Returns (A, B), each a valid DeModFrame.

is_superpack(buf): len == 32 and buf[0] == 0xD3 and buf[1] == 0x15.

Invariants

  • Lossless: unpack(pack(A, B)) == (A, B) for any two valid frames.
  • Quantum-preserving: each output frame independently satisfies sync + version + CRC, so the existing 246-vector wire certificate is unaffected — SuperPack is a container adapter, not a codec change.
  • Smaller: len(SuperPack) = 32 < 34 = 2 × 17.
  • Tamper-evident: any single-bit change to the 32 bytes fails the joint CRC.

Anchors

  • Inner-frame anchors are unchanged: CRC("123456789") = 0x29B1, CRC(0^15) = 0x4EC3.
  • SuperPack of two all-zero-core frames (encode(0,0,0,0,b"\x00\x00\x00\x00",0)) has joint CRC = 0x5B75 (pinned in superpack._selftest).

Certification

The contract is Documentation/superpack_vectors.json (7 frame-pair → container cases + the joint-CRC anchor), generated by python3 python/MCP/gen_superpack_vectors.py (which also emits the dependency-free codec/superpack_vectors.gen.h) and copied identically to python/MCP/. Every implementation packs/unpacks those cases byte-for-byte; CI (wire-certify.yml) regenerates the vectors, diffs them against the committed copies, and runs each language's SuperPack cert:

Lang pack/unpack Cert
Python python/MCP/superpack.py superpack.py selftest + gen_superpack_vectors.py
Rust codec/src/superpack.rs codec/tests/certify_superpack.rs
C codec/demod_superpack.h C_SDK/tests/test_superpack_certify.c
Go go/dcf/superpack.go go/dcf/superpack_certify_test.go
C++ cpp/include/dcf/superpack.hpp cpp/tests/certify_superpack.cpp
Perl perl/lib/DCF/SuperPack.pm perl/t/superpack.t
Node.js JS/nodejs/src/superpack.js JS/nodejs/test/certify_superpack.js
Java java/com/demod/dcf/SuperPack.java java/com/demod/dcf/SuperPackCertify.java
Kotlin kotlin/.../dcf/SuperPack.kt folded into dcf/Certify.kt
Swift swift/Sources/DCFWire/SuperPack.swift swift/Tests/.../SuperPackCertifyTests.swift
Haskell haskell/src/DCF/Transport/SuperPack.hs folded into haskell/test/Certify.hs
Lua lua/dcf_superpack.lua self-certs on load (embedded vectors)
Lisp lisp/src/wire.lisp (pack-super/unpack-super) self-certs on load (embedded vectors)

pytest matrix-bridge/tests/test_bridge_wire.py additionally pins size, losslessness, the golden joint CRC, tamper detection, and rejection of corrupt inputs for the Python reference.