Error raised when an unknown discriminator is encountered when decoding.
Error raised when an unknown discriminator is encountered when decoding.
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.
Supports creation of a coproduct codec.
Supports creation of a coproduct codec. See scodec.codecs.CoproductCodecBuilder for details.
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[A]
, returns a new codec that encodes/decodes B :: A :: HNil
.
When called on a Codec[A]
, returns a new codec that encodes/decodes B :: A :: HNil
.
HList equivalent of ~>
.
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 ~>
.
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.
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
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:
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
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.Gets this as a Decoder
.
Gets this as a Decoder
.
Gets this as an Encoder
.
Gets this as an Encoder
.
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
Converts this to a codec that fails encoding with an error.
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.
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.
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.
Creates a new codec with all unit values filtered out.
Creates a new codec with all unit values filtered out.
Converts this GenCodec
to a GenCodec[C, B]
using the supplied C => Attempt[A]
.
Converts this GenCodec
to a GenCodec[A, C]
using the supplied B => Attempt[C]
.
Attempts to encode the specified value in to a bit vector.
Attempts to encode the specified value in to a bit vector.
Converts this to a codec that fails decoding with an error.
Converts this to a codec that fails decoding with an error.
Transforms using two functions, A => Attempt[B]
and B => Attempt[A]
.
Transforms using two functions, A => Attempt[B]
and B => Attempt[A]
.
When called on a Codec[L]
for some L <: HList
, returns a new codec the encodes/decodes
the HList L
followed by the value A
, where the latter is encoded/decoded with the codec
returned from applying L
to f
.
When called on a Codec[L]
for some L <: HList
, returns a new codec the encodes/decodes
the HList L
followed by the value A
, where the latter is encoded/decoded with the codec
returned from applying L
to f
.
When called on a Codec[L]
for some L <: HList
, returns a new codec the encodes/decodes
the HList L
followed by the HList M
, where the latter is encoded/decoded with the codec
returned from applying L
to f
.
When called on a Codec[L]
for some L <: HList
, returns a new codec the encodes/decodes
the HList L
followed by the HList M
, where the latter is encoded/decoded with the codec
returned from applying L
to f
.
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 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 <~
.
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.
Lifts this codec in to a codec of a singleton hlist.
Converts this GenCodec
to a GenCodec[A, C]
using the supplied B => C
.
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
.
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 GenCodec
to a GenCodec[C, B]
using the supplied partial
function from C
to A
.
Polymorphic function version of xmap
.
Polymorphic function version of xmap
.
When called on a Codec[A]
where A
is not a subytpe of HList
, returns a new codec that's the result of
xmapping with p
and q
, using p
to convert from A
to B
and using q
to convert from
B
to A
.
polymorphic function that converts from A
to B
polymorphic function that converts from B
to A
Polymorphic function version of xmap
.
Polymorphic function version of xmap
.
When called on a Codec[L]
for some L <: HList
, returns a new codec that's the result of
xmapping with p
and q
, using p
to convert from L
to M
and using q
to convert from
M
to L
.
polymorphic function that converts from L
to M
polymorphic function that converts from M
to L
Polymorphic function version of xmap
that uses a single polymorphic function in both directions.
Polymorphic function version of xmap
that uses a single polymorphic function in both directions.
When called on a Codec[A]
where A
is not a subytpe of HList
, returns a new codec that's the result of
xmapping with p
for both forward and reverse directions.
polymorphic function that converts from A
to B
and from B
to A
Polymorphic function version of xmap
that uses a single polymorphic function in both directions.
Polymorphic function version of xmap
that uses a single polymorphic function in both directions.
When called on a Codec[L]
for some L <: HList
, returns a new codec that's the result of
xmapping with p
for both forward and reverse directions.
polymorphic function that converts from L
to M
and from M
to L
When called on a Decoder[C]
where C
is a coproduct containing type A
, converts to a Decoder[Option[A]]
.
When called on a Decoder[C]
where C
is a coproduct containing type A
, converts to a Decoder[Option[A]]
.
When called on a Encoder[C]
where C
is a coproduct containing type A
, converts to an Encoder[A]
.
When called on a Encoder[C]
where C
is a coproduct containing type A
, converts to an Encoder[A]
.
Provides a bound on the size of successfully encoded values.
Provides a bound on the size of successfully encoded values.
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
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.
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.
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
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.
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.
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
.
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)
.
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.
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
.
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
.
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.
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.
Transforms using two functions, A => Attempt[B]
and B => Attempt[A]
.
Transforms using two functions, A => Attempt[B]
and B => Attempt[A]
.
(discriminatorCodec: TransformSyntax[Codec, A]).exmap(f, g)
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
.
(discriminatorCodec: TransformSyntax[Codec, A]).narrow(f, g)
(discriminatorCodec: Tuple2CodecSupport[A]).self
(discriminatorCodec: EnrichedCoproductDecoder[A]).self
(discriminatorCodec: EnrichedCoproductEncoder[Coproduct]).self
(discriminatorCodec: ValueCodecEnrichedWithGenericSupport[A]).self
(discriminatorCodec: ValueCodecEnrichedWithHListSupport[A]).self
(discriminatorCodec: HListCodecEnrichedWithHListSupport[A]).self
Supports TransformSyntax.
Supports TransformSyntax.
(discriminatorCodec: TransformSyntax[Codec, A]).self
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
.
(discriminatorCodec: TransformSyntax[Codec, A]).widen(f, g)
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
.
(discriminatorCodec: TransformSyntax[Codec, A]).xmap(f, g)
(discriminatorCodec: ValueEnrichedWithTuplingSupport[DiscriminatorCodec[A, B]]).~(b)
Transforms using two functions, A => B
and B => Option[A]
.
Transforms using two functions, A => B
and B => Option[A]
.
Particularly useful when combined with case class apply/unapply. E.g., pxmap(fa, Foo.apply, Foo.unapply)
.
(Since version 1.7.0) Use widenOpt instead
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