This is the actual code without any typos.

org.proto

message Optimize {
    required int element_size = 1;
    required string element_name = 2;}

message nodes {
    repeated Optimize = 1;}

Have this decoding function:

DecodeNodeMsg(char *msg, int size){

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

    node.ParseFromArray((void *)msg, size);

    for (int i = 0; i < nodes.Optimize().size(); i++)
    {
        element_size = nodes.Optimize(i).element_size();
        element_name = nodes.Optimize(i).element_name();
        cout << "size" << element_size << endl;
        cout << "name" << element_name << endl;
        NumofElem++;
    }
    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.

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



On Tuesday, November 26, 2013 12:26:56 PM UTC-8, Kiran Kumar wrote:
>
> File org.proto
> ------------------
>
> message Optimize {
>     required int element_size;
>     required string element_name;
> }
>
> message nodes {
>     repeated Optimize;
> }
>
> *Have this decoding function:*
>
> DecodeNodeMsg()
> {
>
>     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;
>         NumofElem++;
>     }
>         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 ?
>
> Thanks,
> Kiran
>

-- 
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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to