Delimiter and Length Framing

A byte stream needs record boundaries if it carries several messages. Delimiters and lengths supply different framing rules.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace a boundary problem
  2. State what corruption affects
  3. Compare two boundaries for the same text payload
  4. Decide how a damaged stream is handled

Trace a boundary problem

If an unescaped newline separates messages, a payload containing that byte will appear as two messages. An escaping rule can preserve it. A length-prefixed record instead tells the reader how many bytes to consume before the next record.

State what corruption affects

A bad declared length can make the reader take bytes belonging to the next header. Document how a reader reports incomplete or out-of-range records. See input validation by stages for separating format and domain failures.[1]

Compare two boundaries for the same text payload

A value with an embedded newline cannot be stored unchanged in a newline-delimited format unless that format quotes or escapes it. A length-prefixed format can preserve the bytes as-is, provided it counts bytes and the reader knows the length encoding. See separators and escaping.

Payload bytes: 41 0A 42
Raw newline splitting sees two pieces
Length-prefix value 3 keeps all three bytes together
An escaping format can encode the embedded break explicitly

Decide how a damaged stream is handled

A corrupted length can lead to a bad subsequent boundary. A delimiter may allow resynchronization where the format defines strict escaping and recovery. Neither representation alone replaces validation and application limits. Test data that contains exactly the delimiter symbol.

References

  1. IETF, RFC 3629: UTF-8, a Transformation Format of ISO 10646 ↩