xdr_array()--Translate between Arrays and Their XDR


  Syntax
 #include <rpc/xdr.h>

 bool_t xdr_array(XDR *xdrs,
                  caddr_t *arrp,
                  u_int *sizep,
                  const u_int maxsize,
                  const u_int elsize,
                  const xdrproc_t elproc);

  Service Program Name: QZNFTRPC

  Default Public Authority: *USE

  Threadsafe: No

The xdr_array() function is a filter primitive that translates between variable-length arrays and their corresponding external representations. This function is called to encode or decode each element of the array.


Parameters

xdrs  (Input) 
A pointer to the External Data Representation (XDR) stream handle.

arrp  (I/O) 
The address of the pointer to the array. If *arrp==NULL and the array is being deserialized, XDR allocates an array of the appropriate size and sets this parameter to point to that array.

sizep  (I/O) 
The address of the element count of the array. The element count cannot exceed the value for the maxsize parameter.

maxsize  (Input) 
The maximum number of array elements.

elsize  (Input) 
The byte size of each of the array elements.

elproc  (Input) 
Translates between the C form of the array elements and their external representations. This parameter is an XDR filter.

Authorities

No authorization is required.


Return Value

TRUE (1) Successful
FALSE (0) Unsuccessful


Error Conditions

None.


Error Messages

Message ID Error Message Text
CPE3418 E Possible APAR condition or hardware failure.
CPF3CF2 E Error(s) occurred during running of &1 API.
CPF9872 E Program or service program &1 in library &2 ended. Reason code &3.


Example

The following example shows how xdr_array() is used.

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.

#include <stdio.h>
#include <values.h>
#include <xdr.h>

#define ARRAY_SIZE 256

typedef struct xarray
{
        int size;
        int *p_array;
} xarray ;

bool_t xdr_xarray(XDR *xdrs, xarray *p_xarray )
{
     /*
      * Force XDR to allocate memory while decoding
      */
     if((xdrs->x_op==XDR_DECODE)&&
     (p_xarray->p_array!=NULL))
     {
        free(p_xarray->p_array);
        p_xarray->p_array=NULL;
     }
     /*
      *  This code has a  dual job :
      *  A) While decoding, it allocated memory, stores the decoded
      *          xarray in it, and updates size field in xarray
      *          struct.
      *  B) While decoding it stores xarray's size and the data
      *          itself in XDR.
      */
    return xdr_array(
                 xdrs,
                 (char**)(&(p_xarray->p_array)),
                 &(p_xarray->size),
                 MAX_INT,
                 sizeof(int),
                 (xdrproc_t)xdr_int))

}


API introduced: V4R2

[ Back to top | Remote Procedure Call (RPC) APIs | APIs by category ]