Codec
Companion for Codec.
- Companion
- class
Document{}
def apply[A](encoder: A => Attempt[BitVector], decoder: BitVector => Attempt[DecodeResult[A]]): Codec[A]
Creates a codec from encoder and decoder functions.
Provides a
Typically used to consruct codecs for recursive structures.
Codec[A]
that delegates to a lazily evaluated Codec[A]
.Typically used to consruct codecs for recursive structures.
When called on a
the tuple
returned from applying
Codec[A]
for some A <: Tuple
, returns a new codec that encodes/decodesthe tuple
A
followed by the value B
, where the latter is encoded/decoded with the codecreturned from applying
A
to f
.Builds a
That is, this operator is a codec-level tuple prepend operation.
Codec[A *: B]
from a Codec[A]
and a Codec[B]
where B
is a tuple type.That is, this operator is a codec-level tuple prepend operation.
- Value Params
- codec
-
codec to prepend
codecB :+ codecA
returns a new codec that encodes/decodes the tuple B
followed by an A
.That is, this operator is a codec-level tuple append operation.
Builds a
That is, this operator is a codec-level tuple concat operation.
Codec[A ++ B]
from a Codec[A]
and a Codec[B]
where A
and B
are tuples.That is, this operator is a codec-level tuple concat operation.
- Value Params
- codecA
-
codec to concat
When called on a
the tuple
returned from applying
Codec[A]
for some A <: Tuple
, returns a new codec that encodes/decodesthe tuple
A
followed by the tuple B
, where the latter is encoded/decoded with the codecreturned from applying
A
to f
.When called on a
For example,
{{{
uint8 :: utf8
}}}
has type
uint8 :: utf8
}}}
Codec[A]
where A
is not a tuple, creates a new codec that encodes/decodes a tuple of (B, A)
.For example,
{{{
uint8 :: utf8
}}}
has type
Codec[(Int, Int)]
.uint8 :: utf8
}}}
Creates a new codec that encodes/decodes a tuple of
This allows later parts of a tuple codec to be dependent on earlier values.
A :: B
given a function A => Codec[B]
.This allows later parts of a tuple codec to be dependent on earlier values.
Creates an encoder that encodes with each of the specified encoders, returning
the first successful result.
the first successful result.
- Inhertied from
- EncoderFunctions
final def decodeBoth[A, B](decA: Decoder[A], decB: Decoder[B])(buffer: BitVector): Attempt[DecodeResult[(A, B)]]
Decodes a tuple
(A, B)
by first decoding A
and then using the remaining bits to decode B
.- Inhertied from
- DecoderFunctions
final def decodeBothCombine[A, B, C](decA: Decoder[A], decB: Decoder[B])(buffer: BitVector)(f: (A, B) => C): Attempt[DecodeResult[C]]
Decodes a
C
by first decoding A
and then using the remaining bits to decode B
, then applying the decoded values to the specified function to generate a C
.- Inhertied from
- DecoderFunctions
Creates a decoder that decodes with each of the specified decoders, returning
the first successful result.
the first successful result.
- Inhertied from
- DecoderFunctions
Encodes the specified values, one after the other, to a bit vector using the specified encoders.
- Inhertied from
- EncoderFunctions