Encode opaque bytes and counted ASCII strings
03Fixed opaque data has no count prefix. Variable opaque data and strings have a four-byte byte count, then payload and residual zero padding.
The selected decoder checks the bound before treating the announced length as a buffer request. No allocation or data acceptance follows this failed gate.
Source for this drawing: RFC 4506 · Read RFC section 4.9 ↗
New to this? Start hereA quick picture + helpful background
First, agree how to read the message.
An encoding tells a reader how to interpret bytes. A format tells it how values fit together. Correctly reading a value does not make that value trustworthy.
Helpful first, if these ideas are unfamiliar
These pictures are analogies to help you learn. The linked RFC explains the actual rules.
Terms in this drawing
Related RFCs and changes
“Updates” changes part of an earlier RFC. “Obsoletes” replaces it. This list shows selected related documents.
Count payload bytes, exclude padding, and respect the declared maximum.
- Opaque means uninterpreted bytes. Fixed opaque data declared opaque sample[5] carries exactly five bytes plus three residual zero bytes; it has no count prefix. The type description supplies its size (§4.9).
- Variable opaque data declared opaque sample<8> begins with an unsigned 32-bit byte count n. Five payload bytes therefore use count 00 00 00 05, five bytes and three zero bytes: twelve bytes total. The maximum8 is a declaration bound, not another transmitted number (§4.10).
- An XDR string is a counted sequence of ASCII bytes. The string "cat" has count 3, bytes63 61 74, then one zero pad byte. XDR does not append a C-style terminator as part of the string. A zero pad byte is outside the count; an embedded NUL can instead be a counted string byte and creates native-API hazards (§§4.11,8). No automatic UTF-8 extension is assumed.
- An omitted bound <> means a maximum of 2^32−1, not unlimited memory or a safe allocation size. Encoding a count beyond the declared maximum is an error. Decoders still need to ensure incoming sizes fit provisioned buffers even when the description has a large or omitted bound (§§4.10–4.11,8).
- The fourth state illustrates count 9 against an explicit bound 8 and stops a chosen decoder before allocation. This is a local safety gate, not a new wire exchange. Empty counted data has count 0 and no payload/padding. Residual bytes in the representation are zero; the helper additionally chooses strict rejection of nonzero padding, not an invented universal decoder MUST.
Illustrative values and bounded offline encoding/decoding models. Not a complete XDR compiler, RPC/NFS implementation, transport, memory allocator or security verifier.
Read the RFC section ↗