Packet Encoding & Compression
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
Unit (JSON) → CBOR → Deflate → Blake3 → Envelope- 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)