One of the not-so-great things about proto3 is that maps have to have primitive types (string, int etc)
We can convert keys to custom types using the (scalapb.field).key_type field, but this requires a mapping from the business object to a simpler protobuf supported key.
What is the practice for defining protobuf messages with typemappers such that the generated code exposes fields of type scala.immutable.Map[ComplexKey, ComplexValue] ?
The only way I see to do that is to have:
option (scalapb.options) = {
import: "my.namespace.TypeMappers._"
};message KeyVal {
Key key = 1;
Val val = 2;
}
message KeyVals {
repeated KeyVal key_vals = 1;
}
message MyMsg {
KeyVals data = 1 [(scalapb.field).type = "scala.collection.immutable.Map[Key, Val]"]
}
Is there a way or a practice/pattern to define generic typemappers?
We end up creating 2 protobuf classes and one TypeMapper for every map this way.