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[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 ~>
.
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
.
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
.
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.
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)
.
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.
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 to decode
error if value could not be decoded or the decoded value
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.
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.
error or binary encoding of the value
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]
.
Curried version of exmap
.
Curried version of exmap
.
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
.
Curried version of narrow
.
Curried version of 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
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
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.
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.
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)
.
Curried version of widenOpt
.
Curried version of widenOpt
.
Curried version of widen
.
Curried version of widen
.
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
.
Curried version of xmap
.
Curried version of xmap
.
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]
.
(tuple9Codec: TransformSyntax[Codec, (A, B, C, D, E, F, G, H, I)]).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
.
(tuple9Codec: TransformSyntax[Codec, (A, B, C, D, E, F, G, H, I)]).narrow(f, g)
(tuple9Codec: Tuple2CodecSupport[(A, B, C, D, E, F, G, H, I)]).self
(tuple9Codec: EnrichedCoproductEncoder[Coproduct with (A, B, C, D, E, F, G, H, I)]).self
(tuple9Codec: ValueCodecEnrichedWithGenericSupport[(A, B, C, D, E, F, G, H, I)]).self
(tuple9Codec: ValueCodecEnrichedWithHListSupport[(A, B, C, D, E, F, G, H, I)]).self
Supports TransformSyntax.
Supports TransformSyntax.
(tuple9Codec: TransformSyntax[Codec, (A, B, C, D, E, F, G, H, I)]).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
.
(tuple9Codec: TransformSyntax[Codec, (A, B, C, D, E, F, G, H, I)]).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
.
(tuple9Codec: TransformSyntax[Codec, (A, B, C, D, E, F, G, H, I)]).xmap(f, g)
(tuple9Codec: ValueEnrichedWithTuplingSupport[Tuple9Codec[A, B, C, D, E, F, G, H, I]]).~(b)
(tuple9Codec: Tuple2CodecSupport[(A, B, C, D, E, F, G, H, I)]).~~(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