1 /* <lambda>null2 * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 */ 4 5 package kotlinx.serialization.internal 6 7 import kotlinx.serialization.* 8 import kotlinx.serialization.descriptors.* 9 import kotlinx.serialization.encoding.* 10 11 @Suppress("Unused") 12 @PublishedApi 13 internal class InlineClassDescriptor( 14 name: String, 15 generatedSerializer: GeneratedSerializer<*> 16 ) : PluginGeneratedSerialDescriptor(name, generatedSerializer, 1) { 17 18 override val isInline: Boolean = true 19 20 override fun hashCode(): Int = super.hashCode() * 31 21 22 override fun equals(other: Any?): Boolean = equalsImpl(other) { otherDescriptor -> 23 otherDescriptor.isInline && 24 typeParameterDescriptors.contentEquals(otherDescriptor.typeParameterDescriptors) 25 } 26 } 27 28 @InternalSerializationApi InlinePrimitiveDescriptornull29public fun <T> InlinePrimitiveDescriptor(name: String, primitiveSerializer: KSerializer<T>): SerialDescriptor = 30 InlineClassDescriptor(name, object : GeneratedSerializer<T> { 31 // object needed only to pass childSerializers() 32 override fun childSerializers(): Array<KSerializer<*>> = arrayOf(primitiveSerializer) 33 34 override val descriptor: SerialDescriptor get() = error("unsupported") 35 36 override fun serialize(encoder: Encoder, value: T) { 37 error("unsupported") 38 } 39 40 override fun deserialize(decoder: Decoder): T { 41 error("unsupported") 42 } 43 }) 44