Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you iterate through a mutable repeated Proto field in C++ using a range-based for loop?

How do you you iterate through a mutable repeated Protocol Buffer field using a range-based for loop in C++?

like image 230
michaelrbock Avatar asked Nov 16 '18 23:11

michaelrbock


People also ask

Are repeated fields ordered in Protobuf?

Yes, repeated fields retain the order of items.

What is repeated field in Protobuf?

repeated : this field can be repeated any number of times (including zero) in a well-formed message. The order of the repeated values will be preserved.

How does Protobuf serialize?

The Protobuf serialization mechanism is given through the protoc application, this compiler will parse the . proto file and will generate as output, source files according to the configured language by its arguments, in this case, C++. You can also obtain more information about, reading the section compiler invocation.

What is a repeated field?

RepeatedField and RepeatedPtrField are used by generated protocol message classes to manipulate repeated fields. These classes are very similar to STL's vector, but include a number of optimizations found to be useful specifically in the case of Protocol Buffers.


1 Answers

Use a reference:

for (MyProto &my_proto : *container->mutable_my_protos()) {…}
like image 161
michaelrbock Avatar answered Oct 17 '22 07:10

michaelrbock