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.

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

  • descriptor is always the same as one used in Encoder.beginStructure. While this parameter may seem redundant, it is required for efficient serialization process to avoid excessive field spilling. If you are writing your own format, you can safely ignore this parameter and use one used in beginStructure for simplicity.

  • index of the element being encoded. This element at this index in the descriptor should be associated with the one being written.

The symmetric interface for the deserialization process is CompositeDecoder.

Not stable for inheritance

CompositeEncoder 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.

Inheritors

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
abstract 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.

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

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

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

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

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

Returns Encoder 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 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.

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

Link copied to clipboard

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.

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

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

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

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

Link copied to clipboard

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: