AbstractEncoder

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

AbstractEncoder
Link copied to clipboard
fun AbstractEncoder()

Functions

beginCollection
Link copied to clipboard
open fun beginCollection(descriptor: SerialDescriptor, collectionSize: Int): CompositeEncoder

Encodes the beginning of the collection with size collectionSize and the given serializer of its type parameters. This method has to be implemented only if you need to know collection size in advance, otherwise, beginStructure can be used.

beginStructure
Link copied to clipboard
open override fun beginStructure(descriptor: SerialDescriptor): CompositeEncoder

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

encodeBoolean
Link copied to clipboard
open override fun encodeBoolean(value: Boolean)

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

encodeBooleanElement
Link copied to clipboard
override fun encodeBooleanElement(descriptor: SerialDescriptor, index: Int, value: Boolean)

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.

encodeByte
Link copied to clipboard
open override fun encodeByte(value: Byte)

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

encodeByteElement
Link copied to clipboard
override fun encodeByteElement(descriptor: SerialDescriptor, index: Int, value: Byte)

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.

encodeChar
Link copied to clipboard
open override fun encodeChar(value: Char)

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

encodeCharElement
Link copied to clipboard
override fun encodeCharElement(descriptor: SerialDescriptor, index: Int, value: Char)

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.

encodeDouble
Link copied to clipboard
open override fun encodeDouble(value: Double)

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

encodeDoubleElement
Link copied to clipboard
override fun encodeDoubleElement(descriptor: SerialDescriptor, index: Int, value: Double)

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.

encodeElement
Link copied to clipboard
open fun encodeElement(descriptor: SerialDescriptor, index: Int): Boolean

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.

encodeEnum
Link copied to clipboard
open override fun encodeEnum(enumDescriptor: SerialDescriptor, index: Int)

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

encodeFloat
Link copied to clipboard
open override fun encodeFloat(value: Float)

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

encodeFloatElement
Link copied to clipboard
override fun encodeFloatElement(descriptor: SerialDescriptor, index: Int, value: Float)

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.

encodeInline
Link copied to clipboard
open override fun encodeInline(inlineDescriptor: SerialDescriptor): Encoder

Returns Encoder for encoding an underlying type of an inline class. inlineDescriptor describes a serializable inline class.

encodeInlineElement
Link copied to clipboard
override fun encodeInlineElement(descriptor: SerialDescriptor, index: Int): Encoder

Returns Encoder for decoding an underlying type of an inline class. Serializable inline class is described by the child descriptor of given descriptor at index.

encodeInt
Link copied to clipboard
open override fun encodeInt(value: Int)

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

encodeIntElement
Link copied to clipboard
override fun encodeIntElement(descriptor: SerialDescriptor, index: Int, value: Int)

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.

encodeLong
Link copied to clipboard
open override fun encodeLong(value: Long)

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

encodeLongElement
Link copied to clipboard
override fun encodeLongElement(descriptor: SerialDescriptor, index: Int, value: Long)

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.

encodeNotNullMark
Link copied to clipboard
open fun encodeNotNullMark()

Notifies the encoder that value of a nullable type that is being serialized is not null. It should be called before writing a non-null value of nullable type:

encodeNull
Link copied to clipboard
open override fun encodeNull()

Encodes null value.

encodeNullableSerializableElement
Link copied to clipboard
open override fun <T : Any> encodeNullableSerializableElement(descriptor: SerialDescriptor, index: Int, serializer: SerializationStrategy<T>, value: T?)

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.

encodeNullableSerializableValue
Link copied to clipboard
open fun <T : Any> encodeNullableSerializableValue(serializer: SerializationStrategy<T>, value: T?)

Encodes the nullable value of type T by delegating the encoding process to the given serializer.

encodeSerializableElement
Link copied to clipboard
open override fun <T> encodeSerializableElement(descriptor: SerialDescriptor, index: Int, serializer: SerializationStrategy<T>, value: T)

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

encodeSerializableValue
Link copied to clipboard
open fun <T> encodeSerializableValue(serializer: SerializationStrategy<T>, value: T)

Encodes the value of type T by delegating the encoding process to the given serializer. For example, encodeInt call us equivalent to delegating integer encoding to Int.serializer: encodeSerializableValue(Int.serializer())

encodeShort
Link copied to clipboard
open override fun encodeShort(value: Short)

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

encodeShortElement
Link copied to clipboard
override fun encodeShortElement(descriptor: SerialDescriptor, index: Int, value: Short)

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.

encodeString
Link copied to clipboard
open override fun encodeString(value: String)

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

encodeStringElement
Link copied to clipboard
override fun encodeStringElement(descriptor: SerialDescriptor, index: Int, value: String)

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.

encodeValue
Link copied to clipboard
open fun encodeValue(value: Any)

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

endStructure
Link copied to clipboard
open override fun endStructure(descriptor: SerialDescriptor)

Denotes the end of the structure associated with current encoder. For example, composite encoder of JSON format will write a closing bracket in the underlying input and reduce the number of nesting for pretty printing.

shouldEncodeElementDefault
Link copied to clipboard
open fun shouldEncodeElementDefault(descriptor: SerialDescriptor, index: Int): Boolean

Whether the format should encode values that are equal to the default values. This method is used by plugin-generated serializers for properties with default values:

Properties

serializersModule
Link copied to clipboard
abstract val serializersModule: SerializersModule

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