kotlinx-serialization / kotlinx.serialization.builtins / AbstractEncoder

AbstractEncoder

(common, js, jvm, native) 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.

Constructors

(common, js, jvm, native)

<init>

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.

<init>()

Properties

(common, js, jvm, native)

context

Context of the current serialization process, including contextual and polymorphic serialization and, potentially, a format-specific configuration.

open val context: SerialModule

Functions

(common, js, jvm, native)

beginStructure

Encodes the beginning of the nested structure in a serialized form and returns CompositeDecoder responsible for encoding this very structure. E.g the hierarchy:

open fun beginStructure(descriptor: SerialDescriptor, vararg typeSerializers: KSerializer<*>): CompositeEncoder
(common, js, jvm, native)

encodeBoolean

Encodes a boolean value. Corresponding kind is PrimitiveKind.BOOLEAN.

open fun encodeBoolean(value: Boolean): Unit
(common, js, jvm, native)

encodeBooleanElement

Encodes a boolean value associated with an element at the given index in serial descriptor. The element at the given index should have PrimitiveKind.BOOLEAN kind.

fun encodeBooleanElement(descriptor: SerialDescriptor, index: Int, value: Boolean): Unit
(common, js, jvm, native)

encodeByte

Encodes a single byte value. Corresponding kind is PrimitiveKind.BYTE.

open fun encodeByte(value: Byte): Unit
(common, js, jvm, native)

encodeByteElement

Encodes a single byte value associated with an element at the given index in serial descriptor. The element at the given index should have PrimitiveKind.BYTE kind.

fun encodeByteElement(descriptor: SerialDescriptor, index: Int, value: Byte): Unit
(common, js, jvm, native)

encodeChar

Encodes a 16-bit unicode character value. Corresponding kind is PrimitiveKind.CHAR.

open fun encodeChar(value: Char): Unit
(common, js, jvm, native)

encodeCharElement

Encodes a 16-bit unicode character value associated with an element at the given index in serial descriptor. The element at the given index should have PrimitiveKind.CHAR kind.

fun encodeCharElement(descriptor: SerialDescriptor, index: Int, value: Char): Unit
(common, js, jvm, native)

encodeDouble

Encodes a 64-bit IEEE 754 floating point value. Corresponding kind is PrimitiveKind.DOUBLE.

open fun encodeDouble(value: Double): Unit
(common, js, jvm, native)

encodeDoubleElement

Encodes a 64-bit IEEE 754 floating point value associated with an element at the given index in serial descriptor. The element at the given index should have PrimitiveKind.DOUBLE kind.

fun encodeDoubleElement(descriptor: SerialDescriptor, index: Int, value: Double): Unit
(common, js, jvm, native)

encodeElement

Invoked before writing an element that is part of the structure to determine whether it should be encoded. Element information can be obtained from the descriptor by the given index.

open fun encodeElement(descriptor: SerialDescriptor, index: Int): Boolean
(common, js, jvm, native)

encodeEnum

Encodes a enum value that is stored at the index in enumDescriptor elements collection. Corresponding kind is UnionKind.ENUM_KIND.

open fun encodeEnum(enumDescriptor: SerialDescriptor, index: Int): Unit
(common, js, jvm, native)

encodeFloat

Encodes a 32-bit IEEE 754 floating point value. Corresponding kind is PrimitiveKind.FLOAT.

open fun encodeFloat(value: Float): Unit
(common, js, jvm, native)

encodeFloatElement

Encodes a 32-bit IEEE 754 floating point value associated with an element at the given index in serial descriptor. The element at the given index should have PrimitiveKind.FLOAT kind.

fun encodeFloatElement(descriptor: SerialDescriptor, index: Int, value: Float): Unit
(common, js, jvm, native)

encodeInt

Encodes a 32-bit integer value. Corresponding kind is PrimitiveKind.INT.

open fun encodeInt(value: Int): Unit
(common, js, jvm, native)

encodeIntElement

Encodes a 32-bit integer value associated with an element at the given index in serial descriptor. The element at the given index should have PrimitiveKind.INT kind.

fun encodeIntElement(descriptor: SerialDescriptor, index: Int, value: Int): Unit
(common, js, jvm, native)

encodeLong

Encodes a 64-bit integer value. Corresponding kind is PrimitiveKind.LONG.

open fun encodeLong(value: Long): Unit
(common, js, jvm, native)

encodeLongElement

Encodes a 64-bit integer value associated with an element at the given index in serial descriptor. The element at the given index should have PrimitiveKind.LONG kind.

fun encodeLongElement(descriptor: SerialDescriptor, index: Int, value: Long): Unit
(common, js, jvm, native)

encodeNull

Encodes null value.

open fun encodeNull(): Unit
(common, js, jvm, native)

encodeNullableSerializableElement

Delegates nullable value encoding of the type T to the given serializer. value is associated with an element at the given index in serial descriptor.

fun <T : Any> encodeNullableSerializableElement(descriptor: SerialDescriptor, index: Int, serializer: SerializationStrategy<T>, value: T?): Unit
(common, js, jvm, native)

encodeSerializableElement

Delegates value encoding of the type T to the given serializer. value is associated with an element at the given index in serial descriptor.

fun <T> encodeSerializableElement(descriptor: SerialDescriptor, index: Int, serializer: SerializationStrategy<T>, value: T): Unit
(common, js, jvm, native)

encodeShort

Encodes a 16-bit short value. Corresponding kind is PrimitiveKind.SHORT.

open fun encodeShort(value: Short): Unit
(common, js, jvm, native)

encodeShortElement

Encodes a 16-bit short value associated with an element at the given index in serial descriptor. The element at the given index should have PrimitiveKind.SHORT kind.

fun encodeShortElement(descriptor: SerialDescriptor, index: Int, value: Short): Unit
(common, js, jvm, native)

encodeString

Encodes a string value. Corresponding kind is PrimitiveKind.STRING.

open fun encodeString(value: String): Unit
(common, js, jvm, native)

encodeStringElement

Encodes a string value associated with an element at the given index in serial descriptor. The element at the given index should have PrimitiveKind.STRING kind.

fun encodeStringElement(descriptor: SerialDescriptor, index: Int, value: String): Unit
(common, js, jvm, native)

encodeUnit

open fun encodeUnit(): Unit
(common, js, jvm, native)

encodeUnitElement

fun encodeUnitElement(descriptor: SerialDescriptor, index: Int): Unit
(common, js, jvm, native)

encodeValue

Invoked to encode a value when specialized encode* method was not overridden.

open fun encodeValue(value: Any): Unit