Package kotlinx.serialization.encoding

Basic concepts of encoding and decoding of serialized data.

Types

Link copied to clipboard
abstract class AbstractDecoder : Decoder, CompositeDecoder

A skeleton implementation of both Decoder and CompositeDecoder that can be used for simple formats and for testability purpose. Most of the decode* methods have default implementation that delegates decodeValue(value: Any) as TargetType. See Decoder documentation for information about each particular decode* method.

Link copied to clipboard
abstract class AbstractEncoder : Encoder, CompositeEncoder

A skeleton implementation of both Encoder and CompositeEncoder that can be used for simple formats and for testability purpose. Most of the encode* methods have default implementation that delegates encodeValue(value: Any). See Encoder documentation for information about each particular encode* method.

Link copied to clipboard
interface CompositeDecoder

CompositeDecoder is a part of decoding process that is bound to a particular structured part of the serialized form, described by the serial descriptor passed to Decoder.beginStructure.

Link copied to clipboard
interface CompositeEncoder

CompositeEncoder is a part of encoding process that is bound to a particular structured part of the serialized form, described by the serial descriptor passed to Encoder.beginStructure.

Link copied to clipboard
interface Decoder

Decoder is a core deserialization primitive that encapsulates the knowledge of the underlying format and an underlying storage, exposing only structural methods to the deserializer, making it completely format-agnostic. Deserialization process takes a decoder and asks him for a sequence of primitive elements, defined by a deserializer serial form, while decoder knows how to retrieve these primitive elements from an actual format representations.

Link copied to clipboard
interface Encoder

Encoder is a core serialization primitive that encapsulates the knowledge of the underlying format and its storage, exposing only structural methods to the serializer, making it completely format-agnostic. Serialization process transforms a single value into the sequence of its primitive elements, also called its serial form, while encoding transforms these primitive elements into an actual format representation: JSON string, ProtoBuf ByteArray, in-memory map representation etc.

Functions

Link copied to clipboard
inline fun <T> Decoder.decodeStructure(descriptor: SerialDescriptor, crossinline block: CompositeDecoder.() -> T): T

Begins a structure, decodes it using the given block, ends it and returns decoded element.

Link copied to clipboard
inline fun Encoder.encodeCollection(    descriptor: SerialDescriptor,     collectionSize: Int,     crossinline block: CompositeEncoder.() -> Unit)

Begins a collection, encodes it using the given block and ends it.

inline fun <E> Encoder.encodeCollection(    descriptor: SerialDescriptor,     collection: Collection<E>,     crossinline block: CompositeEncoder.(index: Int, E) -> Unit)

Begins a collection, calls block with each item and ends the collections.

Link copied to clipboard
inline fun Encoder.encodeStructure(descriptor: SerialDescriptor, crossinline block: CompositeEncoder.() -> Unit)

Begins a structure, encodes it using the given block and ends it.