cniElementAsBitstream

Gets the bitstream representation of the specified element. The parser associated with the element serializes the element and all its children. The result is copied to memory allocated by the caller. You can call this function only on the message body, that is, the last child of the message root. In the special case where all options specified match those of the original bitstream, for example, a bitstream read from a WebSphere MQ queue by the MQInput node, and the message has not been modified since receiving the original bitstream, this original bitstream is copied into the memory allocated by the user. In this case, the parser is not required to parse and re-serialize the message.

Syntax

CciSize cniElementAsBitstream(
  int*                       returnCode,
  CciElement*                element,
  const struct CciByteArray* value,
  CciChar*                   messageType,
  CciChar*                   messageSet,
  CciChar*                   messageFormat,
  int                        encoding,
  int                        ccsid,
  int                        options);

Parameters

returnCode
The return code from the function (output). Specifying a NULL pointer signifies that the node does not want to deal with errors. If input is not NULL, the output signifies the success status of the call. Any exceptions thrown during the execution of this call are re-thrown to the next upstream node in the flow. Call cciGetLastExceptionData for details of the exception.
element
The syntax element to be serialized (input.) Must be last child of the message root.
value
A pointer to a CciByteArray struct containing a pointer to a region of memory allocated by the caller, and the size in CciBytes of this memory (output).
messageType
The message type definition used to create the bitstream from the element tree (input). A NULL pointer means that this parameter is ignored. Also, if the parser associated with the element has no interest in this value, for example, if it is a generic XML parser, the parameter is ignored.
messageSet
The message set definition used to create the bitstream from the element tree (input). A NULL pointer means that this parameter is ignored. Also, if the parser associated with the element has no interest in this value, for example, if it is a generic XML parser, the parameter is also ignored.
messageFormat
The format used to create the bitstream from the element tree (input). A NULL pointer means that this parameter is ignored. Also, if the parser associated with the element has no interest in this value, for example, if it is a generic XML parser, the parameter is ignored.
encoding
The encoding to use when writing the bitstream (input). This parameter is mandatory. You can specify a value of 0 to indicate that the queue manager's encoding should be used.
ccsid
The coded character set identifier to use when writing the bitstream (input). This parameter is mandatory. You can specify a value of 0 to indicate that the queue manager's ccsid should be used. A ccsid of -1 indicates that the bitstream is to be generated using ccsid information contained in the subtree consisting of the field pointed to by element and its children. Currently no parsers support this option.
options
This is a place holder and should always be 0.

Return values

  • If successful, the correct size of memory needed to hold the bitstream is returned.
  • If the memory allocated by the caller was insufficient, returnCode is set to CCI_BUFFER_TOO_SMALL.
  • If an exception occurs during execution, returnCode is set to CCI_EXCEPTION.

Example

In this example, the node queries the properties folder to determine the messageSet, messageType, messageFormat, encoding, and bitstream. It then uses this information to get the bitstream representation of the message body.

  inRootElement=cniRootElement(&rc, message);
  checkRC(rc);

  inBodyRoot = cniLastChild(&rc, inRootElement);
  checkRC(rc);

  inMQMD = cniSearchFirstChild(&rc,
                               inRootElement,
                               CCI_COMPARE_MODE_NAME,
                               0,
                               CciString("MQMD",BIP_DEF_COMP_CCSID));
  checkRC(rc);
  

  inPropertiesFolder =cniSearchFirstChild(&rc,
                               inRootElement,
                               CCI_COMPARE_MODE_NAME,
                               0,
                               CciString("Properties",BIP_DEF_COMP_CCSID));
  checkRC(rc);

  encodingElement  = cniSearchFirstChild(&rc,
                               inPropertiesFolder,
                               CCI_COMPARE_MODE_NAME,
                               0,
                               CciString("Encoding",BIP_DEF_COMP_CCSID));
  checkRC(rc);

  ccsidElement  = cniSearchFirstChild(&rc,
                               inPropertiesFolder,
                               CCI_COMPARE_MODE_NAME,
                               0,
                               CciString("CodedCharSetId",BIP_DEF_COMP_CCSID));
  checkRC(rc);

  messageSetElement = cniSearchFirstChild(&rc,
                               inPropertiesFolder,
                               CCI_COMPARE_MODE_NAME,
                               0,
                               CciString("MessageSet",BIP_DEF_COMP_CCSID));
  checkRC(rc);

  messageTypeElement = cniSearchFirstChild(&rc,
                               inPropertiesFolder,
                               CCI_COMPARE_MODE_NAME,
                               0,
                               CciString("MessageType",BIP_DEF_COMP_CCSID));
  checkRC(rc);

  messageFormatElement = cniSearchFirstChild(&rc,
                               inPropertiesFolder,
                               CCI_COMPARE_MODE_NAME,
                               0,
                               CciString("MessageFormat",BIP_DEF_COMP_CCSID));
  checkRC(rc);

  
  encoding = cniElementIntegerValue(&rc, encodingElement);
  checkRC(rc);

  ccsid    = cniElementIntegerValue(&rc, ccsidElement);
  checkRC(rc);

  messageSetLength=512;
  messageSet       = (CciChar*)malloc(messageSetLength * sizeof(CciChar));
  messageSetLength = cniElementCharacterValue(&rc,
                                        messageSetElement,
                                        messageSet,
                                        messageSetLength);
  checkRC(rc);

  messageTypeLength=512;
  messageType       = (CciChar*)malloc(messageTypeLength * sizeof(CciChar));
  messageTypeLength = cniElementCharacterValue(&rc,
                                        messageTypeElement,
                                        messageType,
                                        messageTypeLength);
   checkRC(rc);

  messageFormatLength=512;
  messageFormat       = (CciChar*)malloc(messageFormatLength * sizeof(CciChar));
  messageFormatLength = cniElementCharacterValue(&rc,
                                        messageFormatElement,
                                        messageFormat,
                                        messageFormatLength);
  checkRC(rc);

  bitstream.size=512;
  bitstream.pointer=(CciByte*)malloc(sizeof(CciByte) * 512);
  
  bufLength = cniElementAsBitstream(&rc,
                        inBodyRoot,
                        &bitstream,
                        messageType,
                        messageSet,
                        messageFormat,
                        encoding,
                        ccsid,
                        0);
  
  checkRC(rc);
  bitstream.size=bufLength;

  convertMessage(&bitstream.pointer, &bitstream.size);