All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.kotlinx.serialization.internal.InlineClassDescriptor.kt Maven / Gradle / Ivy

/*
 * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */

package kotlinx.serialization.internal

import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*

@Suppress("Unused")
@PublishedApi
internal class InlineClassDescriptor(
    name: String,
    generatedSerializer: GeneratedSerializer<*>
) : PluginGeneratedSerialDescriptor(name, generatedSerializer, 1) {

    override val isInline: Boolean = true

    override fun hashCode(): Int = super.hashCode() * 31

    override fun equals(other: Any?): Boolean = equalsImpl(other) { otherDescriptor ->
        otherDescriptor.isInline &&
                typeParameterDescriptors.contentEquals(otherDescriptor.typeParameterDescriptors)
    }
}

@InternalSerializationApi
public fun  InlinePrimitiveDescriptor(name: String, primitiveSerializer: KSerializer): SerialDescriptor =
    InlineClassDescriptor(name, object : GeneratedSerializer {
        // object needed only to pass childSerializers()
        override fun childSerializers(): Array> = arrayOf(primitiveSerializer)

        override val descriptor: SerialDescriptor get() = error("unsupported")

        override fun serialize(encoder: Encoder, value: T) {
            error("unsupported")
        }

        override fun deserialize(decoder: Decoder): T {
            error("unsupported")
        }
    })




© 2015 - 2025 Weber Informatics LLC | Privacy Policy