Codec

Companion for Codec.

Companion
class
class Object
trait Matchable
class Any

Value members

Concrete methods

inline
def apply[A](using c: Codec[A]): Codec[A]
def apply[A](encoder: A => Attempt[BitVector], decoder: BitVector => Attempt[DecodeResult[A]]): Codec[A]

Creates a codec from encoder and decoder functions.

Creates a codec from encoder and decoder functions.

def apply[A](encoder: Encoder[A], decoder: Decoder[A]): Codec[A]

Creates a codec from an encoder and a decoder.

Creates a codec from an encoder and a decoder.

inline
def derived[A](using m: Of[A]): Codec[A]
def fromTuple[A <: Tuple](a: A)(using evidence$1: IsMappedBy[Codec][A]): Codec[InverseMap[A, Codec]]

Constructs a Codec[(A, B, ..., N)] from a tuple (Codec[A], Codec[B], ..., Codec[N]).

Constructs a Codec[(A, B, ..., N)] from a tuple (Codec[A], Codec[B], ..., Codec[N]).

def lazily[A](codec: => Codec[A]): Codec[A]

Provides a Codec[A] that delegates to a lazily evaluated Codec[A]. Typically used to consruct codecs for recursive structures.

Provides a Codec[A] that delegates to a lazily evaluated Codec[A]. Typically used to consruct codecs for recursive structures.

Inherited methods

final
def choiceDecoder[A](decoders: Decoder[A]*): Decoder[A]

Creates a decoder that decodes with each of the specified decoders, returning the first successful result.

Creates a decoder that decodes with each of the specified decoders, returning the first successful result.

Inherited from
DecoderFunctions
final
def choiceEncoder[A](encoders: Encoder[A]*): Encoder[A]

Creates an encoder that encodes with each of the specified encoders, returning the first successful result.

Creates an encoder that encodes with each of the specified encoders, returning the first successful result.

Inherited 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.

Decodes a tuple (A, B) by first decoding A and then using the remaining bits to decode B.

Inherited 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.

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.

Inherited from
DecoderFunctions
final
def encode[A](a: A)(using encA: Encoder[A]): Attempt[BitVector]

Encodes the specified value using the given Encoder[A].

Encodes the specified value using the given Encoder[A].

Inherited from
EncoderFunctions
final
def encodeBoth[A, B](encA: Encoder[A], encB: Encoder[B])(a: A, b: B): Attempt[BitVector]

Encodes the specified values, one after the other, to a bit vector using the specified encoders.

Encodes the specified values, one after the other, to a bit vector using the specified encoders.

Inherited from
EncoderFunctions

Concrete fields

final lazy
val Codec_BitVector: Codec[BitVector]
final lazy
val Codec_Boolean: Codec[Boolean]
final lazy
val Codec_Byte: Codec[Byte]
final lazy
val Codec_ByteVector: Codec[ByteVector]
final lazy
val Codec_Double: Codec[Double]
final lazy
val Codec_Float: Codec[Float]
final lazy
val Codec_Int: Codec[Int]
final lazy
val Codec_Long: Codec[Long]
final lazy
val Codec_Short: Codec[Short]
final lazy
val Codec_String: Codec[String]
final lazy
val Codec_UUID: Codec[UUID]

Extensions

Extensions

extension [A, B](a: Codec[A])
def ::[A, B](using DummyImplicit): Codec[(A, B)]

When called on a Codec[A] where A is not a tuple, creates a new codec that encodes/decodes a tuple of (B, A). For example,

When called on a 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 }}}

extension [A <: Tuple](codecA: Codec[A])
inline
extension [A <: Tuple, B <: Tuple](codecA: Codec[A])
inline
def flatConcat(f: A => Codec[B]): Codec[Concat[A, B]]

When called on a Codec[A] for some A <: Tuple, returns a new codec that encodes/decodes the tuple A followed by the tuple B, where the latter is encoded/decoded with the codec returned from applying A to f.

When called on a Codec[A] for some A <: Tuple, returns a new codec that encodes/decodes the tuple A followed by the tuple B, where the latter is encoded/decoded with the codec returned from applying A to f.

extension [A <: Tuple, B <: Tuple](codecA: Codec[A])
inline
def ++(codecB: Codec[B]): Codec[Concat[A, B]]

Builds a 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.

Builds a 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

extension [A <: Tuple, B](codecA: Codec[A])
inline
def flatAppend(f: A => Codec[B]): Codec[Concat[A, B *: EmptyTuple]]

When called on a Codec[A] for some A <: Tuple, returns a new codec that encodes/decodes the tuple A followed by the value B, where the latter is encoded/decoded with the codec returned from applying A to f.

When called on a Codec[A] for some A <: Tuple, returns a new codec that encodes/decodes the tuple A followed by the value B, where the latter is encoded/decoded with the codec returned from applying A to f.

extension [A, B <: Tuple](codecA: Codec[A])
def flatPrepend(f: A => Codec[B]): Codec[A *: B]

Creates a new codec that encodes/decodes a tuple of A :: B given a function A => Codec[B]. This allows later parts of a tuple codec to be dependent on earlier values.

Creates a new codec that encodes/decodes a tuple of A :: B given a function A => Codec[B]. This allows later parts of a tuple codec to be dependent on earlier values.

extension [A, B <: Tuple](codecA: Codec[A])
def ::[A, B <: Tuple]: Codec[A *: B]

Builds a 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.

Builds a 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

extension [A, B <: Tuple](codecB: Codec[B])
inline
def :+(codecA: Codec[A]): Codec[Concat[B, A *: EmptyTuple]]

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.

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.