The eXternal Data Representation (XDR) primitives are subroutines that define the basic and constructed data types. The XDR language provides programmers with a specification for uniform representations that includes filter primitives for basic and constructed data types. The basic data types include integers, enumerations, Booleans, hyperintegers, floating points, and void data. The constructed data types include strings, structures, byte arrays, arrays, opaque data, unions, and pointers.
The XDR standard translates both basic and constructed data types. For basic data types, XDR provides basic filter primitives that serialize information from the local host's representation to the XDR representation and deserialize information from the XDR representation to the local host's representation. For constructed data types, XDR provides constructed filter primitives that allow the use of basic data types, such as integers and floating-point numbers, to create more complex constructs such as arrays and discriminated unions.
Remote Procedure Calls (RPCs) use XDR to establish uniform representations for data types to transfer the call message data between machines. Although the XDR constructs resemble the C programming language, C language constructs define the code for programs. XDR, however, standardizes the representation of data types directly in the programming code.
The XDR primitives are subroutines that define the basic and constructed data types. The basic data type filter primitives include the following:
The XDR library provides basic filter primitives that translate between types of numbers and their external representations. The XDR number filters cover signed and unsigned integers, as well as signed and unsigned short and long integers.
The subroutines for the XDR number filters are:
|xdr_int||Translates between C language integers and their external representations.|
|xdr_u_int||Translates between C language unsigned integers and their external representations.|
|xdr_long||Translates between C language long integers and their external representations.|
|xdr_u_long||Translates between C language unsigned long integers and their external representations.|
|xdr_short||Translates between C language short integers and their external representations.|
|xdr_u_short||Translates between C language unsigned short integers and their external representations.|
The XDR library provides primitives that translate between floating-point data and their external representations. Floating-point data encodes an integer with an exponent. Floats and double-precision numbers compose floating-point data.
Note: Numbers are represented as IEEE standard floating points. Subroutines may fail when decoding IEEE representations into machine-specific representations, or vice versa.
The subroutines for the XDR floating-point filters are:
|xdr_double||Translates between C language double-precision numbers and their external representations.|
|xdr_float||Translates between C language floats and their external representations.|
The XDR library provides a primitive for generic enumerations based on the assumption that a C enumeration value (enum) has the same representation. There is a special enumeration in XDR known as the Boolean.
The subroutines for the XDR library enumeration filters are:
|xdr_bool||Translates between Booleans and their external representations.|
|xdr_enum||Translates between C language enumerations and their external representations.|
Sometimes an XDR subroutine must be supplied to the RPC system, but no data is required or passed. The XDR library provides the following primitive for this function:
|xdr_void||Supplies an XDR subroutine to the RPC system without transmitting data.|
The XDR filter primitives are subroutines that define the basic and constructed data types. Constructed data type filters allow complex data types to be created from basic data types. Constructed data types require more parameters to perform more complicated functions than do basic data types. Memory management is an example of a more complicated function that can be performed with the constructed primitives. Memory is allocated when deserializing data with the xdr_decode subroutine. Memory is deallocated through the xdr_free subroutine.
The constructed data-type filter primitives include the following:
A string is a constructed filter primitive that consists of a sequence of bytes terminated by a null byte. The null byte does not figure into the length of the string. Externally, strings are represented by a sequence of ASCII characters. Internally, XDR uses the char * designation to represent pointers to strings.
The XDR library includes primitives for the following string routines:
|xdr_string||Translates between C language strings and their external representations.|
|xdr_wrapstring||Calls the xdr_string subroutine.|
Arrays are constructed filter primitives and can be either generic arrays or byte arrays. The XDR library provides filter primitives for handling both types of arrays.
Generic arrays consist of arbitrary elements. Generic arrays are handled in much the same way as byte arrays, which handle a subset of generic arrays where the size of the arbitrary elements is 1, and their external descriptions are predetermined. The primitive for generic arrays requires an additional parameter to define the size of the element in the array and to call an XDR subroutine to encode or decode each element in the array.
The XDR library includes the following subroutines for generic arrays:
|xdr_array||Translates between variable-length arrays and their corresponding external representations.|
|xdr_vector||Translates between fixed-length arrays and their corresponding external representations.|
The XDR library provides a primitive for byte arrays. Although similar to strings, byte arrays differ by having a byte count. That is, the length of the array is set by an unsigned integer. They also differ in that byte arrays are not terminated with a null character. External and internal representations of byte arrays are the same.
The XDR library includes the following subroutine for byte arrays:
|xdr_bytes||Translates between counted byte string arrays and their external representations.|
Opaque data is composed of bytes of a fixed size that are not interpreted as they pass through the data streams. Opaque data bytes, such as handles, are passed between server and client without being inspected by the client. The client uses the data as it is and then returns it to the server. By definition, the actual data contained in the opaque object is not portable between computers.
The XDR library includes the following subroutine for opaque data:
|xdr_opaque||Translates between opaque data and its external representation.|
The XDR library provides a primitive for pointers so that structures referenced within other structures can be easily serialized, deserialized, and freed. The XDR library includes the following subroutine for pointers to structures:
|xdr_reference||Provides pointer chasing within structures.|
A discriminated union is a C language union, which is an object that holds several data types. One arm of the union is an enumeration value, or discriminant, that holds a specific object to be processed over the system first. The discriminant is an enumeration value (enum_t).
The XDR library includes the following subroutine for discriminated unions:
|xdr_union||Translates between discriminated unions and their external representations.|