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.
#include <hmq.h> MQEINT32 MQeFieldsDump( MQEHSESS hSess, MQEHFIELDS hFlds, MQEINT32 srcOff, MQEBYTE pBuf[], MQEINT32 BufLen, MQEVOID *pBase, MQEINT32 * pCompCode, MQEINT32 * pReason)
/** 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. */