MQeFieldsDump

Description
Serializes the encoded fields in an MQeFields object into a byte array.

This functions supports partial dumps. Between partial dumps, the programmer should not add or delete any field in the MQeFields object. If fields are added or deleted, inconsistencies may occur between the data that has already been copied out and the data that is waiting to be copied. This causes errors when the user tries to restore the MQeFields object from the byte array.

Syntax
#include <hmq.h>
MQEINT32 MQeFieldsDump( MQEHSESS hSess,
									MQEHFIELDS hFlds, 
									MQEINT32 srcOff, 
            					MQEBYTE pBuf[], 
									MQEINT32 BufLen, 
									MQEVOID *pBase, 
           					MQEINT32 * pCompCode, 
									MQEINT32 * pReason) 

Parameters

MQEHSESS hSess - input
The session handle, returned by MQeInitialize.

MQEHFIELDS hFlds - input
Handle to an MQeFields object.

MQEINT32 srcOff - input
The offset into internal byte array representation of the MQeFields object at which the dump should start

MQEBYTE pBuf[] - output
The buffer to hold the dumped bytes

MQEINT32 BufLen - input
The number of bytes to dump

MQEVOID *pbase - input
The base pointer for the output buffer pBuf

MQEINT32 * pCompCode - output
MQECC_OK, MQECC_WARNING or MQECC_ERROR.

MQEINT32 * pReason - output
If the returned *pCompCode equals MQECC_ERROR, *pReason may have any of the following values:

MQE_EXCEPT_INVALID_HANDLE

MQE_EXCEPT_ALLOCATION_FAILED

Return Value

MQEINT32
  • On success, returns the number of bytes copied into the buffer.
  • On failure, returns '-1'.

Implementation
The byte order in which the primitive data types are dumped is big-endian.

Example
/**
   This example shows how to dump the 
		fields object into an array of fix-size buffers.
 */
#include <hmq.h>
static MQECHAR const * FieldsType = "com.ibm.mqe.MQeFields";
 
static   MQECHAR * textBuf  = 
						"The Owl and the Pussy Cat went to sea.";
static   MQEBYTE   byteBuf[] = 
						{ 0xAB, 0xCD, 0x12, 0x44};
 
#define  MAX_CHUNK_SIZE 16
MQEHSESS   hSess;
MQEHFIELDS hFlds;
MQEINT32   compcode;
MQEINT32   reason;
MQEINT32   int32Val;
MQEINT32   i, offset;
MQEINT32   chunk, nchunks;
MQEBYTE ** buf_array;
MQEINT32   nbytes;
MQEINT32   rc;
 
hSess   = MQeInitialize("MyAppsName", 
									&compcode, &reason);
hFlds   = MQeFieldsAlloc( hSess, FieldsType, 
									&compcode, &reason);
 
/* Put some fields into the fields object */
int32Val = 0x12345678;
rc = MQeFieldsPut( hSess, hFlds, "x", 
							MQE_TYPE_INT, 
							&int32Val, 1, 
							&compcode, 
							&reason); 
rc = MQeFieldsPut( hSess, hFlds, "nm", 
							MQE_TYPE_ASCII, 
							textBuf, 
							strlen(textBuf), 
							&compcode, 
							&reason); 
rc = MQeFieldsPut( hSess, hFlds, "b" , 
							MQE_TYPE_BYTE, 
							byteBuf, 4, 
							&compcode, 
							&reason); 
 
nbytes  = MQeFieldsDumpLength( hSess, hFlds, 
											&compcode, &reason);
 
offset  = 0;
i       = 0;
 
/*
 * Calc number of chunks needed 
		to hold the dump byte array
 */
nchunks = nbytes/MAX_CHUNK_SIZE;   
chunk = nbytes%MAX_CHUNK_SIZE;
 
/*
 * Allocate the buf array.
 */
 
while (nchunks != 0)
{
   buf_array[i] = (MQEBYTE*) malloc(MAX_CHUNK_SIZE);
   rc = MQeFieldsDump( hSess, hFlds, 
								offset, 
								&buf_array;[i][0], 
								MAX_CHUNK_SIZE, NULL,
								&compcode, 
								&reason);
   offset  += MAX_CHUNK_SIZE;
   nchunks--;
   i++;
}
 
buf_array[i] = (MQEBYTE*) malloc(chunk);
rc = MQeFieldsDump( hSess, hFlds, 
							offset, 
							&buf_array;[i][0], 
							chunk, 
							NULL, 
							&compcode, 
							&reason);
 
/* Do something with the buf_array[], like store it into a file. */

See Also



© IBM Corporation 2002. All Rights Reserved