All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lightningkite.lightningdb.ServerFileSerialization.kt Maven / Gradle / Ivy

package com.lightningkite.lightningdb

import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.descriptors.SerialKind
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

object ServerFileSerialization : KSerializer {
    //Description("A URL referencing a file that the server owns.")
    @OptIn(ExperimentalSerializationApi::class)
    override val descriptor: SerialDescriptor = object: SerialDescriptor {
        override val kind: SerialKind = PrimitiveKind.STRING
        override val serialName: String = "com.lightningkite.lightningdb.ServerFile"
        override val elementsCount: Int get() = 0
        override fun getElementName(index: Int): String = error()
        override fun getElementIndex(name: String): Int = error()
        override fun isElementOptional(index: Int): Boolean = error()
        override fun getElementDescriptor(index: Int): SerialDescriptor = error()
        override fun getElementAnnotations(index: Int): List = error()
        override fun toString(): String = "PrimitiveDescriptor($serialName)"
        private fun error(): Nothing = throw IllegalStateException("Primitive descriptor does not have elements")
        override val annotations: List = ServerFile::class.annotations
    }

    override fun serialize(encoder: Encoder, value: ServerFile) {
        encoder.encodeString(value.location)
    }

    override fun deserialize(decoder: Decoder): ServerFile {
        return ServerFile(decoder.decodeString())
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy