There are case classes which are already used in the project. These classes are used in the slick-mapping too. And these classes extends some additional traits.
I don't want to generate all these classes from *.proto
description.
Is there an opportunity to extend them in protobuf
?
Or should I use a wrappers for them. And these wrappers will be described in *.proto
and generated from it.
For proto definition
message PBPerson {
int64 id = 1;
string name = 2;
google.protobuf.StringValue phone = 3;
repeated string hobbies = 4;
}
and scala case class definition
case class Person(
id: Long,
name: String,
phone: Option[String],
hobbies: Seq[String])
you can use https://github.com/changvvb/scala-protobuf-java
import pbconverts.{ Protoable, Scalable }
val convertedPBPerson:PBPerson = Protoable[Person,PBPerson].toProto(person)
val convertedPerson:Person = Scalable[Person,PBPerson].toScala(pbPerson)
Additionally, this lib uses scala macro to ensure it's a type-safe conversion.
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