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
- Alphabetic
- By Inheritance
- DiscriminatorCodec
- KnownDiscriminatorType
- Codec
- GenCodec
- Decoder
- Encoder
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- 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
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- 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 anOption[R]
- cr
codec that encodes/decodes
R
s
- 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 anOption[R]
- cr
codec that encodes/decodes
R
s
- 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
- final def <~[B](codecB: Codec[B])(implicit ev: =:=[Unit, B]): Codec[A]
Assuming
B
isUnit
, creates aCodec[A]
that: encodes theA
followed by a unit; decodes anA
followed by a unit and discards the decoded unit. - final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- 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 ofB
is dependent onA
. - 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 anOption[R]
- fromRep
function used during decoding that converts an
R
to anA
- cr
codec that encodes/decodes
R
s
- 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 anOption[R]
- fromRep
function used during decoding that converts an
R
to anA
- cr
codec that encodes/decodes
R
s
- 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
toR
used during encoding- cr
codec that encodes/decodes
R
s
- 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
toR
used during encoding- cr
codec that encodes/decodes
R
s
- def asDecoder: Decoder[A]
Gets this as a
Decoder
.Gets this as a
Decoder
.- Definition Classes
- Decoder
- def asEncoder: Encoder[A]
Gets this as an
Encoder
.Gets this as an
Encoder
.- Definition Classes
- Encoder
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- 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 anOption[R]
- fromRep
function used during decoding that converts an
R
to anA
- cr
codec that encodes/decodes
R
s
- 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 anOption[R]
- fromRep
function used during decoding that converts an
R
to anA
- cr
codec that encodes/decodes
R
s
- 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
toR
used during encoding- fromRep
function used during decoding that converts an
R
to anA
- cr
codec that encodes/decodes
R
s
- 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
toR
used during encoding- fromRep
function used during decoding that converts an
R
to anA
- cr
codec that encodes/decodes
R
s
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- final def compact: Codec[A]
Converts this codec to a new codec that compacts the encoded bit vector before returning it.
- final def complete: Codec[A]
Converts this codec to a new codec that fails decoding if there are remaining bits.
- final def consume[B](f: (A) => Codec[B])(g: (B) => A): Codec[B]
Similar to
flatZip
except theA
type is not visible in the resulting type -- the binary effects of theCodec[A]
still occur though.Similar to
flatZip
except theA
type is not visible in the resulting type -- the binary effects of theCodec[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 anHList
, this method is equivalent to usingflatPrepend
andderive
. That is,a.consume(f)(g) === a.flatPrepend(f).derive[A].from(g)
.- Definition Classes
- Codec
- def contramap[C](f: (C) => A): GenCodec[C, A]
Converts this
GenCodec
to aGenCodec[C, B]
using the suppliedC => A
. - 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
- DiscriminatorCodec → Decoder
- def decodeOnly[AA >: A]: Codec[AA]
Converts this to a codec that fails encoding with an error.
- 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
- 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 ofA
is decoded, an decoding error is returned.- Definition Classes
- Codec
- final def dropLeft[B](codecB: Codec[B])(implicit ev: =:=[Unit, A]): Codec[B]
Assuming
A
isUnit
, creates aCodec[B]
that: encodes the unit followed by aB
; decodes a unit followed by aB
and discards the decoded unit.Assuming
A
isUnit
, creates aCodec[B]
that: encodes the unit followed by aB
; decodes a unit followed by aB
and discards the decoded unit.- Definition Classes
- Codec
- final def dropRight[B](codecB: Codec[B])(implicit ev: =:=[Unit, B]): Codec[A]
Assuming
B
isUnit
, creates aCodec[A]
that: encodes theA
followed by a unit; decodes anA
followed by a unit and discards the decoded unit.Assuming
B
isUnit
, creates aCodec[A]
that: encodes theA
followed by a unit; decodes anA
followed by a unit and discards the decoded unit.- Definition Classes
- Codec
- def econtramap[C](f: (C) => Attempt[A]): GenCodec[C, A]
Converts this
GenCodec
to aGenCodec[C, B]
using the suppliedC => Attempt[A]
. - def emap[C](f: (A) => Attempt[C]): GenCodec[A, C]
Converts this
GenCodec
to aGenCodec[A, C]
using the suppliedB => Attempt[C]
. - 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
- DiscriminatorCodec → Encoder
- 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
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- final def exmap[B](f: (A) => Attempt[B], g: (B) => Attempt[A]): Codec[B]
Transforms using two functions,
A => Attempt[B]
andB => Attempt[A]
.Transforms using two functions,
A => Attempt[B]
andB => Attempt[A]
.- Definition Classes
- Codec
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- def flatMap[B](f: (A) => Decoder[B]): Decoder[B]
Converts this decoder to a
Decoder[B]
using the suppliedA => Decoder[B]
.Converts this decoder to a
Decoder[B]
using the suppliedA => Decoder[B]
.- Definition Classes
- Decoder
- 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 ofB
is dependent onA
.Returns a new codec that encodes/decodes a value of type
(A, B)
where the codec ofB
is dependent onA
.- Definition Classes
- Codec
- 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 aCodec[(((A, B), C), D)]
results in aCodec[A :: B :: C :: D :: HNil]
. This is particularly useful when combined with~
,~>
, and<~
.- Definition Classes
- Codec
- 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
- 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
andB
are the same type.Converts this generalized codec in to a non-generalized codec assuming
A
andB
are the same type.- Definition Classes
- GenCodec
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- 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
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def map[C](f: (A) => C): GenCodec[A, C]
Converts this
GenCodec
to aGenCodec[A, C]
using the suppliedB => C
. - final def narrow[B](f: (A) => Attempt[B], g: (B) => A): Codec[B]
Transforms using two functions,
A => Attempt[B]
andB => A
.Transforms using two functions,
A => Attempt[B]
andB => A
.The supplied functions form an injection from
B
toA
. Hence, this method converts from a larger to a smaller type. Hence, the namenarrow
.- Definition Classes
- Codec
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def pairedWith[B](codecB: Codec[B]): Codec[(A, B)]
Creates a
Codec[(A, B)]
that first encodes/decodes anA
followed by aB
.Creates a
Codec[(A, B)]
that first encodes/decodes anA
followed by aB
.- Definition Classes
- Codec
- def pcontramap[C](f: (C) => Option[A]): GenCodec[C, A]
Converts this
GenCodec
to aGenCodec[C, B]
using the supplied partial function fromC
toA
. - 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
- DiscriminatorCodec → Encoder
- 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 anOption[R]
- cr
codec that encodes/decodes
R
s
- 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 anOption[R]
- cr
codec that encodes/decodes
R
s
- 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
toR
used during encoding- cr
codec that encodes/decodes
R
s
- 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
toR
used during encoding- cr
codec that encodes/decodes
R
s
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- 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
- 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
- def toString(): String
- Definition Classes
- DiscriminatorCodec → AnyRef → Any
- 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
- 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 suppliedClassTag[R]
. As such, the *erased* type ofA
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
R
s
- 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 suppliedClassTag[R]
. As such, the *erased* type ofA
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
R
s
- 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 anA
successfully.Converts this to a
Codec[Unit]
that encodes using the specified zero value and decodes a unit value when this codec decodes anA
successfully.- Definition Classes
- Codec
- 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 ofA
is passed to encode, an encoding error is returned.- Definition Classes
- Codec
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def widen[B](f: (A) => B, g: (B) => Attempt[A]): Codec[B]
Transforms using two functions,
A => B
andB => Attempt[A]
.Transforms using two functions,
A => B
andB => Attempt[A]
.The supplied functions form an injection from
A
toB
. Hence, this method converts from a smaller to a larger type. Hence, the namewiden
.- Definition Classes
- Codec
- 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
- 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
- final def xmap[B](f: (A) => B, g: (B) => A): Codec[B]
Transforms using the isomorphism described by two functions,
A => B
andB => A
.Transforms using the isomorphism described by two functions,
A => B
andB => A
.- Definition Classes
- Codec
- 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
toR
used during encoding- fromRep
function used during decoding that converts an
R
to anA
- cr
codec that encodes/decodes
R
s
- 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
toR
used during encoding- fromRep
function used during decoding that converts an
R
to anA
- cr
codec that encodes/decodes
R
s
- final def ~[B](codecB: Codec[B]): Codec[(A, B)]
Creates a
Codec[(A, B)]
that first encodes/decodes anA
followed by aB
.Creates a
Codec[(A, B)]
that first encodes/decodes anA
followed by aB
.Operator alias for pairedWith.
- Definition Classes
- Codec
- final def ~>[B](codecB: Codec[B])(implicit ev: =:=[Unit, A]): Codec[B]
Assuming
A
isUnit
, creates aCodec[B]
that: encodes the unit followed by aB
; decodes a unit followed by aB
and discards the decoded unit.