CborEncoder

This interface provides access to the current Cbor instance, so it can be properly taken into account in a custom serializer. For example, a custom serializer can output a byte array using Cbor.encodeToByteArray and embed resulting data into the output, as required, by some COSE structures. The actual CBOR Encoder used during serialization implements this interface, so it is possible to cast the encoder passed to KSerializer.serialize to CborEncoder when implementing such low-level serializers, to access configuration properties:

override fun serialize(encoder: Encoder, value: AlgorithmParameters) {
if (encoder is CborEncoder) {
val useDefiniteLengthEncoding = (encoder as CborEncoder).cbor.configuration.writeDefiniteLengths
// Do CBOR-specific low-level stuff
}
}

Properties

Link copied to clipboard
abstract val cbor: Cbor

Exposes the current Cbor instance and all its configuration flags. Useful for low-level custom serializers.

Link copied to clipboard

Functions

Link copied to clipboard
open fun beginCollection(descriptor: SerialDescriptor, collectionSize: Int): CompositeEncoder
Link copied to clipboard
Link copied to clipboard
abstract fun encodeBoolean(value: Boolean)
Link copied to clipboard
abstract fun encodeByte(value: Byte)
Link copied to clipboard
abstract fun encodeChar(value: Char)
Link copied to clipboard
abstract fun encodeDouble(value: Double)
Link copied to clipboard
abstract fun encodeEnum(enumDescriptor: SerialDescriptor, index: Int)
Link copied to clipboard
abstract fun encodeFloat(value: Float)
Link copied to clipboard
abstract fun encodeInline(descriptor: SerialDescriptor): Encoder
Link copied to clipboard
abstract fun encodeInt(value: Int)
Link copied to clipboard
abstract fun encodeLong(value: Long)
Link copied to clipboard
Link copied to clipboard
abstract fun encodeNull()
Link copied to clipboard
open fun <T : Any> encodeNullableSerializableValue(serializer: SerializationStrategy<T>, value: T?)
Link copied to clipboard
open fun <T> encodeSerializableValue(serializer: SerializationStrategy<T>, value: T)
Link copied to clipboard
abstract fun encodeShort(value: Short)
Link copied to clipboard
abstract fun encodeString(value: String)