Packet Encoding & Compression
stratt advanced 8 min read
ELI5
After you know what goes into a packet (STRATT-001), you need to know how to squish it down for transmission. Encoding is the process of turning the structured data into a compact byte stream. Compression makes it even smaller.
Technical Deep Dive
Encoding Pipeline
flowchart LR A["Unit\n(JSON)"] -->|"~50% smaller"| B["CBOR\nbinary"] B -->|"30–70% smaller"| C["Deflate\ncompressed"] C -->|"integrity hash"| D["Blake3\nfingerprint"] D -->|"wrap"| E["STRATT\nEnvelope"]Each stage has a distinct responsibility — serialisation, compression, integrity, and framing — so they can be swapped independently. The Blake3 step hashes the compressed payload rather than the original JSON; this locks the fingerprint to the exact bytes on the wire, making tampering detectable even if the decompressed content looks intact.
- CBOR (Concise Binary Object Representation): ~50% smaller than JSON
- Deflate (zlib): Additional 30-70% compression for text-heavy payloads
- Blake3: Integrity verification of the compressed payload
Compression Strategy
| Payload Size | Strategy |
|---|---|
| < 256 bytes | No compression (overhead exceeds savings) |
| 256B – 4KB | CBOR only |
| 4KB – 64KB | CBOR + Deflate |
| > 64KB | CBOR + Deflate + streaming |
Error Handling
Encoding failures surface as STRATT_ENCODE_ERROR with subcodes:
E1001: Schema validation failureE1002: Compression buffer overflowE1003: Fingerprint mismatch (tampering detected)
Key Terms
- CBOR: Binary JSON alternative. Smaller, faster, type-preserving.
- Deflate: LZ77 + Huffman coding compression.
- Streaming: Processing large payloads in chunks without loading entirely into memory.
Q&A
Q: Why not just use Protocol Buffers? A: CBOR is self-describing and doesn’t require a schema at decode time. STRATT values flexibility over absolute minimal size.
Examples
Before encoding:
{ "src": "council-1", "dst": "council-2", "body": "Hello world" }After CBOR + Deflate:
0x1f 0x8b 0x08 0x00 ... (14 bytes)neighbors on the map
- GRACE Session Structure & Context Lifecycle starting a new GRACE session