scodec.codecs

CoproductCodecBuilder

final class CoproductCodecBuilder[C <: Coproduct, L <: HList, R] extends AnyRef

Supports building a coproduct codec.

A coproduct codec is built by:

To specify the discriminator, call either discriminatedByIndex(intCodec) or discriminatedBy(codec) followed by one of the methods on NeedDiscriminators. The former uses the type index as the discriminator value.

For example:

(int32 :+: bool(8) :+: variableSizeBytes(uint8, ascii)).discriminatedByIndex(uint8)

The first 8 bits of the resulting binary contains the discriminator value due to usage of the uint8 codec as the discriminator codec. A discriminator value of 0 causes the remaining bits to be encoded/decoded with int32. Similarly, a value of 1 causes the remaining bits to be encoded/decoded with bool(8) and a value of 2 causes the remaining bits to be encoded/decoded as a sized ASCII string.

Alternatively, discriminator values can be explicitly specified using discriminatedBy(codec).using(Sized(...)).

For example:

(int32 :+: bool(8) :+: variableSizeBytes(uint8, ascii)).discriminatedBy(fixedSizeBytes(1, ascii)).using(Sized("i", "b", "s"))

In this example, integers are associated with the discriminator i, booleans with b, and strings with s. The discriminator is encoded with fixedSizeBytes(1, ascii).

The methods which generate a Codec return a Codec[R] instead of a Codec[C]. Typically, C =:= R but the xmap and exmap methods allow transformations between C and R to be deferred until after the codec is built.

C

coproduct type

L

hlist type that has a codec for each type in the coproduct C

R

resulting codec type

Source
CoproductCodec.scala
Linear Supertypes
Ordering
  1. Grouped
  2. Alphabetic
  3. By inheritance
Inherited
  1. CoproductCodecBuilder
  2. AnyRef
  3. Any
Implicitly
  1. by toTransformSyntax
  2. by ValueEnrichedWithTuplingSupport
  3. by any2stringadd
  4. by any2stringfmt
  5. by any2ArrowAssoc
  6. by any2Ensuring
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. final class NeedDiscriminators[A] extends AnyRef

    Assists in creating a coproduct codec, after the coproduct type and discriminator type have been fixed.

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. def +(other: String): String

    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to StringAdd performed by method any2stringadd in scala.Predef.
    Definition Classes
    StringAdd
  5. def ->[B](y: B): (CoproductCodecBuilder[C, L, R], B)

    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to ArrowAssoc[CoproductCodecBuilder[C, L, R]] performed by method any2ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  6. def :+:[A](left: Codec[A]): CoproductCodecBuilder[:+:[A, C], ::[Codec[A], L], :+:[A, C]]

    Adds a codec to the head of this coproduct codec.

  7. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  8. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  9. val a: CoproductCodecBuilder[C, L, R]

    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to ValueEnrichedWithTuplingSupport[CoproductCodecBuilder[C, L, R]] performed by method ValueEnrichedWithTuplingSupport in scodec.codecs.
    Definition Classes
    ValueEnrichedWithTuplingSupport
  10. def as[B](implicit as: Transformer[R, B]): CoproductCodecBuilder[C, L, B]

    Transforms using implicitly available evidence that such a transformation is possible.

    Transforms using implicitly available evidence that such a transformation is possible.

    Typical transformations include converting:

    • an F[L] for some L <: HList to/from an F[CC] for some case class CC, where the types in the case class are aligned with the types in L
    • an F[C] for some C <: Coproduct to/from an F[SC] for some sealed class SC, where the component types in the coproduct are the leaf subtypes of the sealed class.
    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to TransformSyntax[[a]CoproductCodecBuilder[C, L, a], R] performed by method toTransformSyntax in scodec.codecs.CoproductCodecBuilder. This conversion will take place only if C is a subclass of Coproduct (C <: Coproduct) and at the same time L is a subclass of HList (L <: HList).
    Definition Classes
    TransformSyntax
  11. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  12. def auto[A](implicit discriminated: Discriminated[R, A], auto: CoproductBuilderAutoDiscriminators[R, C, A]): Codec[R]

    Automatically generates a Codec[R] given an implicit Discriminated[R, A] and an implicit Discriminator[R, X, A] for each X that is a member of the coproduct type that represents R.

  13. def choice: Codec[R]

    Creates a coproduct codec that encodes no discriminator.

    Creates a coproduct codec that encodes no discriminator. Rather, decoding is accomplished by trying each codec in order and using the first successful result.

  14. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  15. def discriminatedBy[A](discriminatorCodec: Codec[A]): NeedDiscriminators[A]

    Supports creation of a coproduct codec that uses an arbitrary discriminator.

  16. def discriminatedByIndex(discriminatorCodec: Codec[Int]): Codec[R] with KnownDiscriminatorType[Int]

    Creates the coproduct codec using the specified integer codec as the discriminator codec and using coproduct indices as discriminators.

    Creates the coproduct codec using the specified integer codec as the discriminator codec and using coproduct indices as discriminators.

    For example, (a :+: b :+: c).discriminatedByIndex(uint8) results in using 0 for a, 1 for b, and 2 for c.

  17. def ensuring(cond: (CoproductCodecBuilder[C, L, R]) ⇒ Boolean, msg: ⇒ Any): CoproductCodecBuilder[C, L, R]

    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to Ensuring[CoproductCodecBuilder[C, L, R]] performed by method any2Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  18. def ensuring(cond: (CoproductCodecBuilder[C, L, R]) ⇒ Boolean): CoproductCodecBuilder[C, L, R]

    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to Ensuring[CoproductCodecBuilder[C, L, R]] performed by method any2Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  19. def ensuring(cond: Boolean, msg: ⇒ Any): CoproductCodecBuilder[C, L, R]

    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to Ensuring[CoproductCodecBuilder[C, L, R]] performed by method any2Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  20. def ensuring(cond: Boolean): CoproductCodecBuilder[C, L, R]

    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to Ensuring[CoproductCodecBuilder[C, L, R]] performed by method any2Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  21. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  22. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  23. def exmap[S](rToS: (R) ⇒ Attempt[S], sToR: (S) ⇒ Attempt[R]): CoproductCodecBuilder[C, L, S]

    Creates a builder that applies the specified transformations to any codecs generated by the returned builder.

  24. def exmapc[B](f: (R) ⇒ Attempt[B])(g: (B) ⇒ Attempt[R]): CoproductCodecBuilder[C, L, B]

    Curried version of exmap.

    Curried version of exmap.

    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to TransformSyntax[[a]CoproductCodecBuilder[C, L, a], R] performed by method toTransformSyntax in scodec.codecs.CoproductCodecBuilder. This conversion will take place only if C is a subclass of Coproduct (C <: Coproduct) and at the same time L is a subclass of HList (L <: HList).
    Definition Classes
    TransformSyntax
  25. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  26. def formatted(fmtstr: String): String

    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to StringFormat performed by method any2stringfmt in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  27. def framing(ct: CodecTransformation): CoproductCodecBuilder[C, L, R]

    Applies the specified codec transformation to all component codecs.

  28. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  29. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  30. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  31. def narrow[B](f: (R) ⇒ Attempt[B], g: (B) ⇒ R): CoproductCodecBuilder[C, L, B]

    Transforms using two functions, A => Attempt[B] and B => A.

    Transforms using two functions, A => Attempt[B] and B => A.

    The supplied functions form an injection from B to A. Hence, this method converts from a larger to a smaller type. Hence, the name narrow.

    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to TransformSyntax[[a]CoproductCodecBuilder[C, L, a], R] performed by method toTransformSyntax in scodec.codecs.CoproductCodecBuilder. This conversion will take place only if C is a subclass of Coproduct (C <: Coproduct) and at the same time L is a subclass of HList (L <: HList).
    Definition Classes
    TransformSyntax
  32. def narrowc[B](f: (R) ⇒ Attempt[B])(g: (B) ⇒ R): CoproductCodecBuilder[C, L, B]

    Curried version of narrow.

    Curried version of narrow.

    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to TransformSyntax[[a]CoproductCodecBuilder[C, L, a], R] performed by method toTransformSyntax in scodec.codecs.CoproductCodecBuilder. This conversion will take place only if C is a subclass of Coproduct (C <: Coproduct) and at the same time L is a subclass of HList (L <: HList).
    Definition Classes
    TransformSyntax
  33. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  34. final def notify(): Unit

    Definition Classes
    AnyRef
  35. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  36. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  37. def toString(): String

    Definition Classes
    AnyRef → Any
  38. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  39. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  40. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  41. def widen[B](f: (R) ⇒ B, g: (B) ⇒ Attempt[R]): CoproductCodecBuilder[C, L, B]

    Transforms using two functions, A => B and B => Attempt[A].

    Transforms using two functions, A => B and B => Attempt[A].

    The supplied functions form an injection from A to B. Hence, this method converts from a smaller to a larger type. Hence, the name widen.

    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to TransformSyntax[[a]CoproductCodecBuilder[C, L, a], R] performed by method toTransformSyntax in scodec.codecs.CoproductCodecBuilder. This conversion will take place only if C is a subclass of Coproduct (C <: Coproduct) and at the same time L is a subclass of HList (L <: HList).
    Definition Classes
    TransformSyntax
  42. def widenOpt[B](f: (R) ⇒ B, g: (B) ⇒ Option[R]): CoproductCodecBuilder[C, L, B]

    Transforms using two functions, A => B and B => Option[A].

    Transforms using two functions, A => B and B => Option[A].

    Particularly useful when combined with case class apply/unapply. E.g., widenOpt(fa, Foo.apply, Foo.unapply).

    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to TransformSyntax[[a]CoproductCodecBuilder[C, L, a], R] performed by method toTransformSyntax in scodec.codecs.CoproductCodecBuilder. This conversion will take place only if C is a subclass of Coproduct (C <: Coproduct) and at the same time L is a subclass of HList (L <: HList).
    Definition Classes
    TransformSyntax
  43. def widenOptc[B](f: (R) ⇒ B)(g: (B) ⇒ Option[R]): CoproductCodecBuilder[C, L, B]

    Curried version of widenOpt.

    Curried version of widenOpt.

    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to TransformSyntax[[a]CoproductCodecBuilder[C, L, a], R] performed by method toTransformSyntax in scodec.codecs.CoproductCodecBuilder. This conversion will take place only if C is a subclass of Coproduct (C <: Coproduct) and at the same time L is a subclass of HList (L <: HList).
    Definition Classes
    TransformSyntax
  44. def widenc[B](f: (R) ⇒ B)(g: (B) ⇒ Attempt[R]): CoproductCodecBuilder[C, L, B]

    Curried version of widen.

    Curried version of widen.

    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to TransformSyntax[[a]CoproductCodecBuilder[C, L, a], R] performed by method toTransformSyntax in scodec.codecs.CoproductCodecBuilder. This conversion will take place only if C is a subclass of Coproduct (C <: Coproduct) and at the same time L is a subclass of HList (L <: HList).
    Definition Classes
    TransformSyntax
  45. def xmap[B](f: (R) ⇒ B, g: (B) ⇒ R): CoproductCodecBuilder[C, L, B]

    Transforms using the isomorphism described by two functions, A => B and B => A.

    Transforms using the isomorphism described by two functions, A => B and B => A.

    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to TransformSyntax[[a]CoproductCodecBuilder[C, L, a], R] performed by method toTransformSyntax in scodec.codecs.CoproductCodecBuilder. This conversion will take place only if C is a subclass of Coproduct (C <: Coproduct) and at the same time L is a subclass of HList (L <: HList).
    Definition Classes
    TransformSyntax
  46. def xmapc[B](f: (R) ⇒ B)(g: (B) ⇒ R): CoproductCodecBuilder[C, L, B]

    Curried version of xmap.

    Curried version of xmap.

    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to TransformSyntax[[a]CoproductCodecBuilder[C, L, a], R] performed by method toTransformSyntax in scodec.codecs.CoproductCodecBuilder. This conversion will take place only if C is a subclass of Coproduct (C <: Coproduct) and at the same time L is a subclass of HList (L <: HList).
    Definition Classes
    TransformSyntax
  47. def ~[B](b: B): (CoproductCodecBuilder[C, L, R], B)

    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to ValueEnrichedWithTuplingSupport[CoproductCodecBuilder[C, L, R]] performed by method ValueEnrichedWithTuplingSupport in scodec.codecs.
    Definition Classes
    ValueEnrichedWithTuplingSupport
  48. def [B](y: B): (CoproductCodecBuilder[C, L, R], B)

    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to ArrowAssoc[CoproductCodecBuilder[C, L, R]] performed by method any2ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Shadowed Implicit Value Members

  1. def exmap[B](f: (R) ⇒ Attempt[B], g: (B) ⇒ Attempt[R]): CoproductCodecBuilder[C, L, B]

    Transforms using two functions, A => Attempt[B] and B => Attempt[A].

    Transforms using two functions, A => Attempt[B] and B => Attempt[A].

    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to TransformSyntax[[a]CoproductCodecBuilder[C, L, a], R] performed by method toTransformSyntax in scodec.codecs.CoproductCodecBuilder. This conversion will take place only if C is a subclass of Coproduct (C <: Coproduct) and at the same time L is a subclass of HList (L <: HList).
    Shadowing
    This implicitly inherited member is shadowed by one or more members in this class.
    To access this member you can use a type ascription:
    (coproductCodecBuilder: TransformSyntax[[a]CoproductCodecBuilder[C, L, a], R]).exmap(f, g)
    Definition Classes
    TransformSyntax
  2. val self: CoproductCodecBuilder[C, L, R]

    Supports TransformSyntax.

    Supports TransformSyntax.

    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to TransformSyntax[[a]CoproductCodecBuilder[C, L, a], R] performed by method toTransformSyntax in scodec.codecs.CoproductCodecBuilder. This conversion will take place only if C is a subclass of Coproduct (C <: Coproduct) and at the same time L is a subclass of HList (L <: HList).
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (coproductCodecBuilder: TransformSyntax[[a]CoproductCodecBuilder[C, L, a], R]).self
    Definition Classes
    TransformSyntax
  3. val self: Any

    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to StringAdd performed by method any2stringadd in scala.Predef.
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (coproductCodecBuilder: StringAdd).self
    Definition Classes
    StringAdd
  4. val self: Any

    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to StringFormat performed by method any2stringfmt in scala.Predef.
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (coproductCodecBuilder: StringFormat).self
    Definition Classes
    StringFormat

Deprecated Value Members

  1. def pxmap[B](f: (R) ⇒ B, g: (B) ⇒ Option[R]): CoproductCodecBuilder[C, L, B]

    Transforms using two functions, A => B and B => Option[A].

    Transforms using two functions, A => B and B => Option[A].

    Particularly useful when combined with case class apply/unapply. E.g., pxmap(fa, Foo.apply, Foo.unapply).

    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to TransformSyntax[[a]CoproductCodecBuilder[C, L, a], R] performed by method toTransformSyntax in scodec.codecs.CoproductCodecBuilder. This conversion will take place only if C is a subclass of Coproduct (C <: Coproduct) and at the same time L is a subclass of HList (L <: HList).
    Definition Classes
    TransformSyntax
    Annotations
    @deprecated
    Deprecated

    (Since version 1.7.0) Use widenOpt instead

  2. def x: CoproductCodecBuilder[C, L, R]

    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to ArrowAssoc[CoproductCodecBuilder[C, L, R]] performed by method any2ArrowAssoc in scala.Predef.
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (coproductCodecBuilder: ArrowAssoc[CoproductCodecBuilder[C, L, R]]).x
    Definition Classes
    ArrowAssoc
    Annotations
    @deprecated
    Deprecated

    (Since version 2.10.0) Use leftOfArrow instead

  3. def x: CoproductCodecBuilder[C, L, R]

    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to Ensuring[CoproductCodecBuilder[C, L, R]] performed by method any2Ensuring in scala.Predef.
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (coproductCodecBuilder: Ensuring[CoproductCodecBuilder[C, L, R]]).x
    Definition Classes
    Ensuring
    Annotations
    @deprecated
    Deprecated

    (Since version 2.10.0) Use resultOfEnsuring instead

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion toTransformSyntax from CoproductCodecBuilder[C, L, R] to TransformSyntax[[a]CoproductCodecBuilder[C, L, a], R]

Inherited by implicit conversion ValueEnrichedWithTuplingSupport from CoproductCodecBuilder[C, L, R] to ValueEnrichedWithTuplingSupport[CoproductCodecBuilder[C, L, R]]

Inherited by implicit conversion any2stringadd from CoproductCodecBuilder[C, L, R] to StringAdd

Inherited by implicit conversion any2stringfmt from CoproductCodecBuilder[C, L, R] to StringFormat

Inherited by implicit conversion any2ArrowAssoc from CoproductCodecBuilder[C, L, R] to ArrowAssoc[CoproductCodecBuilder[C, L, R]]

Inherited by implicit conversion any2Ensuring from CoproductCodecBuilder[C, L, R] to Ensuring[CoproductCodecBuilder[C, L, R]]

Combinators

Ungrouped