Class/Object

scodec.codecs

CoproductCodecBuilder

Related Docs: object CoproductCodecBuilder | package codecs

Permalink

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 StringFormat
  5. by Ensuring
  6. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. final class NeedDiscriminators[A] extends AnyRef

    Permalink

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

Value Members

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

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

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

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

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

    Permalink

    Adds a codec to the head of this coproduct codec.

  6. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  7. val a: CoproductCodecBuilder[C, L, R]

    Permalink
    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
  8. def as[B](implicit as: Transformer[R, B]): CoproductCodecBuilder[C, L, B]

    Permalink

    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
  9. final def asInstanceOf[T0]: T0

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

    Permalink

    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.

  11. def choice: Codec[R]

    Permalink

    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.

  12. def clone(): AnyRef

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

    Permalink

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

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

    Permalink

    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.

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

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

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

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

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

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

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

    Permalink

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

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

    Permalink

    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
  23. def finalize(): Unit

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

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

    Permalink

    Applies the specified codec transformation to all component codecs.

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

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

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

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

    Permalink

    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
  30. def narrowc[B](f: (R) ⇒ Attempt[B])(g: (B) ⇒ R): CoproductCodecBuilder[C, L, B]

    Permalink

    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
  31. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  32. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  33. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  34. val self: CoproductCodecBuilder[C, L, R]

    Permalink

    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).
    Definition Classes
    TransformSyntax
  35. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  36. def toString(): String

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

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

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

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

    Permalink

    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
  41. def widenOpt[B](f: (R) ⇒ B, g: (B) ⇒ Option[R]): CoproductCodecBuilder[C, L, B]

    Permalink

    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
  42. def widenOptc[B](f: (R) ⇒ B)(g: (B) ⇒ Option[R]): CoproductCodecBuilder[C, L, B]

    Permalink

    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
  43. def widenc[B](f: (R) ⇒ B)(g: (B) ⇒ Attempt[R]): CoproductCodecBuilder[C, L, B]

    Permalink

    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
  44. def xmap[B](f: (R) ⇒ B, g: (B) ⇒ R): CoproductCodecBuilder[C, L, B]

    Permalink

    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
  45. def xmapc[B](f: (R) ⇒ B)(g: (B) ⇒ R): CoproductCodecBuilder[C, L, B]

    Permalink

    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
  46. def ~[B](b: B): (CoproductCodecBuilder[C, L, R], B)

    Permalink
    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
  47. def [B](y: B): (CoproductCodecBuilder[C, L, R], B)

    Permalink
    Implicit information
    This member is added by an implicit conversion from CoproductCodecBuilder[C, L, R] to ArrowAssoc[CoproductCodecBuilder[C, L, R]] performed by method ArrowAssoc 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]

    Permalink

    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

Deprecated Value Members

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

    Permalink

    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

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 any2stringadd[CoproductCodecBuilder[C, L, R]]

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

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

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

Combinators

Ungrouped