2

All of my case classes and case objects should be in protobuf. Now I need for them to belong to a single trait.

Sadly this is how I have done:

message WGCommand {
    oneof sealed_value {
        EnqueueWorkDone enq = 1;
        OpenWorkgroup oWg = 3;
    }
}

message OpenWorkgroup {}

message EnqueueWorkDone {
    required string id = 1;
    required string actorRef = 2;
}

This one creates

final case class OpenWorkgroup(){...}

I want my protobuf to produce something like this:

sealed trait WGCommand
case object OpenWorkgroup extends WGCommand
case class EnqueueWorkDone(id:String, actorRef:String) extends WGCommand
Jitterbug
  • 302
  • 1
  • 11
  • I think that what you are asking is how you can make a message with no fields be a case object and not a case class. This is not currently possible, but came up in the past and it's an enhancement that we can consider (see https://github.com/scalapb/ScalaPB/issues/485) - feel free to leave a note on that issue. In the mean time, you can create your own ADT hierarchy and use custom types to convert to and from them. – thesamet Aug 13 '19 at 16:26
  • 1
    Thanks @thesamet. I've resigned myself to using empty messages. I got more case classes than case objects anyway. If you could transfer your comment as an answer... I'll accept it. :) – Jitterbug Aug 16 '19 at 06:25

1 Answers1

1

I think that what you are asking is how you can make a message with no fields be a case object and not a case class. This is not currently possible, but came up in the past and it's an enhancement that we can consider (see https://github.com/scalapb/ScalaPB/issues/485) - feel free to leave a note on that issue. In the mean time, you can create your own ADT hierarchy and use custom types to convert to and from them.

Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96
thesamet
  • 6,382
  • 2
  • 31
  • 42