summaryrefslogtreecommitdiff
path: root/core/commonMain/src/kotlinx/serialization/internal/PluginHelperInterfaces.kt
blob: f613c2adbfb033bc89a389a09d05a5d0dd7ff91a (plain)
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
/*
 * 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 kotlin.jvm.*
import kotlin.native.concurrent.*

@SharedImmutable
@JvmField
internal val EMPTY_SERIALIZER_ARRAY: Array<KSerializer<*>> = arrayOf()

/**
 * An interface for a [KSerializer] instance generated by the compiler plugin.
 *
 * Should not be implemented manually or used directly.
 */
@InternalSerializationApi
public interface GeneratedSerializer<T> : KSerializer<T> {
    public fun childSerializers(): Array<KSerializer<*>>
    public fun typeParametersSerializers(): Array<KSerializer<*>> = EMPTY_SERIALIZER_ARRAY
}

/**
 * An internal interface used by the compiler plugin for objects that are factories of typed serializers, for example
 * for auto-generated companion objects for [Serializable] classes with type parameters.
 *
 * This interface is used to lookup and create serializers in K/N using `@AssociatedObjectKey`.
 * Should not be used in any user code. Please use generated `.serializer(kSerializer1, kSerializer2, ...)`
 * method on a companion or top-level `serializer(KType)` function.
 */
@Deprecated("Inserted into generated code and should not be used directly", level = DeprecationLevel.HIDDEN)
public interface SerializerFactory {
    public fun serializer(vararg typeParamsSerializers: KSerializer<*>): KSerializer<*>
}