Reputation: 11
I want to receive a list (array) of message using protobuf. The idea would be to receive something like:
[
{
"field1": "value1",
"field2": "value2"
},
{
"field1": "value1",
"field2": "value2"
}
]
However, when defining protobuf messages I can get ride of the top name in this array. For example:
message MyFields {
string field1 = 1;
string field2 = 2;
}
message MyMessage {
repeated MyFields some_identifier = 1;
}
Which would create something like:
{
"some_identifier":
[
{
"field1": "value1",
"field2": "value2"
},
{
"field1": "value1",
"field2": "value2"
}
]
}
Not even sure if this is possible with protobuf.
Thanks!
Upvotes: 1
Views: 116
Reputation: 39370
did you try with a repeated
Map? Like:
message MyFields {
map<string, string> MyMap = 1;
}
message MyMessage {
repeated MyFields some_identifier = 1;
}
Upvotes: 0
Reputation: 40061
It is not possible.
Protobuf requires that messages comprise fields and fields have a name, a type (and a field number).
In your example, the repeated message field would have no name and this isn't permitted.
Upvotes: 1