Visual RFC.
ALL RFCs / RFC 4506
Read the RFC ↗
RFC 4506 / External data representation

Select one union arm or optional value

05

A discriminant comes first and selects one arm. Optional data encodes presence, not a native pointer address.

RFC 4506 · § 4.15EXAMPLE
4 / 4
Select one union arm or optional valueOptional string presence encodes TRUE plus counted cat for12bytes or FALSE alone for4bytes, never a native pointer address.A discriminant selects exactly one armOptional string examplePresent: bool1, count3, cat, pad12bytes totalAbsent: bool0, no element bytes4bytes totalThe star is presence, not a process addressChoose one arm · optional data uses a boolean discriminant
04
Represent optional presence

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 ↗

Protocol participantThreat or exceptionProtocol controlSimplified drawings · precise section references
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.

Related RFCs and changes

“Updates” changes part of an earlier RFC. “Obsoletes” replaces it. This list shows selected related documents.

KEY POINT

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).
DETAILS

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 ↗

All chapters in RFC 4506

Drawing view

Scroll the drawing to see every part. Playback controls stay above it.

RFC 9700 / CHAPTERS

Chapters

For full details, tables, algorithms, and exceptions, read the original RFC.

RFC status and corrections ↗