offset 参数表明开始解析的消息缓冲区内的偏移量。这是必需的,因为另一个解析器可能具有消息的前一部分(例如,MQMD 头已由消息代理的内部解析器解析)。偏移量必须是正数并且小于缓冲区 的大小。建议实施函数验证偏移是有效的,因为如果前一个解析器有错误,则这可能改进问题确定。
解析器必须返回它所占有的剩余缓冲区的大小。这必须小于或等于比当前偏移小的缓冲区的大小。
解析器不能尝试引起解析其他的语法元素树部分,例如,通过浏览到根元素并到另一个分支。这可能导致不可预测的结果。
如果 CPI_VFT 结构中提供了此实施函数,则既不能指定 cpiParseBufferEncoded() 也不能指定 cpiParseBufferFormatted(),这是因为 cpiDefineParserClass() 函数将失败,返回码为 CCI_INVALID_IMPL_FUNCTION。
在其中定义 | 类型 | 成员 |
CPI_VFT | 有条件的 | iFpParseBuffer |
int cpiParseBuffer( CciParser* parser, CciContext* context, int offset);
解析器取得所有权的消息缓冲区的剩余部分的大小(以字节为单位)。
此示例取自样本解析器文件 BipSampPluginParser.c(428 行到 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); }