AbstractEncoder
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.
Properties
Functions
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.
Encodes the beginning of the nested structure in a serialized form and returns CompositeDecoder responsible for encoding this very structure. E.g the hierarchy:
Encodes a boolean value. Corresponding kind is PrimitiveKind.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.
Encodes a single byte value. Corresponding kind is PrimitiveKind.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.
Encodes a 16-bit unicode character value. Corresponding kind is PrimitiveKind.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.
Begins a collection, encodes it using the given block and ends it.
Begins a collection, calls block with each item and ends the collections.
Encodes a 64-bit IEEE 754 floating point value. Corresponding kind is PrimitiveKind.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.
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.
Encodes a enum value that is stored at the index in enumDescriptor elements collection. Corresponding kind is SerialKind.ENUM.
Encodes a 32-bit IEEE 754 floating point value. Corresponding kind is PrimitiveKind.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.
Returns Encoder for encoding an underlying type of a value class in an inline manner. descriptor describes a serializable value class.
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.
Encodes a 32-bit integer value. Corresponding kind is PrimitiveKind.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.
Encodes a 64-bit integer value. Corresponding kind is PrimitiveKind.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.
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:
Encodes null
value.
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.
Encodes the nullable value of type T by delegating the encoding process to the given serializer.
Delegates value encoding of the type T to the given serializer. value is associated with an element at the given index in serial descriptor.
Encodes the value of type T by delegating the encoding process to the given serializer. For example, encodeInt
call is equivalent to delegating integer encoding to Int.Companion.serializer: encodeSerializableValue(Int.serializer())
Encodes a 16-bit short value. Corresponding kind is PrimitiveKind.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.
Encodes a string value. Corresponding kind is PrimitiveKind.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.
Begins a structure, encodes it using the given block and ends it.
Invoked to encode a value when specialized encode*
method was not overridden.
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.
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: