commonMain.dev.inmo.micro_utils.common.IndexedValueSerializer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of micro_utils.common-jvm Show documentation
Show all versions of micro_utils.common-jvm Show documentation
It is set of projects with micro tools for avoiding of routines coding
The newest version!
package dev.inmo.micro_utils.common
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializer
import kotlinx.serialization.builtins.PairSerializer
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
class IndexedValueSerializer(private val subSerializer: KSerializer) : KSerializer> {
private val originalSerializer = PairSerializer(Int.serializer(), subSerializer)
override val descriptor: SerialDescriptor
get() = originalSerializer.descriptor
override fun deserialize(decoder: Decoder): IndexedValue {
val pair = originalSerializer.deserialize(decoder)
return IndexedValue(
pair.first,
pair.second
)
}
override fun serialize(encoder: Encoder, value: IndexedValue) {
originalSerializer.serialize(
encoder,
Pair(value.index, value.value)
)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy