Hide Message serializers and postpone implementations later

This commit is contained in:
Him188 2020-12-28 14:20:51 +08:00
parent ffa23ec5ef
commit fc72811e2a
5 changed files with 15 additions and 2 deletions

View File

@ -166,6 +166,7 @@ private val builtInSerializersModule by lazy {
subclass(FlashImage::class, FlashImage.serializer()) subclass(FlashImage::class, FlashImage.serializer())
} }
@Suppress("DEPRECATION_ERROR")
contextual(Message::class, Message.Serializer) contextual(Message::class, Message.Serializer)
// contextual(SingleMessage::class, SingleMessage.Serializer) // contextual(SingleMessage::class, SingleMessage.Serializer)
contextual(MessageChain::class, MessageChain.Serializer) contextual(MessageChain::class, MessageChain.Serializer)

View File

@ -73,6 +73,7 @@ import kotlin.internal.LowPriorityInOverloadResolution
* *
* @see Contact.sendMessage 发送消息 * @see Contact.sendMessage 发送消息
*/ */
@Suppress("DEPRECATION_ERROR")
@Serializable(Message.Serializer::class) @Serializable(Message.Serializer::class)
public interface Message { // must be interface. Don't consider any changes. public interface Message { // must be interface. Don't consider any changes.
@ -197,15 +198,18 @@ public interface Message { // must be interface. Don't consider any changes.
public operator fun plus(another: Sequence<Message>): MessageChain = public operator fun plus(another: Sequence<Message>): MessageChain =
another.fold(this, Message::plus).asMessageChain() another.fold(this, Message::plus).asMessageChain()
@Deprecated("消息序列化仍未稳定,请在 2.0-RC 再使用", level = DeprecationLevel.HIDDEN)
public object Serializer : public object Serializer :
MessageSerializer by MessageSerializerImpl, MessageSerializer by MessageSerializerImpl,
KSerializer<Message> by PolymorphicSerializer(Message::class) KSerializer<Message> by PolymorphicSerializer(Message::class)
@Suppress("DEPRECATION_ERROR")
public companion object { public companion object {
/** /**
* JSON 字符串解析 [Message] * JSON 字符串解析 [Message]
* @see serializeToJsonString * @see serializeToJsonString
*/ */
@Deprecated("消息序列化仍未稳定,请在 2.0-RC 再使用", level = DeprecationLevel.HIDDEN)
@JvmOverloads @JvmOverloads
@JvmStatic @JvmStatic
public fun deserializeFromJsonString( public fun deserializeFromJsonString(
@ -219,6 +223,7 @@ public interface Message { // must be interface. Don't consider any changes.
* [Message] 序列化为 JSON 字符串. * [Message] 序列化为 JSON 字符串.
* @see deserializeFromJsonString * @see deserializeFromJsonString
*/ */
@Deprecated("消息序列化仍未稳定,请在 2.0-RC 再使用", level = DeprecationLevel.HIDDEN)
@JvmOverloads @JvmOverloads
@JvmStatic @JvmStatic
public fun Message.serializeToJsonString( public fun Message.serializeToJsonString(
@ -231,6 +236,7 @@ public interface Message { // must be interface. Don't consider any changes.
* @see serializeToJsonString * @see serializeToJsonString
* @see StringFormat.encodeToString * @see StringFormat.encodeToString
*/ */
@Deprecated("消息序列化仍未稳定,请在 2.0-RC 再使用", level = DeprecationLevel.HIDDEN)
@ExperimentalSerializationApi @ExperimentalSerializationApi
@JvmStatic @JvmStatic
public fun Message.serializeToString(format: StringFormat): String = public fun Message.serializeToString(format: StringFormat): String =

View File

@ -93,7 +93,8 @@ public interface MessageChain : Message, List<SingleMessage>, RandomAccess, Coda
asSequence().any { key.safeCast.invoke(it) != null } asSequence().any { key.safeCast.invoke(it) != null }
public object Serializer : KSerializer<MessageChain> { public object Serializer : KSerializer<MessageChain> {
private val delegate = ListSerializer(Message.Serializer) @Suppress("DEPRECATION_ERROR")
private val delegate = ListSerializer<Message>(Message.Serializer)
override val descriptor: SerialDescriptor = delegate.descriptor override val descriptor: SerialDescriptor = delegate.descriptor
override fun deserialize(decoder: Decoder): MessageChain = delegate.deserialize(decoder).asMessageChain() override fun deserialize(decoder: Decoder): MessageChain = delegate.deserialize(decoder).asMessageChain()
override fun serialize(encoder: Encoder, value: MessageChain): Unit = delegate.serialize(encoder, value) override fun serialize(encoder: Encoder, value: MessageChain): Unit = delegate.serialize(encoder, value)
@ -103,11 +104,13 @@ public interface MessageChain : Message, List<SingleMessage>, RandomAccess, Coda
forEach { it.safeCast<CodableMessage>()?.appendMiraiCode(builder) } forEach { it.safeCast<CodableMessage>()?.appendMiraiCode(builder) }
} }
@Suppress("DEPRECATION_ERROR")
public companion object { public companion object {
/** /**
* JSON 字符串解析 [MessageChain] * JSON 字符串解析 [MessageChain]
* @see serializeToJsonString * @see serializeToJsonString
*/ */
@Deprecated("消息序列化仍未稳定,请在 2.0-RC 再使用", level = DeprecationLevel.HIDDEN)
@JvmOverloads @JvmOverloads
@JvmStatic @JvmStatic
public fun deserializeFromJsonString( public fun deserializeFromJsonString(
@ -121,6 +124,7 @@ public interface MessageChain : Message, List<SingleMessage>, RandomAccess, Coda
* [MessageChain] 序列化为 JSON 字符串. * [MessageChain] 序列化为 JSON 字符串.
* @see deserializeFromJsonString * @see deserializeFromJsonString
*/ */
@Deprecated("消息序列化仍未稳定,请在 2.0-RC 再使用", level = DeprecationLevel.HIDDEN)
@JvmOverloads @JvmOverloads
@JvmStatic @JvmStatic
public fun MessageChain.serializeToJsonString( public fun MessageChain.serializeToJsonString(
@ -133,6 +137,7 @@ public interface MessageChain : Message, List<SingleMessage>, RandomAccess, Coda
* @see serializeToJsonString * @see serializeToJsonString
* @see StringFormat.encodeToString * @see StringFormat.encodeToString
*/ */
@Deprecated("消息序列化仍未稳定,请在 2.0-RC 再使用", level = DeprecationLevel.HIDDEN)
@ExperimentalSerializationApi @ExperimentalSerializationApi
@JvmStatic @JvmStatic
public fun MessageChain.serializeToString(format: StringFormat): String = public fun MessageChain.serializeToString(format: StringFormat): String =

View File

@ -46,7 +46,7 @@ import kotlin.random.Random
// not object for ServiceLoader. // not object for ServiceLoader.
internal open class MiraiImpl : IMirai, LowLevelApiAccessor { internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
companion object INSTANCE : MiraiImpl() { companion object INSTANCE : MiraiImpl() {
@Suppress("ObjectPropertyName", "unused") @Suppress("ObjectPropertyName", "unused", "DEPRECATION_ERROR")
private val _init = Mirai.let { private val _init = Mirai.let {
CIO // init CIO // init
Message.Serializer.registerSerializer(OfflineGroupImage::class, OfflineGroupImage.serializer()) Message.Serializer.registerSerializer(OfflineGroupImage::class, OfflineGroupImage.serializer())

View File

@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
internal class MessageSerializationTest { internal class MessageSerializationTest {
@Suppress("DEPRECATION_ERROR")
private val module get() = Message.Serializer.serializersModule private val module get() = Message.Serializer.serializersModule
private val format private val format
get() = Json { get() = Json {