Implementing an XDR Data Stream

Programmers can create and implement XDR data streams.

The following example shows the abstract data types (XDR handle) required. The example contains operations being applied to the stream, an operation vector for the implementation, and two private fields for use by the implementation.


enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 };
typedef struct {
       enum xdr_op x_op;
       struct xdr_ops {
           bool_t  (*x_getlong)  ();
           boot_t  (*x_putlong)  ();
           boot_t  (*x_getbytes) ();
           boot_t  (*x_putbytes) ();
           u_int   (*x_getpostn) ();
           boot_t  (*x_setpostn) ();
           caddr_t (*x_inline)   ();
           VOID    (*x_destroy)  ();
       } *XOp;
       caddr_t x_public;
       caddr_t x_private;
       caddr_t x_base;
       int     x_handy;
} XDR;

The following parameters are pointers to XDR stream manipulation subroutines:

Item Description
x_destroy Frees private data structures.
x_getbytes Gets bytes from the data stream.
x_getlong Gets long integer values from the data stream.
x_getpostn Returns stream offset.
x_inline Points to internal data buffer, which can be used for any purpose.
x_putbytes Puts bytes into the data stream.
x_putlong Puts long integer values into the data stream.
x_setpostn Repositions offset.
XOp Specifies the current operation being performed on the stream. This field is important to the XDR primitives. However, the stream's implementation does not depend on the value of this parameter.

The following fields are specific to a stream's implementation:

Item Description
x_base Contains position information in the data stream that is private to the user implementation.
x_handy Contains extra information, as necessary.
x_public Specifies user data that is private to the stream's implementation and is not used by the XDR primitive.
x_private Points to the private data.