Hub / stratt / stratt-002

Packet Encoding & Compression

advanced ⏱ 8 min ● medium stratt protocol-mechanics

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
  1. CBOR (Concise Binary Object Representation): ~50% smaller than JSON
  2. Deflate (zlib): Additional 30-70% compression for text-heavy payloads
  3. Blake3: Integrity verification of the compressed payload

Compression Strategy

Payload SizeStrategy
< 256 bytesNo compression (overhead exceeds savings)
256B – 4KBCBOR only
4KB – 64KBCBOR + Deflate
> 64KBCBOR + Deflate + streaming

Error Handling

Encoding failures surface as STRATT_ENCODE_ERROR with subcodes:

  • E1001: Schema validation failure
  • E1002: Compression buffer overflow
  • E1003: 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)