Clones this encoder to create a new one with a different encoding function.
Clones this decoder to create a new one with a different decoding function.
Decodes encoded data.
Decodes encoded data.
This method is safe, in that it won't throw for run-of-the-mill errors. Unrecoverable errors such as out of memory exceptions are still thrown, but that's considered valid exceptional cases, where incorrectly encoded data is just... normal.
Callers that wish to fail fast and fail hard can use the unsafeDecode method instead.
Encodes the specified value.
Encodes the specified value.
Creates a new Encoder instances that applies the specified function before encoding.
Creates a new Encoder instances that applies the specified function before encoding.
This is a convenient way of creating Encoder instances: if you already have an Encoder[E, D, R]
, need to
write an Encoder[E, DD, R]
and know how to turn a DD
into a D
, you need but call contramap.
Creates a new Decoder instance that applies the specified function after decoding.
Creates a new Decoder instance that applies the specified function after decoding.
Decodes encoded data unsafely.
Combines a Decoder and an Encoder.
Codecs are only meant as a convenience, and should not be considered more powerful or desirable than encoders or decoders. Some types can be both encoded to and decoded from, and being able to define both instances in one call is convenient. It's however very poor practice to request a type to have a Codec instance - a much preferred alternative would be to require it to have a Decoder and an Encoder instance, which a Codec would fulfill.