File org.proto

message Optimize {
    required int element_size;
    required string element_name;

message nodes {
    repeated Optimize;

*Have this decoding function:*


    Org::nodes *node = new Org::nodes;
    int element_size;
    string element_name;
    int NumofElem = 0; 

    for (int i = 0; i < Org::nodes().Optimize().size(); i++)
        element_size = Org::nodes().Optimize(i).element_size();
        element_name = Org::nodes().Optimize(i).element_name();
        cout << "size" << element_size << endl;
        cout << "name" << element_name << endl;
        cout << "number of" << NumofElem << endl;
I am encoding a nodes message with three Optimize messages in it. and 
calling this decode function. Encoding part is an old code which is working 
fine from long time. So i dont suspect the encoding function. 

I see that the NumofElem is correctly printed as three. However, i see that 
both element_size & element_name is just garbage. Interger has some junk 
value and string has a binary data.

I am having this issue only if this repeated fields. If fields are 
required/optional fields, then i dont have this issue.

Could some one has similar issue... ? if so any clues on how to fix this ?


You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
To post to this group, send email to
Visit this group at
For more options, visit

Reply via email to