Skip to content

Instantly share code, notes, and snippets.

@Jacoby6000
Created January 8, 2018 18:35
Show Gist options
  • Select an option

  • Save Jacoby6000/4ba193649631f299d415ff7af0bba97b to your computer and use it in GitHub Desktop.

Select an option

Save Jacoby6000/4ba193649631f299d415ff7af0bba97b to your computer and use it in GitHub Desktop.
Scodec Discriminators
sealed trait Foo
case class Bar(a: Int) extends Foo
case class Baz(b: String) extends Foo
val barCodec: Codec[Bar] = ???
val bazCodec: Codec[Baz] = ???
val fooCodec: Codec[Foo] =
discriminated[Foo]
.by(uint32)
.typecase(0xDEAD, barCodec.withContext("bar"))
.typecase(0xBEEF, bazCodec.withContext("baz"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment