Protocols
Saved & recent

Message framing

Also called: message boundaries, length-prefix framing

Message framing tells a receiver where one message ends and the next begins. Common approaches include a length prefix, a delimiter with escaping rules, or a fixed message size. Framing matters when the underlying service delivers a stream of bytes without preserving the application’s write boundaries.

For DNS over TCP, a two-byte length precedes each DNS message and excludes those two bytes from the length. A receiver may need several reads to collect one message, or may receive pieces of several messages together. Correct framing reconstructs messages independently of how network reads happen to split the bytes.

Read first
Protocol
Related
Serialization, TCP, DNS
Further reading
IETF RFC 1035 — Domain Names — Implementation and Specification
TCP byte stream 2-byte length fields 12 message A 8 message B 12 message bytes 8 message bytes reads from the stream read 1 read 2 read 3 length parser message A message B reconstructed messages
Schematic DNS-over-TCP framing: length fields count message bytes only. Network reads need not align with message boundaries.

View in the full Protocols collection