/
InlineClassDescriptor.kt
42 lines (32 loc) · 1.39 KB
/
InlineClassDescriptor.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* 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)
}
}
internal fun <T> InlinePrimitiveDescriptor(name: String, primitiveSerializer: KSerializer<T>): SerialDescriptor =
InlineClassDescriptor(name, object : GeneratedSerializer<T> {
// object needed only to pass childSerializers()
override fun childSerializers(): Array<KSerializer<*>> = 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")
}
})