Search code examples
protocol-buffers

How to implement a list of maps in Protocol Buffers?


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?


Solution

  • No, basically. What you have is the closest you can do in protobuf.