Ammad
Ammad

Reputation: 4225

Protocol buffer Java parsing issue

I have .Proto file as shown below

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?

Upvotes: 0

Views: 88

Answers (1)

Peter Lawrey
Peter Lawrey

Reputation: 533472

Each field need to have a unique id to distinguish it.

Your pkts and fc_stats both have an id of 1

I suggest making one of them 2.

Note: it can decode 1 as pkts but it doesn't know what to decode 2 as.

Upvotes: 1

Related Questions