mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
25 lines
848 B
Kotlin
25 lines
848 B
Kotlin
package com.jetbrains.lsp.protocol
|
|
|
|
import kotlinx.serialization.KSerializer
|
|
import kotlinx.serialization.descriptors.PrimitiveKind
|
|
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
|
|
import kotlinx.serialization.descriptors.SerialDescriptor
|
|
import kotlinx.serialization.encoding.Decoder
|
|
import kotlinx.serialization.encoding.Encoder
|
|
|
|
open class EnumAsIntSerializer<T : Enum<*>>(
|
|
serialName: String,
|
|
val serialize: (v: T) -> Int,
|
|
val deserialize: (v: Int) -> T
|
|
) : KSerializer<T> {
|
|
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor(serialName, PrimitiveKind.INT)
|
|
|
|
override fun serialize(encoder: Encoder, value: T) {
|
|
encoder.encodeInt(serialize(value))
|
|
}
|
|
|
|
override fun deserialize(decoder: Decoder): T {
|
|
val v = decoder.decodeInt()
|
|
return deserialize(v)
|
|
}
|
|
} |