On Tue, Jul 2, 2013 at 8:10 PM, <[email protected]> wrote:

> Hi,
>
> In the following protocol buffer, how does one access the repeated fields
> in the extension from C++?
>
Use ExtensionSize(id), GetExtension(id, index) etc. to access repeated
extensions.


>
>
> Glenn
>
> base.proto:
>
> message Base {
>     optional int32 id = 1;
>     repeated int32 ids = 2;
>     optional string name = 3;
>     repeated string names = 4;
>     extensions 1000 to 1999;
> }
>
> ext.proto:
>
> import "base.proto";
> extend Base {
>     repeated string names = 1000;
>     optional int32 number = 1001;
>     repeated int32 numbers = 1002;
>     optional string name = 1003;
> }
>
> Example:
>
> #include "base.pb.h"
> #include "ext.pb.h"
>
> using namespace ::google::protobuf;
>
> int main(int argc, char *argv[])
> {
> Base b;
> // populate b here.
>
> RepeatedPtrField<std::string> base_names = b.names(); // OK
> RepeatedField<int> base_ids = b.ids(); // OK
>
> int ext_number = b.GetExtension(number); // OK
> std::string ext_name = b.GetExtension(name); // OK
> assert( b.HasExtension(numbers) ); // OK
> assert( b.HasExtension(names) ); // OK
> int32 i = b.GetExtension(numbers); // ? Compiles but doesn't make sense.
>
> RepeatedField<int32> ext_numbers = b.GetExtension(numbers); // compilation
> fails:
> RepeatedPtrField<std::string> ext_names = b.MutableExtension(names); //
> compilation fails:
>
> return 0;
> }
>
>  --
> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
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