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
2
  • 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 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, 2019 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, 2019 at 6:25

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.