gtpc2mc6C/C++ Language Support User's Guide

TO2_atRBAWithBuffer-Retrieve Data from a BLOB

This function can be called to read either a complete binary large object (BLOB), or only part of a BLOB by specifying the starting byte position.

The data that is read is placed in the buffer specified by the caller. The number of bytes read will be the length specified, the maximum buffer length of 32 KB (8 × 4096), or the size of the BLOB, whichever is smaller.

Note:
This function does not support all collections. See Table 47 for collections that are supported for this function.

Format

#include <c$to2.h>
void * TO2_atRBAWithBuffer (const TO2_PID_PTR pid_ptr,
                                  TO2_ENV_PTR env_ptr,
                            const long        *relativeByteToRead,
                                  long        *bufferLength,
                                  long        *updateSeqCtr,
                                  void        *buffer);

pid_ptr
The pointer to the persistent identifier (PID) assigned to the collection.

env_ptr
The pointer to the environment as returned by the TO2_createEnv function.

relativeByteToRead
The pointer to a value that specifies the relative byte position in the collection to start the read.

bufferLength
The pointer to a value that specifies the length of the specified buffer. This field will be overlaid with the actual number of bytes read. If the returned length is less than the size of the buffer, the length field is updated with the actual length returned. The minimum buffer length is 20 bytes and the maximum is 32 768.

updateSeqCtr
The pointer to a field where the actual sequence counter value will be stored.

buffer
The pointer to a buffer where the read data is returned.

Normal Return

The normal return is a pointer to the buffer (array of character) supplied by the caller. This buffer now contains the requested data.

Error Return

An error return is indicated by a zero. When zero is returned, use the TO2_getErrorCode function to determine the specific error code. For more information, see Error Handling.

The following error codes are common for this function:

TO2_ERROR_BUFFER_SIZE

TO2_ERROR_DATA_LGH

TO2_ERROR_EMPTY

TO2_ERROR_ENV

TO2_ERROR_EODAD

TO2_ERROR_INDEX

TO2_ERROR_METHOD

TO2_ERROR_NOT_INIT

TO2_ERROR_PID

TO2_ERROR_SEQCTR

TO2_ERROR_ZERO_PID

Note:
The sequence counter field will be updated with the current sequence counter value from the BLOB whenever error codes TO2_ERROR_EODAD and TO2_ERROR_EMPTY are set in the environment.

Programming Considerations

Examples

The following example copies data into a specified buffer from a given BLOB starting at a specified relative byte position for a specified length.

#include <c$to2.h>              /* Needed for TO2 API functions     */
#include <stdio.h>              /* APIs for standard I/O functions  */
 
TO2_PID             blob;
TO2_ENV_PTR         env_ptr;    /* Pointer to the TO2 environment   */
long                position=5; /* We will try to get starting at 5 */
long                seq_ctr;    /* will hold update sequence count  */
char                buff[40];
                                /* use  buffer                      */
char                * buff_ptr;
long                  buffL;    /* length of user buffer            */

  ·
  ·
  ·
/********************************************************************/ /* Copy data from the BLOB starting at the 5th position for up */ /* to 40 bytes, that is the size of the user buffer. */ /********************************************************************/ buffL = sizeof(buff); buff_ptr = TO2_atRBAWithBuffer(&blob, env_ptr, &position, &buffL, &seq_ctr, buff); if (buff_ptr == NULL) { printf("TO2_atRBAWithBuffer failed!\n"); process_error(env_ptr); } else { printf("TO2_atRBAWithBuffer successful!\n"); }

Related Information