Codec

Bidirectional codec that converts between domain Source values and their serialized Target representations.

Implementations expose both encoding and decoding functionality together with runtime type metadata so that calling code can select codecs without relying on Java reflection.

Parameters

Source

domain model type produced by decode.

Target

serialized data type consumed by encode.

See also

Types

Link copied to clipboard
object Companion

Factory helpers for constructing common Codec variants.

Properties

Link copied to clipboard
abstract val sourceClass: KClass<Source>

runtime KClass describing the supported Source type.

Link copied to clipboard
abstract val targetClass: KClass<Target>

runtime KClass describing the supported Target type.

Functions

Link copied to clipboard

Converts a StringCodec into a ByteArrayCodec using UTF-8 byte conversion.

Link copied to clipboard
inline fun <Source : Any, Target : Any, Source2 : Any> Codec<Source, Target>.unsafeTransformSource(crossinline from: (Source) -> Source2, crossinline to: (Source2) -> Source): Codec<Source2, Target>

Builds a new codec by transforming the decoded source type.

Link copied to clipboard
inline fun <Source : Any, Target : Any, Target2 : Any> Codec<Source, Target>.unsafeTransformTarget(crossinline from: (Target2) -> Target, crossinline to: (Target) -> Target2): Codec<Source, Target2>

Builds a new codec by transforming the encoded target type.