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

commonMain.com.xebia.functional.openai.generated.model.MessageStreamEvent.kt Maven / Gradle / Ivy

The newest version!
/**
 *
 * Please note:
 * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * Do not edit this file manually.
 *
 */

@file:Suppress(
    "ArrayInDataClass",
    "EnumEntryName",
    "RemoveRedundantQualifierName",
    "UnusedImport"
)

package com.xebia.functional.openai.generated.model

import com.xebia.functional.openai.generated.model.MessageObject
import com.xebia.functional.openai.generated.model.MessageStreamEventOneOf
import com.xebia.functional.openai.generated.model.MessageStreamEventOneOf1
import com.xebia.functional.openai.generated.model.MessageStreamEventOneOf2
import com.xebia.functional.openai.generated.model.MessageStreamEventOneOf3
import com.xebia.functional.openai.generated.model.MessageStreamEventOneOf4
import com.xebia.functional.openai.attemptDeserialize
import kotlin.jvm.JvmInline
import kotlinx.serialization.*
import kotlinx.serialization.builtins.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
import kotlinx.serialization.json.*

@Serializable(with = MessageStreamEventSerializer::class)
sealed interface MessageStreamEvent {

  @JvmInline
  @Serializable
  value class CaseMessageStreamEventOneOf(val value: MessageStreamEventOneOf): MessageStreamEvent
  @JvmInline
  @Serializable
  value class CaseMessageStreamEventOneOf1(val value: MessageStreamEventOneOf1): MessageStreamEvent
  @JvmInline
  @Serializable
  value class CaseMessageStreamEventOneOf2(val value: MessageStreamEventOneOf2): MessageStreamEvent
  @JvmInline
  @Serializable
  value class CaseMessageStreamEventOneOf3(val value: MessageStreamEventOneOf3): MessageStreamEvent
  @JvmInline
  @Serializable
  value class CaseMessageStreamEventOneOf4(val value: MessageStreamEventOneOf4): MessageStreamEvent

}

object MessageStreamEventSerializer : KSerializer {
    @OptIn(InternalSerializationApi::class, ExperimentalSerializationApi::class)
    override val descriptor: SerialDescriptor = buildSerialDescriptor("MessageStreamEvent", PolymorphicKind.SEALED) { 
      element("1", MessageStreamEventOneOf.serializer().descriptor)
      element("2", MessageStreamEventOneOf1.serializer().descriptor)
      element("3", MessageStreamEventOneOf2.serializer().descriptor)
      element("4", MessageStreamEventOneOf3.serializer().descriptor)
      element("5", MessageStreamEventOneOf4.serializer().descriptor)
    }

    override fun deserialize(decoder: Decoder): MessageStreamEvent {
      val jsonSerde = Json { ignoreUnknownKeys = true }
      val json = decoder.decodeSerializableValue(JsonElement.serializer())
      return attemptDeserialize(json, 
        Pair(MessageStreamEvent.CaseMessageStreamEventOneOf::class) {
          MessageStreamEvent.CaseMessageStreamEventOneOf(jsonSerde.decodeFromJsonElement(MessageStreamEventOneOf.serializer(), json))
      },
        Pair(MessageStreamEvent.CaseMessageStreamEventOneOf1::class) {
          MessageStreamEvent.CaseMessageStreamEventOneOf1(jsonSerde.decodeFromJsonElement(MessageStreamEventOneOf1.serializer(), json))
      },
        Pair(MessageStreamEvent.CaseMessageStreamEventOneOf2::class) {
          MessageStreamEvent.CaseMessageStreamEventOneOf2(jsonSerde.decodeFromJsonElement(MessageStreamEventOneOf2.serializer(), json))
      },
        Pair(MessageStreamEvent.CaseMessageStreamEventOneOf3::class) {
          MessageStreamEvent.CaseMessageStreamEventOneOf3(jsonSerde.decodeFromJsonElement(MessageStreamEventOneOf3.serializer(), json))
      },
        Pair(MessageStreamEvent.CaseMessageStreamEventOneOf4::class) {
          MessageStreamEvent.CaseMessageStreamEventOneOf4(jsonSerde.decodeFromJsonElement(MessageStreamEventOneOf4.serializer(), json))
      })
    }

    override fun serialize(encoder: Encoder, value: MessageStreamEvent) =
      when(value) { 
        is MessageStreamEvent.CaseMessageStreamEventOneOf ->
        encoder.encodeSerializableValue(MessageStreamEventOneOf.serializer(), value.value)

        is MessageStreamEvent.CaseMessageStreamEventOneOf1 ->
        encoder.encodeSerializableValue(MessageStreamEventOneOf1.serializer(), value.value)

        is MessageStreamEvent.CaseMessageStreamEventOneOf2 ->
        encoder.encodeSerializableValue(MessageStreamEventOneOf2.serializer(), value.value)

        is MessageStreamEvent.CaseMessageStreamEventOneOf3 ->
        encoder.encodeSerializableValue(MessageStreamEventOneOf3.serializer(), value.value)

        is MessageStreamEvent.CaseMessageStreamEventOneOf4 ->
        encoder.encodeSerializableValue(MessageStreamEventOneOf4.serializer(), value.value)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy