简体   繁体   English

协议缓冲区Java解析问题

[英]Protocol buffer Java parsing issue

I have .Proto file as shown below 我有.Proto文件,如下所示

message Port {
    repeated Info info = 1;
}

message Info {
    required string if_name = 1 ;
    optional Stats in_stats = 2;

}

message Stats {

    required uint64 pkts = 1 ;
    repeated Accounting fc_stats = 2;
}

message Accounting {
     optional string family = 1 ;
}

extend Sensors {
    optional Port InterfaceExt = 7;
}

I am parsing it and every thing is working as fine except the "Repeated" Accounting element inside stats is not parsing correct data. 我正在解析它,并且除统计数据中的“重复”记帐元素未解析正确的数据外,其他所有功能都正常运行。

Also the Array list Size is Zero for Accounting element, meaning it is not populating properly, however if i print the sensor object it is bringing data in raw format as shown below, 另外,记帐元素的数组列表大小为零,这意味着它没有正确填充,但是,如果我打印传感器对象,它将以原始格式带来数据,如下所示,

info {
        if_name: "xe"
        in_stats {
          pkts: 27
          2: "\n\004IPv4\020\003\030\343\355\277\240e \200\343\355\277\240e"
        }
    }

Any idea what's wrong with it? 知道有什么问题吗?

Each field need to have a unique id to distinguish it. 每个字段都需要有一个唯一的ID来区分它。

Your pkts and fc_stats both have an id of 1 您的pktsfc_stats的ID均为1

I suggest making one of them 2. 我建议做其中之一2。

Note: it can decode 1 as pkts but it doesn't know what to decode 2 as. 注意:它可以将1解码为pkts但是不知道将2解码为pkts

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM