xdr_bytes()--Translate between Counted Byte Arrays and Their XDR


  Syntax
 #include <rpc/xdr.h>

 bool_t xdr_bytes(XDR *xdrs,
                  char **sp,
                  u_int *sizep,
                  const u_int maxsize);

  Service Program Name: QZNFTRPC

  Default Public Authority: *USE

  Threadsafe: No

The xdr_bytes() function is a filter primitive that translates between counted byte arrays and their external representations. This function treats a subset of generic arrays in which the size of array elements is known to be 1 and the external description of each element is built-in. The length of the byte sequence is explicitly located in an unsigned integer. The byte sequence is not ended by a null character. The external representation of the bytes is the same as their internal representation.


Parameters

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

sp  (I/O) 
The address of the pointer to the byte array. If *sp==NULL and the stream is being decoded, then XDR allocates the needed amount of memory.

sizep  (I/O) 
A pointer to the length of the byte area. The value of this parameter cannot exceed the value of the maxsize parameter.

maxsize  (Input) 
The maximum number of bytes allowed when XDR encodes or decodes messages.

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_bytes() 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;
        char *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_bytes(
                 xdrs,
                 (&(p_xarray->p_array)),
                 &(p_xarray->size),
                 MAX_INT);
}


API introduced: V4R2

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