这个protobuffer解码有什么问题?

我正在使用Google protobuffer解码一些缓冲区。 我正在使用优秀的@decodeIO ProtoBuf.js模块。

当我尝试解码这个缓冲区时:

<Buffer 0a 0b 47 57 5f 2d 31 38 5f 39 39 32 39> 

从这个消息:

 message PaymentResponseElement { optional int64 pnPaymentId = 1; optional string messageCode = 2; //won't use pb enum here optional int64 balanceAfterTransaction = 3; optional int32 version = 4; } 

我得到这个错误:

 Error: Illegal wire type for field Message.Field .core.comm.PaymentResponseElement.messageCode: 2 (0 expected) at ProtoBuf.Reflect.Field.decode (/home/joojo/node_modules/protobufjs/ProtoBuf.js:2095:27) at ProtoBuf.Reflect.Message.decode (/home/joojo/node_modules/protobufjs/ProtoBuf.js:1748:51) at ProtoBuf.Reflect.Field.decode (/home/joojo/node_modules/protobufjs/ProtoBuf.js:2196:46) at ProtoBuf.Reflect.Message.decode (/home/joojo/node_modules/protobufjs/ProtoBuf.js:1746:51) at Function.Message.decode (/home/joojo/node_modules/protobufjs/ProtoBuf.js:1630:41) at decode (/home/joojo/public_html/api/control/protoBuffer.js:94:52) at Object.module.exports.decode (/home/joojo/public_html/cageapi/control/protoBuffer.js:110:10) at decode (/home/joojo/public_html/api/control/messageStructurer.js:82:33) at Object.module.exports.decode (/home/joojo/public_html/api/control/messageStructurer.js:94:10 at CleartextStream.month (/home/joojo/public_html/api/connectionHandler.js:83:32) 

不知道发生了什么,发生了几次。 如何解决它?

我必须同意这个实施。 该数据只有1个字段 – 字段编号1,长度前缀(可以是string,二进制或子消息编辑或打包数组)。 如果我们猜测它是一个string(总是UTF-8),它会以"GW_-18_9929" ,看起来"GW_-18_9929"

但是,您的消息声明域1为int64 。 string/长度前缀导线types(导线types2)对于int64无效 – 实际上,唯一有效的导线types是64位(导线types1)。

所以:你的数据是有效的 ,但它不符合你声称的模式。

解读:

  • 0a是二进制1010 – 最后三位(010)是导线types,2 =长度界定; 剩下的1是字段编号:1
  • 0b是十进制的11,后面的字段的长度
  • 47 57 5f 2d 31 38 5f 39 39 32 39是"GW_-18_9929"的有效载荷,UTF-8,