PrimitiveKind

sealed class PrimitiveKind : SerialKind

Values of primitive kinds usually are represented as a single value. All default serializers for Kotlin primitives types and String have primitive kind.

Serializers interaction

Serialization formats typically handle these kinds by calling a corresponding primitive method on encoder or decoder. For example, if the following serializable class class Color(val red: Byte, val green: Byte, val blue: Byte) is represented by your serializer as a single Int value, a typical serializer will serialize its value in the following manner:

val intValue = color.rgbToInt()
encoder.encodeInt(intValue)

and a corresponding Decoder counterpart.

Implementation note

Serial descriptors for primitive kinds are not expected to have any nested elements, thus its element count should be zero. If a class is represented as a primitive value, its corresponding serial name should not be equal to the corresponding primitive type name. For the Color example, represented as single Int, its descriptor should have INT kind, zero elements and serial name not equals to kotlin.Int: PrimitiveDescriptor("my.package.ColorAsInt", PrimitiveKind.INT)

Types

Link copied to clipboard
object BOOLEAN : PrimitiveKind

Primitive kind that represents a boolean true/false value. Corresponding Kotlin primitive is Boolean. Corresponding encoder and decoder methods are Encoder.encodeBoolean and Decoder.decodeBoolean.

Link copied to clipboard
object BYTE : PrimitiveKind

Primitive kind that represents a single byte value. Corresponding Kotlin primitive is Byte. Corresponding encoder and decoder methods are Encoder.encodeByte and Decoder.decodeByte.

Link copied to clipboard
object CHAR : PrimitiveKind

Primitive kind that represents a 16-bit unicode character value. Corresponding Kotlin primitive is Char. Corresponding encoder and decoder methods are Encoder.encodeChar and Decoder.decodeChar.

Link copied to clipboard
object DOUBLE : PrimitiveKind

Primitive kind that represents a 64-bit IEEE 754 floating point value. Corresponding Kotlin primitive is Double. Corresponding encoder and decoder methods are Encoder.encodeDouble and Decoder.decodeDouble.

Link copied to clipboard
object FLOAT : PrimitiveKind

Primitive kind that represents a 32-bit IEEE 754 floating point value. Corresponding Kotlin primitive is Float. Corresponding encoder and decoder methods are Encoder.encodeFloat and Decoder.decodeFloat.

Link copied to clipboard
object INT : PrimitiveKind

Primitive kind that represents a 32-bit int value. Corresponding Kotlin primitive is Int. Corresponding encoder and decoder methods are Encoder.encodeInt and Decoder.decodeInt.

Link copied to clipboard
object LONG : PrimitiveKind

Primitive kind that represents a 64-bit long value. Corresponding Kotlin primitive is Long. Corresponding encoder and decoder methods are Encoder.encodeLong and Decoder.decodeLong.

Link copied to clipboard
object SHORT : PrimitiveKind

Primitive kind that represents a 16-bit short value. Corresponding Kotlin primitive is Short. Corresponding encoder and decoder methods are Encoder.encodeShort and Decoder.decodeShort.

Link copied to clipboard
object STRING : PrimitiveKind

Primitive kind that represents a string value. Corresponding Kotlin primitive is String. Corresponding encoder and decoder methods are Encoder.encodeString and Decoder.decodeString.

Functions

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open override fun toString(): String

Inheritors

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard