The hlist combinator converts a Codec[A] in to a Codec[A :: HNil]. This is typically used with other combinators, like flatZip, which require an HList based codec. Repeated use of the ~ operator creates a left-associated Tuple2 based structure. For example, int8 ~ bool ~ int8 has type Codec[((Int, Boolean),...
The code that is there now needs two minor changes: The Message trait must be sealed, or otherwise, Shapeless will not provide a Generic.Aux[Message, SomeCoproduct] instance. The call to Codec.coproduct[Message] must be after all the subtypes are defined. Moving the companion to the end of the file is sufficient. With...
One way to do this is using the scodec.codecs.optional combinator, which returns a Codec[Option[A]] given a Codec[Boolean] and a Codec[A]. val structure: Codec[(Int, Option[Int])] = uint(7) ~ optional(bool, uint8) This gives us a codec of (Int, Option[Int]) - we need to convert this to a codec of Int. To do...