Framing Strategies
Length-prefix framing (most common):
[4-byte length][payload bytes]
- Pro: O(1) to read: read 4 bytes → allocate buffer → read length bytes
- Con: Can't stream; must buffer entire payload before parsing
Delimiter framing (e.g., RESP, HTTP/1.1 headers):
..payload bytes..\r\n
- Pro: streaming-friendly; simple text protocols
- Con: delimiter must be escaped in payload; scanning required
Fixed-size frames (e.g., AMQP, ATM):
- Pro: no parsing; trivially parallel
- Con: wastes space for variable-length data