← Back to the chapter · Next detail →
Technical detail · CoAP Lab: Message Construction
Header bit fields and byte-builder limits
The datagram header’s bit layout explains how a small byte builder can preview the fields without constructing a complete request.
The first header byte combines version, message type and token length (TKL), the number of token bytes following the header. A token is the byte string used to match a response to its request. The message types are confirmable CON(0), non-confirmable NON(1), acknowledgement ACK(2) and Reset RST(3). A non-confirmable message, NON, does not request an acknowledgement. ACK acknowledges a confirmable message; RST rejects a message the recipient cannot process. The base-format token length is 0–8 bytes; RFC 8974 describes optional extended tokens.
The Code byte holds a method or a response code. Its upper three bits hold the class and its lower five hold the detail. The next two bytes hold the 16-bit Message ID (MID), used for acknowledgement and duplicate detection. A header-only byte builder previews these four header bytes; it does not generate token, options or payload. Some control combinations do not describe valid complete exchanges, so a plausible preview is limited evidence.