CompositeDecoder

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.

Typically, for unordered data, CompositeDecoder is used by a serializer withing a decodeElementIndex-based loop that decodes all the required data one-by-one in any order and then terminates by calling endStructure. Please refer to decodeElementIndex for example of such loop.

All decode* methods have index and serialDescriptor parameters with a strict semantics and constraints:

  • descriptor argument is always the same as one used in Decoder.beginStructure.

  • index of the element being decoded. For sequential decoding, it is always a monotonic sequence from 0 to descriptor.elementsCount and for indexing-loop it is always an index that decodeElementIndex has returned from the last call.

The symmetric interface for the serialization process is CompositeEncoder.

Not stable for inheritance

CompositeDecoder interface is not stable for inheritance in 3rd party libraries, as new methods might be added to this interface or contracts of the existing methods can be changed.

Types

Link copied to clipboard
object Companion

Results of decodeElementIndex used for decoding control flow.

Functions

Link copied to clipboard
abstract 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
abstract 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
abstract 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
open fun decodeCollectionSize(descriptor: SerialDescriptor): Int

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
abstract 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
abstract 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
abstract 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
abstract 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
abstract 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
abstract fun <T : Any> decodeNullableSerializableElement(    descriptor: SerialDescriptor,     index: Int,     deserializer: DeserializationStrategy<T?>,     previousValue: T? = null): T?

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

Link copied to clipboard
open fun decodeSequentially(): Boolean

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
abstract fun <T> decodeSerializableElement(    descriptor: SerialDescriptor,     index: Int,     deserializer: DeserializationStrategy<T>,     previousValue: T? = null): T

Decodes value of the type T with the given deserializer.

Link copied to clipboard
abstract 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
abstract 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
abstract 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.

Properties

Link copied to clipboard
abstract val serializersModule: SerializersModule

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

Inheritors

Link copied to clipboard