Created
January 8, 2018 18:35
-
-
Save Jacoby6000/4ba193649631f299d415ff7af0bba97b to your computer and use it in GitHub Desktop.
Scodec Discriminators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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