Packages

  • package root
    Definition Classes
    root
  • package scodec

    Combinator library for working with binary data.

    Combinator library for working with binary data.

    The primary abstraction of this library is Codec, which provides the ability to encode/decode values to/from binary.

    There are more general abstractions though, such as Encoder and Decoder. There's also GenCodec which extends both Encoder and Decoder but allows the types to vary. Given these more general abstractions, a Codec[A] can be represented as a GenCodec[A, A].

    The more general abstractions are important because they allow operations on codecs that would not otherwise be possible. For example, given a Codec[A], mapping a function A => B over the codec yields a GenCodec[A, B]. Without the more general abstractions, map is impossible to define (e.g., how would codec.map(f).encode(b) be implemented?). Given a GenCodec[A, B], the encoding functionality can be ignored by treating it as a Decoder[B], or the encoding type can be changed via contramap. If after further transformations, the two types to GenCodec are equal, we can reconstitute a Codec from the GenCodec by calling fuse.

    See the codecs package object for pre-defined codecs for many common data types and combinators for building larger codecs out of smaller ones.

    For the categorically minded, note the following:

    • Decoder is a monad
    • Encoder is a contravariant functor
    • GenCodec is a profunctor
    • Codec is an invariant functor
    Definition Classes
    root
  • package codecs

    Provides codecs for common types and combinators for building larger codecs.

    Provides codecs for common types and combinators for building larger codecs.

    Bits and Bytes Codecs

    The simplest of the provided codecs are those that encode/decode BitVectors and ByteVectors directly. These are provided by bits and bytes methods. These codecs encode all of the bits/bytes directly in to the result and decode *all* of the remaining bits/bytes in to the result value. That is, the result of decode always returns a empty bit vector for the remaining bits.

    Similarly, fixed size alternatives are provided by the bits(size) and bytes(size) methods, which encode a fixed number of bits/bytes (or error if not provided the correct size) and decoded a fixed number of bits/bytes (or error if that many bits/bytes are not available).

    There are more specialized codecs for working with bits, including ignore and constant.

    Numeric Codecs

    There are built-in codecs for Int, Long, Float, and Double.

    There are a number of predefined integral codecs named using the form:

    [u]int$${size}[L]

    where u stands for unsigned, size is replaced by one of 8, 16, 24, 32, 64, and L stands for little-endian. For each codec of that form, the type is Codec[Int] or Codec[Long] depending on the specified size. For example, int32 supports 32-bit big-endian 2s complement signed integers, and uint16L supports 16-bit little-endian unsigned integers. Note: uint64[L] are not provided because a 64-bit unsigned integer does not fit in to a Long.

    Additionally, methods of the form [u]int[L](size: Int) and [u]long[L](size: Int) exist to build arbitrarily sized codecs, within the limitations of Int and Long.

    IEEE 754 floating point values are supported by the float, floatL, double, and doubleL codecs.

    Miscellaneous Value Codecs

    In addition to the numeric codecs, there are built-in codecs for Boolean, String, and UUID.

    Boolean values are supported by the bool codecs.

    Combinators

    There are a number of methods provided that create codecs out of other codecs. These include simple combinators such as fixedSizeBits and variableSizeBits and advanced combinators such as discriminated, which provides its own DSL for building a large codec out of many small codecs. For a list of all combinators, see the Combinators section below.

    Cryptography Codecs

    There are codecs that support working with encrypted data (encrypted), digital signatures and checksums (fixedSizeSignature and variableSizeSignature). Additionally, support for java.security.cert.Certificates is provided by certificate and x509Certificate.

    Definition Classes
    scodec
  • ChecksumCodec
  • ChecksumFactory
  • ChecksumMismatch
  • CipherFactory
  • CoproductBuilderAuto
  • CoproductBuilderAutoDiscriminators
  • CoproductBuilderKeyDiscriminators
  • CoproductCodecBuilder
  • DeMultiplexer
  • DeriveHListElementAux
  • Discriminated
  • Discriminator
  • DiscriminatorCodec
  • DropUnits
  • DropUnitsLowPriority
  • FlattenLeftPairs
  • ImplicitCodecs
  • ImplicitCollections
  • ImplicitValues
  • InvertibleRemove
  • KnownDiscriminatorType
  • MultiplexedCodec
  • NeedDiscriminatorCodec
  • PaddedVarAlignedCodec
  • SignatureFactory
  • SignatureSigner
  • Signer
  • SignerFactory
  • StringEnrichedWithCodecContextSupport
  • ToCoproductCodecs
  • ToHListCodec
  • Tuple10Codec
  • Tuple11Codec
  • Tuple12Codec
  • Tuple3Codec
  • Tuple4Codec
  • Tuple5Codec
  • Tuple6Codec
  • Tuple7Codec
  • Tuple8Codec
  • Tuple9Codec
  • TupleCodec
  • ValueEnrichedWithTuplingSupport
  • VarIntCodec
  • VarLongCodec
  • implicits
  • literals
  • ~
c

scodec.codecs

DiscriminatorCodec

final class DiscriminatorCodec[A, B] extends Codec[A] with KnownDiscriminatorType[B]

Codec that supports the binary structure tag ++ value where the tag identifies the encoding/decoding of the value.

To build an instance of this codec, call discriminated and specify the tag type via the by method. Then call one more more of the case combinators on this class.

Each of the case combinators provides two forms, one that defines a case with a single tag value and another, overloaded form that defines a case with a tag value to use in encoding and a predicate on tag value to use in decoding.

The most general case combinators are caseO and caseP (and their operator equivalents, ? and |). In addition to a tag or tag/predicate pair, the caseO combinators are defined by providing a mapping from A to Option[R], a mapping from R to A, and a Codec[R]. The case is used for encoding if the mapping from A to Option[R] returns a Some and it is used for decoding upon matching the tag value. The caseP combinators work the same but take a PartialFunction[A, R] instead of an A => Option[R].

If R is a subtype of A, then the mapping from R to A can be omitted. Hence, the subcaseO and subcaseP (and the operator equivalents, / and \) constrain R to being a subtype of A and do not take a R => A function.

Finally, the least generic case combinators are the typecase combinators which add further constraints to the subcase* combinators. Specifically, the typecase operators omit the A => Option[R] or PartialFunction[A, R] in favor of doing subtype checks. For example, the following codec is a Codec[AnyVal] that encodes a 0 if passed a Boolean and a 1 if passed an Int:

discriminated[AnyVal].by(uint8).typecase(0, bool).typecase(1, int32)

Often, the values are size-delimited -- that is, there is a size field after the tag field and before the value field. To support this, use the framing method to provide a transformation to each value codec. For example, framing(new CodecTransformation { def apply[X](c: Codec[X]) = variableSizeBytes(uint8, c) }).

Source
DiscriminatorCodec.scala
See also

discriminated

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. DiscriminatorCodec
  2. KnownDiscriminatorType
  3. Codec
  4. GenCodec
  5. Decoder
  6. Encoder
  7. AnyRef
  8. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. case class UnknownDiscriminator(discriminator: D, context: List[String]) extends Err with Product with Serializable

    Error raised when an unknown discriminator is encountered when decoding.

    Error raised when an unknown discriminator is encountered when decoding.

    Definition Classes
    KnownDiscriminatorType

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. def /[R <: A](encodeTag: B, decodeTag: (B) => Boolean)(toRep: (A) => Option[R])(cr: Codec[R]): DiscriminatorCodec[A, B]

    Returns a new discriminator codec with a new case added for the specified tag.

    Returns a new discriminator codec with a new case added for the specified tag. Operator alias for subcaseO.

    R

    representative type that this case handles

    encodeTag

    tag value to use during encoding for this case

    decodeTag

    function that determines if this case should be used for decoding given a decoded tag

    toRep

    function used during encoding that converts an A to an Option[R]

    cr

    codec that encodes/decodes Rs

  4. def /[R <: A](tag: B)(toRep: (A) => Option[R])(cr: Codec[R]): DiscriminatorCodec[A, B]

    Returns a new discriminator codec with a new case added for the specified tag.

    Returns a new discriminator codec with a new case added for the specified tag. Operator alias for subcaseO.

    R

    representative type that this case handles

    tag

    tag value for this case

    toRep

    function used during encoding that converts an A to an Option[R]

    cr

    codec that encodes/decodes Rs

  5. def :+:[B](left: Codec[B]): CoproductCodecBuilder[:+:[B, :+:[A, CNil]], ::[Codec[B], ::[Codec[A], HNil]], :+:[B, :+:[A, CNil]]]

    Supports creation of a coproduct codec.

    Supports creation of a coproduct codec. See scodec.codecs.CoproductCodecBuilder for details.

    Definition Classes
    Codec
  6. final def <~[B](codecB: Codec[B])(implicit ev: =:=[Unit, B]): Codec[A]

    Assuming B is Unit, creates a Codec[A] that: encodes the A followed by a unit; decodes an A followed by a unit and discards the decoded unit.

    Assuming B is Unit, creates a Codec[A] that: encodes the A followed by a unit; decodes an A followed by a unit and discards the decoded unit.

    Operator alias of dropRight.

    Definition Classes
    Codec
  7. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  8. final def >>~[B](f: (A) => Codec[B]): Codec[(A, B)]

    Returns a new codec that encodes/decodes a value of type (A, B) where the codec of B is dependent on A.

    Returns a new codec that encodes/decodes a value of type (A, B) where the codec of B is dependent on A. Operator alias for flatZip.

    Definition Classes
    Codec
  9. def ?[R](encodeTag: B, decodeTag: (B) => Boolean)(toRep: (A) => Option[R])(fromRep: (R) => A)(cr: Codec[R]): DiscriminatorCodec[A, B]

    Returns a new discriminator codec with a new case added for the specified tag.

    Returns a new discriminator codec with a new case added for the specified tag. Operator alias for caseO.

    R

    representative type that this case handles

    encodeTag

    tag value to use during encoding for this case

    decodeTag

    function that determines if this case should be used for decoding given a decoded tag

    toRep

    function used during encoding that converts an A to an Option[R]

    fromRep

    function used during decoding that converts an R to an A

    cr

    codec that encodes/decodes Rs

  10. def ?[R](tag: B)(toRep: (A) => Option[R])(fromRep: (R) => A)(cr: Codec[R]): DiscriminatorCodec[A, B]

    Returns a new discriminator codec with a new case added for the specified tag.

    Returns a new discriminator codec with a new case added for the specified tag. Operator alias for caseO.

    R

    representative type that this case handles

    tag

    tag value for this case

    toRep

    function used during encoding that converts an A to an Option[R]

    fromRep

    function used during decoding that converts an R to an A

    cr

    codec that encodes/decodes Rs

  11. def \[R <: A](encodeTag: B, decodeTag: (B) => Boolean)(toRep: PartialFunction[A, R])(cr: Codec[R]): DiscriminatorCodec[A, B]

    Returns a new discriminator codec with a new case added for the specified tag.

    Returns a new discriminator codec with a new case added for the specified tag. Operator alias for subcaseP.

    R

    representative type that this case handles

    encodeTag

    tag value to use during encoding for this case

    decodeTag

    function that determines if this case should be used for decoding given a decoded tag

    toRep

    partial function from A to R used during encoding

    cr

    codec that encodes/decodes Rs

  12. def \[R <: A](tag: B)(toRep: PartialFunction[A, R])(cr: Codec[R]): DiscriminatorCodec[A, B]

    Returns a new discriminator codec with a new case added for the specified tag.

    Returns a new discriminator codec with a new case added for the specified tag. Operator alias for subcaseP.

    R

    representative type that this case handles

    tag

    tag value for this case

    toRep

    partial function from A to R used during encoding

    cr

    codec that encodes/decodes Rs

  13. def asDecoder: Decoder[A]

    Gets this as a Decoder.

    Gets this as a Decoder.

    Definition Classes
    Decoder
  14. def asEncoder: Encoder[A]

    Gets this as an Encoder.

    Gets this as an Encoder.

    Definition Classes
    Encoder
  15. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  16. def caseO[R](encodeTag: B, decodeTag: (B) => Boolean)(toRep: (A) => Option[R])(fromRep: (R) => A)(cr: Codec[R]): DiscriminatorCodec[A, B]

    Returns a new discriminator codec with a new case added for the specified tag.

    Returns a new discriminator codec with a new case added for the specified tag.

    R

    representative type that this case handles

    encodeTag

    tag value to use during encoding for this case

    decodeTag

    function that determines if this case should be used for decoding given a decoded tag

    toRep

    function used during encoding that converts an A to an Option[R]

    fromRep

    function used during decoding that converts an R to an A

    cr

    codec that encodes/decodes Rs

  17. def caseO[R](tag: B)(toRep: (A) => Option[R])(fromRep: (R) => A)(cr: Codec[R]): DiscriminatorCodec[A, B]

    Returns a new discriminator codec with a new case added for the specified tag.

    Returns a new discriminator codec with a new case added for the specified tag.

    R

    representative type that this case handles

    tag

    tag value for this case

    toRep

    function used during encoding that converts an A to an Option[R]

    fromRep

    function used during decoding that converts an R to an A

    cr

    codec that encodes/decodes Rs

  18. def caseP[R](encodeTag: B, decodeTag: (B) => Boolean)(toRep: PartialFunction[A, R])(fromRep: (R) => A)(cr: Codec[R]): DiscriminatorCodec[A, B]

    Returns a new discriminator codec with a new case added for the specified tag.

    Returns a new discriminator codec with a new case added for the specified tag.

    R

    representative type that this case handles

    encodeTag

    tag value to use during encoding for this case

    decodeTag

    function that determines if this case should be used for decoding given a decoded tag

    toRep

    partial function from A to R used during encoding

    fromRep

    function used during decoding that converts an R to an A

    cr

    codec that encodes/decodes Rs

  19. def caseP[R](tag: B)(toRep: PartialFunction[A, R])(fromRep: (R) => A)(cr: Codec[R]): DiscriminatorCodec[A, B]

    Returns a new discriminator codec with a new case added for the specified tag.

    Returns a new discriminator codec with a new case added for the specified tag.

    R

    representative type that this case handles

    tag

    tag value for this case

    toRep

    partial function from A to R used during encoding

    fromRep

    function used during decoding that converts an R to an A

    cr

    codec that encodes/decodes Rs

  20. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  21. final def compact: Codec[A]

    Converts this codec to a new codec that compacts the encoded bit vector before returning it.

    Converts this codec to a new codec that compacts the encoded bit vector before returning it.

    Definition Classes
    CodecGenCodecEncoder
  22. final def complete: Codec[A]

    Converts this codec to a new codec that fails decoding if there are remaining bits.

    Converts this codec to a new codec that fails decoding if there are remaining bits.

    Definition Classes
    CodecGenCodecDecoder
  23. final def consume[B](f: (A) => Codec[B])(g: (B) => A): Codec[B]

    Similar to flatZip except the A type is not visible in the resulting type -- the binary effects of the Codec[A] still occur though.

    Similar to flatZip except the A type is not visible in the resulting type -- the binary effects of the Codec[A] still occur though.

    Example usage:

    case class Flags(x: Boolean, y: Boolean, z: Boolean)
    (bool :: bool :: bool :: ignore(5)).consume { flgs =>
      conditional(flgs.x, uint8) :: conditional(flgs.y, uint8) :: conditional(flgs.z, uint8)
    } {
      case x :: y :: z :: HNil => Flags(x.isDefined, y.isDefined, z.isDefined) }
    }

    Note that when B is an HList, this method is equivalent to using flatPrepend and derive. That is, a.consume(f)(g) === a.flatPrepend(f).derive[A].from(g).

    Definition Classes
    Codec
  24. def contramap[C](f: (C) => A): GenCodec[C, A]

    Converts this GenCodec to a GenCodec[C, B] using the supplied C => A.

    Converts this GenCodec to a GenCodec[C, B] using the supplied C => A.

    Definition Classes
    GenCodecEncoder
  25. def decode(bits: BitVector): Attempt[DecodeResult[A]]

    Attempts to decode a value of type A from the specified bit vector.

    Attempts to decode a value of type A from the specified bit vector.

    bits

    bits to decode

    returns

    error if value could not be decoded or the remaining bits and the decoded value

    Definition Classes
    DiscriminatorCodecDecoder
  26. def decodeOnly[AA >: A]: Codec[AA]

    Converts this to a codec that fails encoding with an error.

    Converts this to a codec that fails encoding with an error.

    Definition Classes
    CodecDecoder
  27. final def decodeValue(bits: BitVector): Attempt[A]

    Attempts to decode a value of type A from the specified bit vector and discards the remaining bits.

    Attempts to decode a value of type A from the specified bit vector and discards the remaining bits.

    bits

    bits to decode

    returns

    error if value could not be decoded or the decoded value

    Definition Classes
    Decoder
  28. final def downcast[B <: A](implicit tb: Typeable[B]): Codec[B]

    Safely lifts this codec to a codec of a subtype.

    Safely lifts this codec to a codec of a subtype.

    When a supertype of B that is not a supertype of A is decoded, an decoding error is returned.

    Definition Classes
    Codec
  29. final def dropLeft[B](codecB: Codec[B])(implicit ev: =:=[Unit, A]): Codec[B]

    Assuming A is Unit, creates a Codec[B] that: encodes the unit followed by a B; decodes a unit followed by a B and discards the decoded unit.

    Assuming A is Unit, creates a Codec[B] that: encodes the unit followed by a B; decodes a unit followed by a B and discards the decoded unit.

    Definition Classes
    Codec
  30. final def dropRight[B](codecB: Codec[B])(implicit ev: =:=[Unit, B]): Codec[A]

    Assuming B is Unit, creates a Codec[A] that: encodes the A followed by a unit; decodes an A followed by a unit and discards the decoded unit.

    Assuming B is Unit, creates a Codec[A] that: encodes the A followed by a unit; decodes an A followed by a unit and discards the decoded unit.

    Definition Classes
    Codec
  31. def econtramap[C](f: (C) => Attempt[A]): GenCodec[C, A]

    Converts this GenCodec to a GenCodec[C, B] using the supplied C => Attempt[A].

    Converts this GenCodec to a GenCodec[C, B] using the supplied C => Attempt[A].

    Definition Classes
    GenCodecEncoder
  32. def emap[C](f: (A) => Attempt[C]): GenCodec[A, C]

    Converts this GenCodec to a GenCodec[A, C] using the supplied B => Attempt[C].

    Converts this GenCodec to a GenCodec[A, C] using the supplied B => Attempt[C].

    Definition Classes
    GenCodecDecoder
  33. def encode(a: A): Attempt[BitVector]

    Attempts to encode the specified value in to a bit vector.

    Attempts to encode the specified value in to a bit vector.

    returns

    error or binary encoding of the value

    Definition Classes
    DiscriminatorCodecEncoder
  34. def encodeOnly: Codec[A]

    Converts this to a codec that fails decoding with an error.

    Converts this to a codec that fails decoding with an error.

    Definition Classes
    Encoder
  35. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  36. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  37. final def exmap[B](f: (A) => Attempt[B], g: (B) => Attempt[A]): Codec[B]

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

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

    Definition Classes
    Codec
  38. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  39. def flatMap[B](f: (A) => Decoder[B]): Decoder[B]

    Converts this decoder to a Decoder[B] using the supplied A => Decoder[B].

    Converts this decoder to a Decoder[B] using the supplied A => Decoder[B].

    Definition Classes
    Decoder
  40. final def flatZip[B](f: (A) => Codec[B]): Codec[(A, B)]

    Returns a new codec that encodes/decodes a value of type (A, B) where the codec of B is dependent on A.

    Returns a new codec that encodes/decodes a value of type (A, B) where the codec of B is dependent on A.

    Definition Classes
    Codec
  41. final def flattenLeftPairs(implicit f: FlattenLeftPairs[A]): Codec[Out]

    Converts this codec to an HList based codec by flattening all left nested pairs.

    Converts this codec to an HList based codec by flattening all left nested pairs. For example, flattenLeftPairs on a Codec[(((A, B), C), D)] results in a Codec[A :: B :: C :: D :: HNil]. This is particularly useful when combined with ~, ~>, and <~.

    Definition Classes
    Codec
  42. def framing(framing: CodecTransformation): DiscriminatorCodec[A, B]

    Replaces the current framing logic with the specified codec transformation.

    Replaces the current framing logic with the specified codec transformation.

    Every representative codec is wrapped with the framing logic when encoding/decoding.

    framing

    new framing logic

  43. final def fuse[AA <: A, BB >: A](implicit ev: =:=[BB, AA]): Codec[BB]

    Converts this generalized codec in to a non-generalized codec assuming A and B are the same type.

    Converts this generalized codec in to a non-generalized codec assuming A and B are the same type.

    Definition Classes
    GenCodec
  44. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  45. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  46. final def hlist: Codec[::[A, HNil]]

    Lifts this codec in to a codec of a singleton hlist.

    Lifts this codec in to a codec of a singleton hlist.

    Definition Classes
    Codec
  47. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  48. def map[C](f: (A) => C): GenCodec[A, C]

    Converts this GenCodec to a GenCodec[A, C] using the supplied B => C.

    Converts this GenCodec to a GenCodec[A, C] using the supplied B => C.

    Definition Classes
    GenCodecDecoder
  49. final def narrow[B](f: (A) => Attempt[B], g: (B) => A): Codec[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.

    Definition Classes
    Codec
  50. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  51. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  52. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  53. final def pairedWith[B](codecB: Codec[B]): Codec[(A, B)]

    Creates a Codec[(A, B)] that first encodes/decodes an A followed by a B.

    Creates a Codec[(A, B)] that first encodes/decodes an A followed by a B.

    Definition Classes
    Codec
  54. def pcontramap[C](f: (C) => Option[A]): GenCodec[C, A]

    Converts this GenCodec to a GenCodec[C, B] using the supplied partial function from C to A.

    Converts this GenCodec to a GenCodec[C, B] using the supplied partial function from C to A. The encoding will fail for any C that f maps to None.

    Definition Classes
    GenCodecEncoder
  55. def sizeBound: SizeBound

    Provides a bound on the size of successfully encoded values.

    Provides a bound on the size of successfully encoded values.

    Definition Classes
    DiscriminatorCodecEncoder
  56. def subcaseO[R <: A](encodeTag: B, decodeTag: (B) => Boolean)(toRep: (A) => Option[R])(cr: Codec[R]): DiscriminatorCodec[A, B]

    Returns a new discriminator codec with a new case added for the specified tag.

    Returns a new discriminator codec with a new case added for the specified tag.

    R

    representative type that this case handles

    encodeTag

    tag value to use during encoding for this case

    decodeTag

    function that determines if this case should be used for decoding given a decoded tag

    toRep

    function used during encoding that converts an A to an Option[R]

    cr

    codec that encodes/decodes Rs

  57. def subcaseO[R <: A](tag: B)(toRep: (A) => Option[R])(cr: Codec[R]): DiscriminatorCodec[A, B]

    Returns a new discriminator codec with a new case added for the specified tag.

    Returns a new discriminator codec with a new case added for the specified tag.

    R

    representative type that this case handles

    tag

    tag value for this case

    toRep

    function used during encoding that converts an A to an Option[R]

    cr

    codec that encodes/decodes Rs

  58. def subcaseP[R <: A](encodeTag: B, decodeTag: (B) => Boolean)(toRep: PartialFunction[A, R])(cr: Codec[R]): DiscriminatorCodec[A, B]

    Returns a new discriminator codec with a new case added for the specified tag.

    Returns a new discriminator codec with a new case added for the specified tag.

    R

    representative type that this case handles

    encodeTag

    tag value to use during encoding for this case

    decodeTag

    function that determines if this case should be used for decoding given a decoded tag

    toRep

    partial function from A to R used during encoding

    cr

    codec that encodes/decodes Rs

  59. def subcaseP[R <: A](tag: B)(toRep: PartialFunction[A, R])(cr: Codec[R]): DiscriminatorCodec[A, B]

    Returns a new discriminator codec with a new case added for the specified tag.

    Returns a new discriminator codec with a new case added for the specified tag.

    R

    representative type that this case handles

    tag

    tag value for this case

    toRep

    partial function from A to R used during encoding

    cr

    codec that encodes/decodes Rs

  60. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  61. def toField[K]: Codec[FieldType[K, A]]

    Lifts this codec to a codec of a shapeless field -- allowing it to be used in records and unions.

    Lifts this codec to a codec of a shapeless field -- allowing it to be used in records and unions.

    Definition Classes
    Codec
  62. def toFieldWithContext[K <: Symbol](k: K): Codec[FieldType[K, A]]

    Lifts this codec to a codec of a shapeless field -- allowing it to be used in records and unions.

    Lifts this codec to a codec of a shapeless field -- allowing it to be used in records and unions. The specified key is pushed in to the context of any errors that are returned from the resulting codec.

    Definition Classes
    Codec
  63. def toString(): String
    Definition Classes
    DiscriminatorCodec → AnyRef → Any
  64. final def tuple: Codec[::[A, HNil]]

    Alias for .hlist - allows cross compilation with Scodec 2 / Scala 3.

    Alias for .hlist - allows cross compilation with Scodec 2 / Scala 3.

    Definition Classes
    Codec
  65. def typecase[R <: A](encodeTag: B, decodeTag: (B) => Boolean, cr: Codec[R])(implicit arg0: ClassTag[R]): DiscriminatorCodec[A, B]

    Returns a new discriminator codec with a new case added for the specified tag.

    Returns a new discriminator codec with a new case added for the specified tag.

    Note: when encoding a value of A, this combinator compares the runtime class of that value to the runtime class of the supplied ClassTag[R]. As such, the *erased* type of A is used and hence, this operation is not safe to use with parameterized representation types.

    R

    representative type that this case handles

    encodeTag

    tag value to use during encoding for this case

    decodeTag

    function that determines if this case should be used for decoding given a decoded tag

    cr

    codec that encodes/decodes Rs

  66. def typecase[R <: A](tag: B, cr: Codec[R])(implicit arg0: ClassTag[R]): DiscriminatorCodec[A, B]

    Returns a new discriminator codec with a new case added for the specified tag.

    Returns a new discriminator codec with a new case added for the specified tag.

    Note: when encoding a value of A, this combinator compares the runtime class of that value to the runtime class of the supplied ClassTag[R]. As such, the *erased* type of A is used and hence, this operation is not safe to use with parameterized representation types.

    R

    representative type that this case handles

    tag

    tag value for this case

    cr

    codec that encodes/decodes Rs

  67. final def unit(zero: A): Codec[Unit]

    Converts this to a Codec[Unit] that encodes using the specified zero value and decodes a unit value when this codec decodes an A successfully.

    Converts this to a Codec[Unit] that encodes using the specified zero value and decodes a unit value when this codec decodes an A successfully.

    Definition Classes
    Codec
  68. final def upcast[B >: A](implicit ta: Typeable[A]): Codec[B]

    Safely lifts this codec to a codec of a supertype.

    Safely lifts this codec to a codec of a supertype.

    When a subtype of B that is not a subtype of A is passed to encode, an encoding error is returned.

    Definition Classes
    Codec
  69. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  70. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  71. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  72. final def widen[B](f: (A) => B, g: (B) => Attempt[A]): Codec[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.

    Definition Classes
    Codec
  73. final def withContext(context: String): Codec[A]

    Creates a new codec that is functionally equivalent to this codec but pushes the specified context string in to any errors returned from encode or decode.

    Creates a new codec that is functionally equivalent to this codec but pushes the specified context string in to any errors returned from encode or decode.

    Definition Classes
    Codec
  74. final def withToString(str: => String): Codec[A]

    Creates a new codec that is functionally equivalent to this codec but returns the specified string from toString.

    Creates a new codec that is functionally equivalent to this codec but returns the specified string from toString.

    Definition Classes
    Codec
  75. final def xmap[B](f: (A) => B, g: (B) => A): Codec[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.

    Definition Classes
    Codec
  76. def |[R](encodeTag: B, decodeTag: (B) => Boolean)(toRep: PartialFunction[A, R])(fromRep: (R) => A)(cr: Codec[R]): DiscriminatorCodec[A, B]

    Returns a new discriminator codec with a new case added for the specified tag.

    Returns a new discriminator codec with a new case added for the specified tag. Operator alias for caseP.

    R

    representative type that this case handles

    encodeTag

    tag value to use during encoding for this case

    decodeTag

    function that determines if this case should be used for decoding given a decoded tag

    toRep

    partial function from A to R used during encoding

    fromRep

    function used during decoding that converts an R to an A

    cr

    codec that encodes/decodes Rs

  77. def |[R](tag: B)(toRep: PartialFunction[A, R])(fromRep: (R) => A)(cr: Codec[R]): DiscriminatorCodec[A, B]

    Returns a new discriminator codec with a new case added for the specified tag.

    Returns a new discriminator codec with a new case added for the specified tag. Operator alias for caseP.

    R

    representative type that this case handles

    tag

    tag value for this case

    toRep

    partial function from A to R used during encoding

    fromRep

    function used during decoding that converts an R to an A

    cr

    codec that encodes/decodes Rs

  78. final def ~[B](codecB: Codec[B]): Codec[(A, B)]

    Creates a Codec[(A, B)] that first encodes/decodes an A followed by a B.

    Creates a Codec[(A, B)] that first encodes/decodes an A followed by a B.

    Operator alias for pairedWith.

    Definition Classes
    Codec
  79. final def ~>[B](codecB: Codec[B])(implicit ev: =:=[Unit, A]): Codec[B]

    Assuming A is Unit, creates a Codec[B] that: encodes the unit followed by a B; decodes a unit followed by a B and discards the decoded unit.

    Assuming A is Unit, creates a Codec[B] that: encodes the unit followed by a B; decodes a unit followed by a B and discards the decoded unit.

    Operator alias of dropLeft.

    Definition Classes
    Codec

Inherited from KnownDiscriminatorType[B]

Inherited from Codec[A]

Inherited from GenCodec[A, A]

Inherited from Decoder[A]

Inherited from Encoder[A]

Inherited from AnyRef

Inherited from Any

Primary Members

Discriminator Support

Basic Combinators

Tuple Support

HList Support

Coproduct Support

Ungrouped