2018-12-26 08:07:24 +00:00
|
|
|
package com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts
|
|
|
|
|
|
|
|
import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier
|
2019-08-17 16:08:36 +00:00
|
|
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.RawUpdate
|
|
|
|
import kotlinx.serialization.*
|
|
|
|
import kotlinx.serialization.internal.StringDescriptor
|
2018-12-26 08:07:24 +00:00
|
|
|
|
2019-01-21 06:13:31 +00:00
|
|
|
interface Update {
|
2018-12-26 08:07:24 +00:00
|
|
|
val updateId: UpdateIdentifier
|
2019-01-21 06:13:31 +00:00
|
|
|
val data: Any
|
2018-12-26 08:07:24 +00:00
|
|
|
}
|
2019-08-17 16:08:36 +00:00
|
|
|
|
|
|
|
object UpdateSerializerWithoutDeserialization : KSerializer<Update> {
|
|
|
|
override val descriptor: SerialDescriptor = StringDescriptor.withName("UpdateSerializerWithoutDeserialization")
|
|
|
|
|
|
|
|
override fun deserialize(decoder: Decoder): Update = UpdateDeserializationStrategy.deserialize(decoder)
|
|
|
|
|
|
|
|
override fun serialize(encoder: Encoder, obj: Update) = throw UnsupportedOperationException()
|
|
|
|
}
|
|
|
|
|
|
|
|
object UpdateDeserializationStrategy : DeserializationStrategy<Update> {
|
|
|
|
override val descriptor: SerialDescriptor = StringDescriptor.withName("UpdateDeserializationStrategy")
|
|
|
|
|
|
|
|
override fun patch(decoder: Decoder, old: Update): Update = throw UpdateNotSupportedException(descriptor.name)
|
|
|
|
|
|
|
|
override fun deserialize(decoder: Decoder): Update {
|
|
|
|
return RawUpdate.serializer().deserialize(decoder).asUpdate
|
|
|
|
}
|
|
|
|
}
|