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
.
representative type that this case handles
tag value to use during encoding for this case
function that determines if this case should be used for decoding given a decoded tag
function used during encoding that converts an A
to an Option[R]
codec that encodes/decodes R
s
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
.
representative type that this case handles
tag value for this case
function used during encoding that converts an A
to an Option[R]
codec that encodes/decodes R
s
When called on a Codec[L]
for some L <: HList
, returns a new codec that encodes/decodes
the HList L
followed by a B
.
When called on a Codec[L]
for some L <: HList
, returns a new codec that encodes/decodes
the HList L
followed by a B
.
That is, this operator is a codec-level HList
append operation.
When called on a Codec[A]
where A
is not a subytpe of HList
, creates a new codec that encodes/decodes an HList
of B :: A :: HNil
.
When called on a Codec[A]
where A
is not a subytpe of HList
, creates a new codec that encodes/decodes an HList
of B :: A :: HNil
.
For example,
uint8 :: utf8
has type Codec[Int :: String :: HNil]
.
uint8 :: utf8
}}}
When called on a Codec[L]
for some L <: HList
, returns a new codec representing Codec[B :: L]
.
When called on a Codec[L]
for some L <: HList
, returns a new codec representing Codec[B :: L]
.
That is, this operator is a codec-level HList
prepend operation.
codec to prepend
When called on a Codec[L]
for some L <: HList
, returns a new codec the encodes/decodes
the HList K
followed by the HList L
.
When called on a Codec[L]
for some L <: HList
, returns a new codec the encodes/decodes
the HList K
followed by the HList L
.
When called on a Codec[L]
for some L <: HList
, returns a new codec that encodes/decodes
B :: L
but only returns L
.
When called on a Codec[L]
for some L <: HList
, returns a new codec that encodes/decodes
B :: L
but only returns L
. HList equivalent of ~>
.
Creates a Codec[A]
that: encodes an A
followed by the zero element of the Monoid
of B
;
decodes an A
followed by a B
and discards the decoded B
.
Creates a new codec that encodes/decodes an HList
type of A :: L
given a function A => Codec[L]
.
Creates a new codec that encodes/decodes an HList
type of A :: L
given a function A => Codec[L]
.
This allows later parts of an HList
codec to be dependent on earlier values.
Operator alias for flatPrepend
.
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 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
.
representative type that this case handles
tag value to use during encoding for this case
function that determines if this case should be used for decoding given a decoded tag
function used during encoding that converts an A
to an Option[R]
function used during decoding that converts an R
to an A
codec that encodes/decodes R
s
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
.
representative type that this case handles
tag value for this case
function used during encoding that converts an A
to an Option[R]
function used during decoding that converts an R
to an A
codec that encodes/decodes R
s
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
.
representative type that this case handles
tag value to use during encoding for this case
function that determines if this case should be used for decoding given a decoded tag
partial function from A
to R
used during encoding
codec that encodes/decodes R
s
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
.
representative type that this case handles
tag value for this case
partial function from A
to R
used during encoding
codec that encodes/decodes R
s
Returns a new codec that encodes/decodes a value of type B
by using an iso between A
and B
.
Returns a new codec that encodes/decodes a value of type B
by using an iso between A
and 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.
representative type that this case handles
tag value to use during encoding for this case
function that determines if this case should be used for decoding given a decoded tag
function used during encoding that converts an A
to an Option[R]
function used during decoding that converts an R
to an A
codec that encodes/decodes R
s
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.
representative type that this case handles
tag value for this case
function used during encoding that converts an A
to an Option[R]
function used during decoding that converts an R
to an A
codec that encodes/decodes R
s
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.
representative type that this case handles
tag value to use during encoding for this case
function that determines if this case should be used for decoding given a decoded tag
partial function from A
to R
used during encoding
function used during decoding that converts an R
to an A
codec that encodes/decodes R
s
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.
representative type that this case handles
tag value for this case
partial function from A
to R
used during encoding
function used during decoding that converts an R
to an A
codec that encodes/decodes R
s
Converts this codec to a new codec that compacts the encoded bit vector before returning it.
Converts this codec to a new codec that fails decoding if there are remaining bits.
Converts this GenCodec
to a GenCodec[C, B]
using the supplied C => 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 to decode
error if value could not be decoded or the remaining bits and the decoded value
Decodes a value of type A
from the specified bit vector and discards any
remaining bits, throwing an IllegalArgumentException
if an error occurs.
Decodes a value of type A
from the specified bit vector and discards any
remaining bits, throwing an IllegalArgumentException
if an error occurs.
bits to decode
the decoded value
if a decoding error occurs
Attempts to decode a value of type A
from the specified bit vector and discards any
remaining bits.
Attempts to decode a value of type A
from the specified bit vector and discards any
remaining bits.
bits to decode
error if value could not be decoded or the decoded value
Creates a Codec[B]
that: encodes the zero element of the Monoid
of A followed by a
B;
decodes an
A followed by a
B and discards the decoded
A.
Creates a Codec[B]
that: encodes the zero element of the Monoid
of A followed by a
B;
decodes an
A followed by a
B and discards the decoded
A.
Creates a Codec[A]
that: encodes an A
followed by the zero element of the Monoid
of B
;
decodes an A
followed by a B
and discards the decoded B
.
Creates a Codec[A]
that: encodes an A
followed by the zero element of the Monoid
of B
;
decodes an A
followed by a B
and discards the decoded B
.
Attempts to encode the specified value in to a bit vector.
Attempts to encode the specified value in to a bit vector.
Encodes the specified value in to a bit vector, throwing an
IllegalArgumentException
if encoding fails.
Encodes the specified value in to a bit vector, throwing an
IllegalArgumentException
if encoding fails.
value to encode
upon encoding failure
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]
.
Creates a new codec that encodes/decodes an HList
type of A :: L
given a function A => Codec[L]
.
Creates a new codec that encodes/decodes an HList
type of A :: L
given a function A => Codec[L]
.
This allows later parts of an HList
codec to be dependent on earlier values.
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
.
Creates a new codec that encodes/decodes an HList
type of A :: B :: HNil
given a function A => Codec[B]
.
Creates a new codec that encodes/decodes an HList
type of A :: B :: HNil
given a function A => Codec[B]
.
If B
is an HList
type, consider using flatPrepend
instead, which avoids nested HLists
.
This is the direct HList
equivalent of flatZip
.
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.
Lifts this codec in to a codec of a singleton hlist, which allows easy binding to case classes of one argument.
Lifts this codec in to a codec of a singleton hlist, which allows easy binding to case classes of one argument.
Converts this GenCodec
to a GenCodec[A, C]
using the supplied B => C
.
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
.
Converts this encoder to an Encoder[B]
using the supplied partial
function from B
to A
.
Converts this encoder to an Encoder[B]
using the supplied partial
function from B
to A
. The encoding will fail for any B
that
f
maps to None
.
Maps to a codec
of type B
, where there is a partial function
from B
to A
.
Maps to a codec
of type B
, where there is a partial function
from B
to A
. The encoding will fail for any B
that
f
maps to None
.
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.
representative type that this case handles
tag value to use during encoding for this case
function that determines if this case should be used for decoding given a decoded tag
function used during encoding that converts an A
to an Option[R]
codec that encodes/decodes R
s
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.
representative type that this case handles
tag value for this case
function used during encoding that converts an A
to an Option[R]
codec that encodes/decodes R
s
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.
representative type that this case handles
tag value to use during encoding for this case
function that determines if this case should be used for decoding given a decoded tag
partial function from A
to R
used during encoding
codec that encodes/decodes R
s
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.
representative type that this case handles
tag value for this case
partial function from A
to R
used during encoding
codec that encodes/decodes R
s
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.
representative type that this case handles
tag value to use during encoding for this case
function that determines if this case should be used for decoding given a decoded tag
codec that encodes/decodes R
s
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.
representative type that this case handles
tag value for this case
codec that encodes/decodes R
s
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
.
Maps to a codec of type B
using two total functions, A => B
and B => A
.
Maps to a codec of type B
using two total functions, A => B
and B => A
.
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
.
representative type that this case handles
tag value to use during encoding for this case
function that determines if this case should be used for decoding given a decoded tag
partial function from A
to R
used during encoding
function used during decoding that converts an R
to an A
codec that encodes/decodes R
s
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
.
representative type that this case handles
tag value for this case
partial function from A
to R
used during encoding
function used during decoding that converts an R
to an A
codec that encodes/decodes R
s
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.
Creates a Codec[B]
that: encodes the zero element of the Monoid
of A followed by a
B;
decodes an
A followed by a
B and discards the decoded
A.
(discriminatorCodec: ValueCodecEnrichedWithHListSupport[A]).self
(discriminatorCodec: HListCodecEnrichedWithHListSupport[A]).self
(discriminatorCodec: ValueEnrichedWithTuplingSupport[DiscriminatorCodec[A, B]]).~(b)
Codec that supports the binary structure
tag ++ value
where thetag
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
andcaseP
(and their operator equivalents,?
and|
). In addition to a tag or tag/predicate pair, thecaseO
combinators are defined by providing a mapping fromA
toOption[R]
, a mapping fromR
toA
, and aCodec[R]
. The case is used for encoding if the mapping fromA
toOption[R]
returns aSome
and it is used for decoding upon matching the tag value. ThecaseP
combinators work the same but take aPartialFunction[A, R]
instead of anA => Option[R]
.If
R
is a subtype ofA
, then the mapping fromR
toA
can be omitted. Hence, thesubcaseO
andsubcaseP
(and the operator equivalents,/
and\
) constrainR
to being a subtype ofA
and do not take aR => A
function.Finally, the least generic case combinators are the
typecase
combinators which add further constraints to thesubcase*
combinators. Specifically, the typecase operators omit theA => Option[R]
orPartialFunction[A, R]
in favor of doing subtype checks. For example, the following codec is aCodec[AnyVal]
that encodes a 0 if passed aBoolean
and a 1 if passed anInt
:discriminated