CRUMB a card from devarno-cloud

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.

  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)

neighbors on the map