此函数是现有 cpiWriteBuffer() 实施函数所提供的功能的扩展,它提供了译码和编码字符集,当解析器按顺序将其元素树解析为输出位流时,应使用此字符集来表示输出消息。如果不需要进行序列化(例如,当输出基于输入位流并且树未经更改时),则代理不会调用此实施函数。如果 CPI_VFT 结构中提供了此实施函数,则既不能指定 cpiWriteBuffer() 也不能指定 cpiWriteBufferFormatted(),这是因为 cpiDefineParserClass() 函数将失败,返回码为 CCI_INVALID_IMPL_FUNCTION。
在其中定义 | 类型 | 成员 |
CPI_VFT | 有条件的 | iFpWriteBufferEncoded |
int cpiWriteBufferEncoded( CciParser* parser, CciContext* context, int encoding, int ccsid);
追加在缓冲区中位流后面的数据大小(以字节为单位)。
此示例取自样本解析器文件 BipSampPluginParser.c(612 行到 642 行):
int cpiWriteBufferEncoded( CciParser* parser, CciContext* context, int encoding, int ccsid ){ PARSER_CONTEXT_ST* pc = (PARSER_CONTEXT_ST *)context ; int initialSize = 0; int rc = 0; const void* a; CciByte b; initialSize = cpiBufferSize(&rc, parser); a = cpiBufferPointer(&rc, parser); b = cpiBufferByte(&rc, parser, 0); cpiAppendToBuffer(&rc, parser, (char *)"Some test data", 14); return cpiBufferSize(0, parser) - initialSize; }