Compose arrays and structures in declaration order
04Array counts refer to elements. Each element is already an XDR value; structure fields follow their declaration order.
The fixed array has two elements with different encoded sizes. The geometric spans are8:12 bytes and each string retains its own count/padding.
Source for this drawing: RFC 4506 · Read RFC section 4.12 ↗
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.
Do not confuse an array element count with a byte length or native structure padding.
- A fixed-length array encodes its elements in natural order without adding an array count. Each element’s encoding occupies a multiple of four bytes. unsigned int values[3] holding7,8,9 therefore occupies twelve bytes (§4.12).
- A variable-length array begins with a four-byte unsigned ELEMENT count. unsigned int values<4> holding the same three values carries count 3, then7,8,9: sixteen bytes total. The count is 3, not twelve payload bytes, and it cannot exceed the declared element bound (§4.13).
- A structure encodes components in declaration order. For the illustrative struct record { unsigned int id; string label<8>; }, id 7 precedes the encoded string cat. The twelve encoded bytes contain no field-name strings and no extra padding copied from a C compiler’s native layout (§4.14).
- An array’s elements have the same declared type but may have different encoded lengths. A fixed two-element string array containing cat and picnic uses8 bytes for the first counted string and 12 for the second: twenty total, with no array count. Each string has its own byte count and residual padding (§§4.11–4.12).
- The bounded helpers compose already encoded values; they are not a full type checker or an XDR schema compiler. Type aliases and symbolic constants affect descriptions but do not themselves insert bytes. The next chapters distinguish selected union arms, void and optional data (§§4.16–4.19).
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 ↗