Search code examples
javaprotocol-buffers

Protobuf3 why repeated map is not allowed?


I am using Protobuf3 and I need to create a list of map. I thought I can use repeated map<string, string> but seems like I cannot.

What should I use instead?

thanks


Solution

  • Essentially, map<...> is identical to:

    repeated TypedPair ...
    

    with

    message TypedPair {
        KeyType key = 1;
        ValueType value = 2;
    }
    

    So repeated map<...> would be repeated repeated TypedPair which doesn't make sense.

    Instead, define a type that has a map, and use that:

    message HazMap {
        map<...> map = 1;
    }
    ...
    repeated HazMap maps = 1;
    

    Could this be implicit? Perhaps - but it isn't right now.