Consider the following message.
message example {
repeated string text;
}
Let's say that in C++ I have a list of string that I insert into the text field of example:
exemple aMessage;
std::list<std::string> aList = ... ;
for (std::string anStr : aList)
{
aMessage.add_text(anStr);
}
Later on if I access text of the my message, will that field be ordered in the same way as my list? What about when I serialize it and send it off somewhere?
Will the order stay constant?
Yes, repeated fields retain the order of items.
From Google's Protocol Buffers encoding specification:
The order of the elements with respect to each other is preserved when parsing, though the ordering with respect to other fields is lost.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With