Reputation: 192
I'm trying to create an array that is going to transfer data from C++ application to a Java app. Because of the two languages, how do you format the a Google Protocol message?
Also, what are their limitations and advantages?
So far, I have the following:
message Config {
repeated string types = 1;
}
I think I'm missing somethings!
Upvotes: 1
Views: 38
Reputation: 1062590
If you mean on the wire - then firstly: it is the serializer's job to worry about that, but in this case it is implemented simply as (per repeated element):
0x0a = "field 1, length prefixed" (strings are always length prefixed)
{number of bytes as UTF8, varint-encoded}
{that many bytes of UTF8}
So if you have 3 items repeated you'll have 3 lots of 0x0a, varint, payload slammed one after the other. In the case of some primitive types - integers etc, there is a "packed" encoding that removes the need for a header per element, by prepending the byte-length of the entire array first, then just the array contents as raw non-tokenized data.
If you mean from the caller's perspective, then: it is down to the implementation, but essentially you should expect some familiar API - common to that framework. This might mean that repeated
data is exposed as an array / vector, or it might mean a "collection" class with an Add
etc API. It will depend entirely on what is sensible for the target framework and the implementing author's whimsy.
Upvotes: 1