External Data Representation
As was pointed out earlier, an RPC can be executed between two hosts that run completely different processor hardware. Data types, such as integer and floating-point numbers, can have different physical representations on different machines. For example, some machines store integers (C ints) with the low-order byte first, whereas some machines place the low-order byte last. Similar problems occur with floating-point numeric data. The solution to this problem involves the adoption of a standard for data interchange.
One such standard is the ONC external data representation (XDR). XDR is essentially a collection of C functions and macros that enable conversion from machine-specific data representations to the corresponding standard representations and vice versa. It contains primitives for simple data types such as int, float, and string, and provides the capability to define and transport more complex ones such as records, arrays of arbitrary element type, and pointer-bound structures such as linked lists.
Most of the XDR functions require the passing of a pointer to a structure of "XDR" type. One of the elements of this structure is an enumerated field called x_op. Its possible values are XDR_ENCODE, XDR_DECODE, and XDR_FREE. The XDR_ENCODE operation instructs the XDR routine to convert the passed data to XDR format. The XDR_DECODE operation indicates the conversion of XDR-represented data back to its local representation. XDR_FREE provides a means to de-allocate memory that was dynamically allocated for use by a variable that is no longer needed. For more information on XDR, see the information sources listed in the "References" section of this article.