These are chat archives for trueaccord/ScalaPB

26th
Jul 2017
Guillaume Massé
@MasseGuillaume
Jul 26 2017 07:16
Hello, I'm having a hard time mapping scala ADT to protobuf. I tought that oneof would solve all my issues but ScalaPB create an intermediate class with the value.
Is there any workarround this ?
For example:
in Scala:
sealed trait TaskId
case class RunnerTask(id: SnippetId) extends TaskId
case class EnsimeTask(id: UUID) extends TaskId
in Proto:
message TaskId {
  oneof value {
    SbtRun sbtRunValue = 1;
    Ensime ensimeValue = 2;   
  }

  message SbtRun {
    required SnippetId snippetId = 1;
  }

  message Ensime {
    required UUID id = 1;
  }
}
the issue is that I have something like: SbtRunValue(SbtRun(id))
in my opinion the SbtRunValue does not give much value.
I'm using the same technique, but it's a lot of boilerplate just to unwrap nested case classes
Nadav Samet
@thesamet
Jul 26 2017 15:32
One thing you could do is to add an implicit method to TaskId that would pattern match on value and give you a presentation you like better
(if you prefer not using implicit conversion to add methods, you can also use a scalapb option that makes the generated TaskId message extends some trait that has the method above)