Select one union arm or optional value
05A discriminant comes first and selects one arm. Optional data encodes presence, not a native pointer address.
Presence is encoded as a boolean word followed by the element if present. No native pointer address is transmitted.
Source for this drawing: RFC 4506 · Read RFC section 4.15 ↗
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.
Encode the discriminant and only its selected arm; void contributes zero bytes.
- A discriminated union starts with an int, unsigned int, enum or boolean discriminant, then encodes just the selected arm. A default arm is optional. Without one, an unspecified discriminant has no valid union encoding; each case must itself be a legal value of the discriminant’s type (§§4.15,6.4).
- Chosen example: union reply switch (bool ok) { case TRUE: unsigned int value; case FALSE: void; };. TRUE with value 7 encodes two words:1and7. FALSE encodes only the four-byte zero discriminant, because void contributes zero bytes (§§4.4,4.15–4.16).
- The unknown-case state is a SEPARATE int-switch example with cases 0 and 1 and no default. Discriminant3 has no selected arm, so the drawing stops. An int-switch with default:void could encode 3 with no arm bytes; that default would not make an invalid boolean or unassigned enum value legal (§§4.3–4.4,4.15,6.4).
- Optional data type-name *name is shorthand for a boolean union: FALSE followed by void or TRUE followed by the encoded element. It is also equivalent to a counted array of at most one element. The star does not serialize a process address, ownership pointer or memory-layout offset (§4.19).
- For optional string cat, present TRUE adds word 1 before the eight-byte counted string: twelve bytes. Absent FALSE is only word 0: four bytes. Recursive structures built this way require safe processing limits; no default maximum recursion depth is specified by XDR (§§4.19,8).
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 ↗