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 that 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
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
.
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.
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
Supports building a Codec[M]
for some HList M
where M
is the HList
that results in removing
the first A
from L
.
Supports building a Codec[M]
for some HList M
where M
is the HList
that results in removing
the first A
from L
.
Example usage:
case class Flags(x: Boolean, y: Boolean, z: Boolean) val c = (bool :: bool :: bool :: ignore(5)).flatPrepend { flgs => conditional(flgs.x, uint8) :: conditional(flgs.y, uint8) :: conditional(flgs.z, uint8) } c.derive[Flags].from { case x :: y :: z :: HNil => Flags(x.isDefined, y.isDefined, z.isDefined) }
This codec, the Codec[L]
, is used for encoding/decoding. When decoding, the first value of type
A
is removed from the HList
.
When encoding, the returned codec computes an A
value using the supplied
function and inserts the computed A
in to the HList M
, yielding an HList L
. That HList L
is then encoded using the original codec.
This method is called derive
because the value of type A
is derived from the other fields
in the HList L
.
type to remove from L
and derive from the resulting list
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.
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
.
When called on a Codec[L]
for some L <: HList
, returns a new codec that 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 that 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 that 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 that 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
.
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
.
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.
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]
.
(paddedVarAlignedCodec: TransformSyntax[PaddedVarAlignedCodec, 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
.
(paddedVarAlignedCodec: TransformSyntax[PaddedVarAlignedCodec, A]).narrow(f, g)
(paddedVarAlignedCodec: Tuple2CodecSupport[A]).self
(paddedVarAlignedCodec: EnrichedCoproductDecoder[A]).self
(paddedVarAlignedCodec: EnrichedCoproductEncoder[Coproduct]).self
(paddedVarAlignedCodec: ValueCodecEnrichedWithGenericSupport[A]).self
(paddedVarAlignedCodec: ValueCodecEnrichedWithHListSupport[A]).self
(paddedVarAlignedCodec: HListCodecEnrichedWithHListSupport[A]).self
Supports TransformSyntax.
Supports TransformSyntax.
(paddedVarAlignedCodec: TransformSyntax[PaddedVarAlignedCodec, 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
.
(paddedVarAlignedCodec: TransformSyntax[PaddedVarAlignedCodec, 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
.
(paddedVarAlignedCodec: TransformSyntax[PaddedVarAlignedCodec, A]).xmap(f, g)
(paddedVarAlignedCodec: ValueEnrichedWithTuplingSupport[PaddedVarAlignedCodec[A]]).~(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