WebSphere Message Brokers
File: as08150_
Writer: Lorraine Waitt

Reference topic

This build: July 31, 2007 21:37:56

cpiParseBuffer

Purpose

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. Each user-defined parser that is used to parse a particular message format has this function invoked to:

The offset parameter indicates the offset within the message buffer where parsing is to commence. This is necessary because another parser might own a previous portion of the message (for example, an MQMD header will have been parsed by the message broker's internal parser). The offset must be positive and be less than the size of the buffer. It is recommended that the implementation function verifies that the offset is valid, as this could improve problem determination if a previous parser is in error.

The parser must return the size of the remaining buffer for which it takes ownership. This 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 can cause unpredictable results.

If this implementation function is provided in the CPI_VFT structure, neither cpiParseBufferEncoded() nor cpiParseBufferFormatted() can be specified, because the cpiDefineParserClass() function will fail 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 (lines 428 to 466):

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);
  }
Related concepts
User-defined input nodes
User-defined extensions overview
Related tasks
Creating a parser in C
Related reference
cpiParseBufferEncoded
cpiParseBufferFormatted
C parser implementation functions
Notices | Trademarks | Downloads | Library | Support | Feedback

Copyright IBM Corporation 1999, 2007Copyright IBM Corporation 1999, 2007. All Rights Reserved.
This build: July 31, 2007 21:37:56

as08150_ This topic's URL is: