1

protobuf.js 版本:^6.2.1

缓冲

083515604859581840220a0d6048595815bdf426422a0a0d7047595815bdf426

代码:

protobuf.load("PulseFlagData.proto", function(err, root) {
                            if (err) {
                                callback(err);
                            }
                            var pulse = root.lookup("PulseFlagData");

                            callback(null, pulse.decode(parsed_data.payload)); 
 });   

.proto 文件:

syntax = "proto3";

message PulseFlagSample {
    required fixed32 timestamp = 1;
    required uint32 input = 2;
    required bool flag = 3;
}

message PulseFlagData {
    required uint32 config_version = 1;
    required fixed32 device_time = 2;
    required PulseFlagSample current = 3;
    optional PulseFlagSample last_hour = 4;
}

错误:

/home/deck/NetBeansProjects/lora/node_modules/protobufjs/src/reader.js:390 throw indexOutOfRange(this, length); ^

RangeError: index out of range: 23 + 10 > 32 at RangeError (native) at indexOutOfRange (/home/deck/NetBeansProjects/lora/node_modules/protobufjs/src/reader.js:13:12) at BufferReader.skip (/home /deck/NetBeansProjects/lora/node_modules/protobufjs/src/reader.js:390:19) 在 BufferReader.ReaderPrototype.skipType (/home/deck/NetBeansProjects/lora/node_modules/protobufjs/src/reader.js:410:18 ) 在 Type._PulseFlagSample$decode [as decode] (eval at eof (/home/deck/NetBeansProjects/lora/node_modules/protobufjs/node_modules/@protobufjs/codegen/index.js:102:25), :19:7)在 Type.decode_setup [as decode] (/home/deck/NetBeansProjects/lora/node_modules/protobufjs/src/type.js:370:7) at Type._PulseFlagData$decode [as decode] (eval at eof (/home/甲板/NetBeansProjects/lora/node_modules/protobufjs/node_modules/@protobufjs/codegen/index.js:102:25), :16:27) 在 Type.decode_setup [as decode] (/home/deck/NetBeansProjects/lora/node_modules/protobufjs/src/type.js:370:7) at /home/deck/NetBeansProjects/ lora/server.js:42:50 完成 (/home/deck/NetBeansProjects/lora/node_modules/protobufjs/src/root.js:84:9)

4

1 回答 1

2

您的输入不是有效的协议缓冲区。

  1. 它似乎在消息中间被切断了。最后一个顶级字段是一个 10 个字节的长度分隔字段,但消息仅在 9 个字节后结束。因此,至少缺少一个字节。如果应该出现其他字段,则可能会丢失更多字节。
  2. 即使消息没有提前中断,它似乎也与您解析的类型不匹配。该消息似乎具有以下字段:

    uint32 a = 1;
    fixed32 b = 2;
    int32 c = 3;
    SomeMessageType d = 4;
    SomeMessageType e = 5;
    

    这些字段声明与PulseFlagData您提供的类型不一致。

以下是按字段细分的原始数据:

08 35                       // 1: [u]int32, = 53
15 60485958                 // 2: fixed32,  = 1615354200
18 40                       // 3: [u]int32, = 64
22 0a 0d6048595815bdf42642  // 4: sub-message, length 10
  0d 60485958               //   1: fixed32, = 1615354200
  15 bdf42642               //   2: fixed32, = 3186894402
2a 0a 0d7047595815bdf426    // 5: sub-message, length 10, incomplete
  0d 70475958               //   1: fixed32, = 1883724120
  15 bdf426                 //   2: fixed32, incomplete
于 2016-12-21T05:42:36.157 回答