I'm at a company where we're currently using protobuf3 (with scalapb in my case) for a lot of our internal communication. This version of protobuf does away with the optional
and required
labels from previous versions due to the 'required is forever' argument. I can understand the argument from a protocol point of view, however this leaves at least us with a serialized result that is further away from our actual domain model when all nested messages are wrapped in Option
s.
The simple, and ugly IMHO, solution is to just do myProto.myField.getOrElse {throw Exception("bla"}
whenever a message field is accessed but I don't want a ton of getOreElse
s sprinkled across my code base when the field must be present.
My question is, is there either:
- A library that can help me translate protobuf messages into my domain model using my own case classes? Or
- A (relatively) simple way of doing this myself in a generalized way without massive amounts of boilerplate? I took a stab at doing this myself with some reflection but I'm fairly new to Scala. It was non-obvious how to map a
scalapb.descriptors.FieldDescriptor
to an actual value of the correct type.
Thanks