'\"macro stdmacro
.if n .pH g3n.xdr_complex @(#)xdr_complex	40.6 of 1/29/90
.\" Copyright 1989 AT&T
'\"macro stdmacro
.nr X
.if \nX=0 .ds x} xdr_complex 3N "" "\&"
.if \nX=1 .ds x} xdr_complex 3N ""
.if \nX=2 .ds x} xdr_complex 3N "" "\&"
.if \nX=3 .ds x} xdr_complex "" "" "\&"
.TH \*(x}
.SH NAME
.na
\f4xdr_complex\fP:  \f4 xdr_array\f1, \f4xdr_bytes\f1, \f4xdr_opaque\f1, \f4xdr_pointer\f1, \f4xdr_reference\f1, \f4xdr_string\f1, \f4xdr_union\f1, \f4xdr_vector\f1, \f4xdr_wrapstring\f1 \- library routines for external data representation
.ad
.SH DESCRIPTION
XDR library routines allow C programmers to describe
complex data structures in a machine-independent fashion.
Protocols such as remote procedure calls (RPC)
use these routines to describe the format of the data.
These routines are the XDR library routines for complex data
structures.
They require the creation of XDR stream [see \f4xdr_create\fP(3N)].
.SS Routines
See \f4rpc\fP(3N) for the definition of the
\f4XDR\f1
data structure.
.br
.ne 10
.P
.ft 4
.nf
#include <rpc/xdr.h>
.fi
.ft 1
.br
.ne 10
.P
.ft 4
.nf
.sp .5
bool_t
xdr_array(XDR *xdrs, caddr_t *arrp, u_int *sizep, 
	const u_int maxsize, const u_int elsize,
	const xdrproc_t elproc);
.fi
.ft 1
.IP
\f4xdr_array\f1
translates between variable-length
arrays
and their corresponding external representations.
The parameter
\f2arrp\f1
is the address of the pointer to the array,
while
\f2sizep\f1
is the address of the element count of the array;
this element count cannot exceed
\f2maxsize\f1.
The parameter
\f2elsize\f1
is the
\f4sizeof\f1
each of the array's elements,
and
\f2elproc\f1
is an XDR routine that translates between
the array elements' C form
and their external representation.
This routine returns \f41\f1 if it succeeds,
\f40\f1 otherwise.
.br
.if t .ne 10
.P
.ft 4
.nf
.sp .5
bool_t
xdr_bytes(XDR *xdrs, char **sp, u_int *sizep,
	const u_int maxsize);
.fi
.ft 1
.IP
\f4xdr_bytes\f1
translates between counted byte
strings and their external representations.
The parameter
\f2sp\f1
is the address of the string pointer.
The length of the
string is located at address
\f2sizep\f1;
strings cannot be longer than
\f2maxsize\f1.
This routine returns \f41\f1 if it succeeds,
\f40\f1 otherwise.
.br
.if t .ne 10
.P
.ft 4
.nf
.sp .5
bool_t
xdr_opaque(XDR *xdrs, caddr_t cp, const u_int cnt);
.fi
.ft 1
.IP
\f4xdr_opaque\f1
translates between fixed size opaque
data
and its external representation.
The parameter
\f2cp\f1
is the address of the opaque object,
and
\f2cnt\f1
is its size in bytes.
This routine returns \f41\f1 if it succeeds,
\f40\f1 otherwise.
.P
.ft 4
.nf
.sp .5
bool_t
xdr_pointer(XDR *xdrs, char **objpp, u_int objsize,
	const xdrproc_t xdrobj);
.fi
.ft 1
.IP
Like
\f4xdr_reference\f1
except that it serializes
\f4NULL\fP pointers,
whereas
\f4xdr_reference\f1
does not.
Thus,
\f4xdr_pointer\f1
can represent
recursive data structures,
such as binary trees or
linked lists.
.br
.if t .ne 11
.P
.ft 4
.nf
.sp .5
bool_t
xdr_reference(XDR *xdrs, caddr_t *pp, u_int size,
	const xdrproc_t proc);
.fi
.ft 1
.IP
\f4xdr_reference\f1
provides pointer chasing within structures.
The parameter
\f2pp\f1
is the address of the pointer;
\f2size\f1
is the
\f4sizeof\f1
the structure that
\f2*pp\f1
points to;
and
\f2proc\f1
is an
XDR
procedure that translates the structure
between its C form and its external representation.
This routine returns \f41\f1 if it succeeds,
\f40\f1 otherwise.
.IP
Warning:
this routine does not understand
\f4NULL\fP pointers.
Use
\f4xdr_pointer\f1
instead.
.br
.if t .ne 9
.P
.ft 4
.nf
.sp .5
bool_t
xdr_string(XDR *xdrs, char **sp, const u_int maxsize);
.fi
.ft 1
.IP
\f4xdr_string\f1
translates between C strings and
their
corresponding external representations.
Strings cannot be longer than
\f2maxsize\f1.
Note:
\f2sp\f1
is the address of the string's pointer.
This routine returns \f41\f1 if it succeeds,
\f40\f1 otherwise.
.br
.if t .ne 16
.P
.ft 4
.nf
.sp .5
bool_t
xdr_union(XDR *xdrs, enum_t *dscmp, char *unp,
	const struct xdr_discrim *choices,
	const bool_t (*defaultarm)(const XDR *, const char *,
		const int));
.fi
.ft 1
.IP
\f4xdr_union\f1
translates between a discriminated C
\f4union\f1
and its corresponding external representation.
It first
translates the discriminant of the union located at
\f2dscmp\f1.
This discriminant is always an
\f4enum_t\f1.
Next the union located at
\f2unp\f1
is translated.
The parameter
\f2choices\f1
is a pointer to an array of
\f4xdr_discrim\f1
structures.
Each structure contains an ordered pair of
[\f2value, proc\f1].
If the union's discriminant is equal to the associated
\f2value\f1,
then the
\f2proc\f1
is called to translate the union.
The end of the
\f4xdr_discrim\f1
structure array is denoted by a routine of value
\f4NULL\fP.
If the discriminant is not found in the
\f2choices\f1
array,
then the
\f2defaultarm\f1
procedure is called (if it is not
\f4NULL\fP).
Returns \f41\fP if it succeeds,
\f40\fP otherwise.
.br
.if t .ne 6
.P
.ft 4
.nf
.sp .5
bool_t
xdr_vector(XDR *xdrs, char *arrp, const u_int size,
	const u_int elsize, const xdrproc_t elproc);
.fi
.ft 1
.IP
\f4xdr_vector\f1
translates between fixed-length
arrays
and their corresponding external representations.
The
parameter
\f2arrp\f1
is the address of the pointer to the array,
while
\f2size\f1
is is the element count of the array.
The parameter
\f2elsize\f1
is the
\f4sizeof\f1
each of the array's elements,
and
\f2elproc\f1
is an
XDR
routine that translates between
the array elements' C form
and their external representation.
This routine returns \f41\f1 if it succeeds,
\f40\f1 otherwise.
.br
.if t .ne 10
.P
.ft 4
.nf
.sp .5
bool_t
xdr_wrapstring(XDR *xdrs, char **sp);
.fi
.ft 1
.IP
A routine that calls
\f4xdr_string(\f2xdrs\f4, \f2sp\f4, \f2maxuint\f4);\f1
where
\f2maxuint\f1
is the maximum value of an unsigned integer.
.IP
Many routines,
such as
\f4xdr_array\f1,
\f4xdr_pointer\f1
and
\f4xdr_vector\f1
take a function pointer of type
\f4xdrproc_t\f1,
which takes two arguments.
\f4xdr_string\f1,
one of the most frequently used routines,
requires three arguments,
while
\f4xdr_wrapstring\f1
only requires two.
For these routines,
\f4xdr_wrapstring\f1
is desirable.
This routine returns \f41\f1 if it succeeds,
\f40\f1 otherwise.
.SH SEE ALSO
.na
\f4rpc\fP(3N),
\f4xdr_admin\fP(3N),
\f4xdr_create\fP(3N),
\f4xdr_simple\fP(3N).
.ad
