cpiParseBuffer

This function prepares a parser to parse a new message object. It is called the first time (for each message) that the message flow causes the message content to be parsed.

This function is called for each user-defined parser that is used to parse a particular message format to complete the following actions:
  • Perform all initialization that is required
  • Return the length of the message content that it takes ownership for

The offset parameter indicates the offset within the message buffer where parsing is to commence. This indication is required because another parser might own a previous portion of the message (for example, an MQMD header is parsed by an internal parser owned by the integration node). The offset must be positive and be less than the size of the buffer. Verify in this function that the offset is valid, to remove problems associated with previous parsers.

The parser must return the size of the remaining buffer for which it takes ownership. The size must be less than or equal to the size of the buffer, less the current offset.

A parser must not attempt to cause parsing of other portions of the syntax element tree, for example, by navigating to the root element and to another branch. This action can cause unpredictable results.

If this implementation function is provided in the CPI_VFT structure, you can call neither cpiParseBufferEncoded() nor cpiParseBufferFormatted(), because the cpiDefineParserClass() function fails with a return code of CCI_INVALID_IMPL_FUNCTION.

Defined In Type Member
CPI_VFT Conditional iFpParseBuffer

Syntax

int cpiParseBuffer(
  CciParser*   parser,
  CciContext*  context,
  int          offset);

Parameters

parser
The address of the parser object (input).
context
The address of the context owned by the parser object (input).
offset
The offset into the message buffer at which parsing is to commence (input).

Return values

The size (in bytes) of the remaining portion of the message buffer for which the parser takes ownership.

Sample

This example is taken from the sample parser file BipSampPluginParser.c:

int cpiParseBuffer(
  CciParser*  parser,
  CciContext* context,
  int         offset,
){
  PARSER_CONTEXT_ST* pc = (PARSER_CONTEXT_ST *)context ;
  int                rc;

  /* Get a pointer to the message buffer and set the offset */
  pc->iBuffer = (void *)cpiBufferPointer(&rc, parser);
  pc->iIndex = 0;

  /* Save size of the buffer */
  pc->iSize = cpiBufferSize(&rc, parser);

  /* Prime the first byte in the stream */
  pc->iCurrentCharacter = cpiBufferByte(&rc, parser, pc->iIndex);

  /* Set the current element to the root element */
  pc->iCurrentElement = cpiRootElement(&rc, parser);

  /* Reset flag to ensure parsing is reset correctly */
  pc->iInTag = 0;

  if (pc->trace) {
    fprintf(pc->tracefile, "PLUGIN: <- cpiParseBuffer() 
    retvalue=%d\n", pc->iSize);
    fflush(pc->tracefile);
  }