I am using C++. I have a function which gets the message as an
argument and uses reflection to add the repeated submessages> And how
can I get the number of times a repeated field is repeated in the
message?

On Oct 14, 4:51 pm, Kenton Varda <[email protected]> wrote:
> What language are you using?
> In C++:
>
> Object obj;
> for (int i = 0; i < array1_size; i++) {
>   obj.add_pair()->set_key(array1[i]);
>
> }
>
> if (obj.pair_size() == array2_size) {
>   for (int i = 0; i < array2_size; i++) {
>     obj.mutable_pair(i)->set_value(array2[i]);
>   }
>
> } else {
>   // error
> }
>
> On Wed, Oct 14, 2009 at 11:33 AM, Tejprakash Gill <[email protected]>wrote:
>
>
>
> > I generated a message with declaration below
>
> > message pairs {
> >   optional string key = 1;
> >   optional string val = 2;
> > }
>
> > message Object {
> > repeated pairs Pair = 1;
> > }
>
> > I have two arrays. array1 = [key1, key2, key3]
> > and array2 = [value1, value2, value3, value4]
>
> > I can parse through only one array at a time. how can i dynamically
> > add messages so that in the first pass, I add the appropriate amount
> > of repeated messages to the 'Object' message and set their 'key'
> > values from array1 and then while parsing the second array, I check if
> > the appropriate number of repeated messages have been added values
> > have been already set and if so, just add the 'value' object from
> > array 2.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to