Technical detail · CoAP Wire Format and Option Encoding
CoAP reply options and payload boundaries
An illustrative Constrained Application Protocol (CoAP) thermostat reply shows where option parsing ends and application content begins.
Payload is the application content after the message fields. A payload marker is 0xFF at an option boundary, introducing a nonempty payload. Inside a declared Token or option value, the same byte is data. Its meaning depends on our current position.
I’ll mark every boundary in the thermostat’s reply before reading its temperature; Token Length (TKL) counts Token bytes, and an acknowledgement (ACK) confirms a message.
The reply is 64 45 37 21 71 42 33 9A C0 FF 32 32 2E 35. Its first byte gives Version 1, Type 2 (ACK), TKL 4. Code 45 means 2.05 Content. It echoes Message ID 0x3721 to acknowledge the request message and Token 71 42 33 9A to correlate the answer with that request.
At offset 8, C0 gives Content-Format 0: delta 12 from zero and a zero-length integer value representing zero. This identifies text/plain. Marker FF follows at offset 9; offsets 10–13 carry the text 22.5.
Without the marker, remaining bytes must parse as options or be rejected if malformed. The parser cannot guess that 32 begins a reading. A marker without following payload is malformed too. Mark the header, Token, options, marker and payload before interpreting application behavior.