AbstractDecoder

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.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

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

Functions

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

Decodes the beginning of the nested structure in a serialized form and returns CompositeDecoder responsible for decoding this very structure.

Link copied to clipboard
open override fun decodeBoolean(): Boolean

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

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

Decodes a boolean value from the underlying input. The resulting value is associated with the descriptor element at the given index. The element at the given index should have PrimitiveKind.BOOLEAN kind.

Link copied to clipboard
open override fun decodeByte(): Byte

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

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

Decodes a single byte value from the underlying input. The resulting value is associated with the descriptor element at the given index. The element at the given index should have PrimitiveKind.BYTE kind.

Link copied to clipboard
open override fun decodeChar(): Char

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

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

Decodes a 16-bit unicode character value from the underlying input. The resulting value is associated with the descriptor element at the given index. The element at the given index should have PrimitiveKind.CHAR kind.

Link copied to clipboard

Method to decode collection size that may be called before the collection decoding. Collection type includes Collection, Map and Array (including primitive arrays). Method can return -1 if the size is not known in advance, though for sequential decoding knowing precise size is a mandatory requirement.

Link copied to clipboard
open override fun decodeDouble(): Double

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

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

Decodes a 64-bit IEEE 754 floating point value from the underlying input. The resulting value is associated with the descriptor element at the given index. The element at the given index should have PrimitiveKind.DOUBLE kind.

Link copied to clipboard
abstract fun decodeElementIndex(descriptor: SerialDescriptor): Int

Decodes the index of the next element to be decoded. Index represents a position of the current element in the serial descriptor element that can be found with SerialDescriptor.getElementIndex.

Link copied to clipboard
open override fun decodeEnum(enumDescriptor: SerialDescriptor): Int

Decodes a enum value and returns its index in enumDescriptor elements collection. Corresponding kind is SerialKind.ENUM.

Link copied to clipboard
open override fun decodeFloat(): Float

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

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

Decodes a 32-bit IEEE 754 floating point value from the underlying input. The resulting value is associated with the descriptor element at the given index. The element at the given index should have PrimitiveKind.FLOAT kind.

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

Returns Decoder for decoding an underlying type of a value class in an inline manner. descriptor describes a target value class.

Link copied to clipboard
open override fun decodeInlineElement(descriptor: SerialDescriptor, index: Int): Decoder

Returns Decoder for decoding an underlying type of a value class in an inline manner. Serializable value class is described by the child descriptor of given descriptor at index.

Link copied to clipboard
open override fun decodeInt(): Int

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

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

Decodes a 32-bit integer value from the underlying input. The resulting value is associated with the descriptor element at the given index. The element at the given index should have PrimitiveKind.INT kind.

Link copied to clipboard
open override fun decodeLong(): Long

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

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

Decodes a 64-bit integer value from the underlying input. The resulting value is associated with the descriptor element at the given index. The element at the given index should have PrimitiveKind.LONG kind.

Link copied to clipboard
open override fun decodeNotNullMark(): Boolean

Returns true if the current value in decoder is not null, false otherwise. This method is usually used to decode potentially nullable data:

Link copied to clipboard
open override fun decodeNull(): Nothing?

Decodes the null value and returns it.

Link copied to clipboard
override fun <T : Any> decodeNullableSerializableElement(descriptor: SerialDescriptor, index: Int, deserializer: DeserializationStrategy<T?>, previousValue: T?): T?

Decodes nullable value of the type T with the given deserializer.

Link copied to clipboard

Decodes the nullable value of type T by delegating the decoding process to the given deserializer.

Link copied to clipboard

Checks whether the current decoder supports strictly ordered decoding of the data without calling to decodeElementIndex. If the method returns true, the caller might skip decodeElementIndex calls and start invoking decode*Element directly, incrementing the index of the element one by one. This method can be called by serializers (either generated or user-defined) as a performance optimization, but there is no guarantee that the method will be ever called. Practically, it means that implementations that may benefit from sequential decoding should also support a regular decodeElementIndex-based decoding as well.

Link copied to clipboard
open override fun <T> decodeSerializableElement(descriptor: SerialDescriptor, index: Int, deserializer: DeserializationStrategy<T>, previousValue: T?): T

Decodes value of the type T with the given deserializer.

Link copied to clipboard
open fun <T> decodeSerializableValue(deserializer: DeserializationStrategy<T>, previousValue: T? = null): T

Decodes the value of type T by delegating the decoding process to the given deserializer. For example, decodeInt call is equivalent to delegating integer decoding to Int.serializer: decodeSerializableValue(Int.serializer())

Link copied to clipboard
open override fun decodeShort(): Short

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

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

Decodes a 16-bit short value from the underlying input. The resulting value is associated with the descriptor element at the given index. The element at the given index should have PrimitiveKind.SHORT kind.

Link copied to clipboard
open override fun decodeString(): String

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

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

Decodes a string value from the underlying input. The resulting value is associated with the descriptor element at the given index. The element at the given index should have PrimitiveKind.STRING kind.

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
open fun decodeValue(): Any

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

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

Denotes the end of the structure associated with current decoder. For example, composite decoder of JSON format will expect (and parse) a closing bracket in the underlying input.