1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-05-31 23:15:21 +00:00
tgbotapi/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/abstracts/Message.kt

37 lines
1.5 KiB
Kotlin
Raw Normal View History

2018-12-26 08:07:24 +00:00
package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
2019-12-06 10:46:38 +00:00
import com.soywiz.klock.DateTime
import kotlinx.serialization.*
import kotlinx.serialization.internal.StringDescriptor
2018-12-26 08:07:24 +00:00
interface Message {
val messageId: MessageIdentifier
val chat: Chat
val date: DateTime
}
2019-08-17 16:29:42 +00:00
internal object TelegramBotAPIMessageDeserializationStrategy : DeserializationStrategy<Message> {
override val descriptor: SerialDescriptor = StringDescriptor.withName("TelegramBotAPIMessageSerializer")
override fun patch(decoder: Decoder, old: Message): Message = throw UpdateNotSupportedException(descriptor.name)
override fun deserialize(decoder: Decoder): Message {
return RawMessage.serializer().deserialize(decoder).asMessage
}
}
2019-08-17 16:29:42 +00:00
internal object TelegramBotAPIMessageDeserializeOnlySerializer : KSerializer<Message> {
override val descriptor: SerialDescriptor
get() = TelegramBotAPIMessageDeserializationStrategy.descriptor
override fun deserialize(decoder: Decoder): Message {
return TelegramBotAPIMessageDeserializationStrategy.deserialize(decoder)
}
override fun serialize(encoder: Encoder, obj: Message) {
throw UnsupportedOperationException("Currently, Message objects can't be serialized y this serializer")
}
}