我正在尝试在现有项目中使用鉴别器,我猜我的课程有问题。
考虑这个编解码器示例。如果我将TurnLeft
其编解码器更改为
sealed class TurnLeft(degrees: Int) extends Command {
def getDegrees: Int = degrees
}
implicit val leftCodec: Codec[TurnLeft] = uint8or16.xmap[TurnLeft](v => new TurnLeft(v), _.getDegrees)
我明白了
Error:(x, x) could not find Lazy implicit value of type scodec.Codec[Command]
val codec: Codec[Either[UnrecognizedCommand, Command]] = discriminatorFallback(unrecognizedCodec, Codec[Command])
如果我制作degrees
字段值字段,这一切都有效。我怀疑无形的东西很棘手。我应该怎么做才能让它工作?
演示该问题的示例项目在此处。