I'm looking to create a gRPC response that returns a list of maps. Here is what I imagined the structure being:
message GetSettingsResponse {
repeated map<string, string> settings = 1;
}
Repeating maps is not supported, however, and I had to nest the map in a separate message to make it work:
message GetSettingsResponse {
repeated Setting settings = 1;
}
message Setting {
map<string, string> setting = 1;
}
This works, but it forces us to write some confusing code on both the client and server. Is there any way to avoid this solution and get closer to my desired structure?
Map is one of the composite datatypes of Protobuf.
In general protobuf may serialize fields in a random order.
Proto3 is the latest version of Protocol Buffers and includes the following changes from proto2: Field presence, also known as hasField , is removed by default for primitive fields. An unset primitive field has a language-defined default value.
Proto2: supports optional natively, the wrapper types were recommended but should be avoided in new applications. Proto3: originally did not support presence tracking for primitive fields. As of 2020, proto3 supports both optional fields which have has_foo() methods and "singular" fields, which do not.
No, basically. What you have is the closest you can do in protobuf.
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