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 common Codec construction patterns.

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 by bridging through Kotlin's default string/byte array conversions.

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>

Adapts a codec to a different source type while reusing the original target representation.

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>

Adapts a codec to a different target type while keeping the original source type.