mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-04 14:49:34 +08:00
Cleanup and move local serializable classes to top-level
This commit is contained in:
parent
813ef2b1e6
commit
c37457cafb
@ -47,7 +47,7 @@ public annotation class MiraiInternalFile
|
||||
*/
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
|
||||
@Target(CLASS, TYPEALIAS, FUNCTION, PROPERTY, FIELD, CONSTRUCTOR)
|
||||
@Target(CLASS, TYPEALIAS, FUNCTION, PROPERTY, FIELD, CONSTRUCTOR, TYPE)
|
||||
@MustBeDocumented
|
||||
public annotation class MiraiExperimentalApi(
|
||||
public val message: String = ""
|
||||
|
@ -107,20 +107,20 @@ public class DeviceInfo(
|
||||
}
|
||||
}
|
||||
|
||||
public fun DeviceInfo.generateDeviceInfoData(): ByteArray {
|
||||
@Serializable
|
||||
class DevInfo(
|
||||
@ProtoNumber(1) val bootloader: ByteArray,
|
||||
@ProtoNumber(2) val procVersion: ByteArray,
|
||||
@ProtoNumber(3) val codename: ByteArray,
|
||||
@ProtoNumber(4) val incremental: ByteArray,
|
||||
@ProtoNumber(5) val fingerprint: ByteArray,
|
||||
@ProtoNumber(6) val bootId: ByteArray,
|
||||
@ProtoNumber(7) val androidId: ByteArray,
|
||||
@ProtoNumber(8) val baseBand: ByteArray,
|
||||
@ProtoNumber(9) val innerVersion: ByteArray
|
||||
)
|
||||
@Serializable
|
||||
private class DevInfo(
|
||||
@ProtoNumber(1) val bootloader: ByteArray,
|
||||
@ProtoNumber(2) val procVersion: ByteArray,
|
||||
@ProtoNumber(3) val codename: ByteArray,
|
||||
@ProtoNumber(4) val incremental: ByteArray,
|
||||
@ProtoNumber(5) val fingerprint: ByteArray,
|
||||
@ProtoNumber(6) val bootId: ByteArray,
|
||||
@ProtoNumber(7) val androidId: ByteArray,
|
||||
@ProtoNumber(8) val baseBand: ByteArray,
|
||||
@ProtoNumber(9) val innerVersion: ByteArray
|
||||
)
|
||||
|
||||
public fun DeviceInfo.generateDeviceInfoData(): ByteArray {
|
||||
return ProtoBuf.encodeToByteArray(
|
||||
DevInfo.serializer(), DevInfo(
|
||||
bootloader,
|
||||
|
@ -39,7 +39,7 @@ internal data class MarketFaceImpl internal constructor(
|
||||
* For refinement
|
||||
*/
|
||||
internal class MarketFaceInternal(
|
||||
@JvmField private val delegate: ImMsgBody.MarketFace,
|
||||
private val delegate: ImMsgBody.MarketFace,
|
||||
) : MarketFace, RefinableMessage {
|
||||
override val name: String get() = delegate.faceName.decodeToString()
|
||||
override val id: Int get() = delegate.tabId
|
||||
|
@ -93,7 +93,7 @@ internal abstract class AbstractKeepAliveNetworkHandlerSelector<H : NetworkHandl
|
||||
}
|
||||
|
||||
return if (current != null) {
|
||||
when (val thisState = current.state) {
|
||||
when (current.state) {
|
||||
NetworkHandler.State.CLOSED -> {
|
||||
if (this@AbstractKeepAliveNetworkHandlerSelector.current.compareAndSet(current, null)) {
|
||||
// invalidate the instance and try again.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Mamoe Technologies and contributors.
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
@ -51,7 +51,7 @@ internal class LongConn {
|
||||
check(resp.subcmd == 1)
|
||||
val imgRsp = resp.msgTryupImgRsp.first()
|
||||
if (imgRsp.result != 0) {
|
||||
return Response.Failed(imgRsp.failMsg ?: "")
|
||||
return Response.Failed(imgRsp.failMsg)
|
||||
}
|
||||
|
||||
return if (imgRsp.boolFileExit) {
|
||||
|
@ -228,7 +228,7 @@ internal object MessageSvcPbGetMsg : OutgoingPacketFactory<MessageSvcPbGetMsg.Re
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun QQAndroidBot.createGroupForBot(groupUin: Long): Group? {
|
||||
internal suspend fun QQAndroidBot.createGroupForBot(groupUin: Long): Group? {
|
||||
val group = getGroupByUinOrNull(groupUin)
|
||||
if (group != null) {
|
||||
return null
|
||||
|
@ -7,9 +7,6 @@
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
@file:OptIn(JavaFriendlyAPI::class)
|
||||
|
||||
package net.mamoe.mirai.internal.network.protocol.packet.chat.receive
|
||||
|
||||
import kotlinx.coroutines.CancellationException
|
||||
@ -22,8 +19,11 @@ import net.mamoe.mirai.contact.MemberPermission
|
||||
import net.mamoe.mirai.contact.NormalMember
|
||||
import net.mamoe.mirai.event.events.*
|
||||
import net.mamoe.mirai.internal.QQAndroidBot
|
||||
import net.mamoe.mirai.internal.contact.*
|
||||
import net.mamoe.mirai.internal.contact.GroupImpl
|
||||
import net.mamoe.mirai.internal.contact.NormalMemberImpl
|
||||
import net.mamoe.mirai.internal.contact.checkIsMemberImpl
|
||||
import net.mamoe.mirai.internal.contact.info.MemberInfoImpl
|
||||
import net.mamoe.mirai.internal.contact.newMember
|
||||
import net.mamoe.mirai.internal.message.contextualBugReportException
|
||||
import net.mamoe.mirai.internal.network.MultiPacketByIterable
|
||||
import net.mamoe.mirai.internal.network.Packet
|
||||
@ -34,7 +34,8 @@ import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacket
|
||||
import net.mamoe.mirai.internal.network.protocol.packet.buildResponseUniPacket
|
||||
import net.mamoe.mirai.internal.utils._miraiContentToString
|
||||
import net.mamoe.mirai.internal.utils.io.serialization.readProtoBuf
|
||||
import net.mamoe.mirai.utils.*
|
||||
import net.mamoe.mirai.utils.cast
|
||||
import net.mamoe.mirai.utils.read
|
||||
|
||||
|
||||
internal object OnlinePushPbPushTransMsg :
|
||||
|
@ -49,7 +49,6 @@ import net.mamoe.mirai.internal.network.protocol.packet.sendAndExpect
|
||||
import net.mamoe.mirai.internal.utils.*
|
||||
import net.mamoe.mirai.internal.utils.io.ProtoBuf
|
||||
import net.mamoe.mirai.internal.utils.io.serialization.*
|
||||
import net.mamoe.mirai.internal.utils.parseToMessageDataList
|
||||
import net.mamoe.mirai.utils.*
|
||||
|
||||
|
||||
@ -517,6 +516,37 @@ internal inline fun lambda528(crossinline block: suspend MsgType0x210.(QQAndroid
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
private class Wording(
|
||||
@ProtoNumber(1) val itemID: Int = 0,
|
||||
@ProtoNumber(2) val itemName: String = ""
|
||||
) : ProtoBuf
|
||||
|
||||
@Serializable
|
||||
private class Sub8AMsgInfo(
|
||||
@ProtoNumber(1) val fromUin: Long,
|
||||
@ProtoNumber(2) val botUin: Long,
|
||||
@ProtoNumber(3) val srcId: Int,
|
||||
@ProtoNumber(4) val srcInternalId: Long,
|
||||
@ProtoNumber(5) val time: Long,
|
||||
@ProtoNumber(6) val random: Int,
|
||||
@ProtoNumber(7) val pkgNum: Int, // 1
|
||||
@ProtoNumber(8) val pkgIndex: Int, // 0
|
||||
@ProtoNumber(9) val devSeq: Int, // 0
|
||||
@ProtoNumber(12) val flag: Int, // 1
|
||||
@ProtoNumber(13) val wording: Wording
|
||||
) : ProtoBuf
|
||||
|
||||
@Serializable
|
||||
private class Sub8A(
|
||||
@ProtoNumber(1) val msgInfo: List<Sub8AMsgInfo>,
|
||||
@ProtoNumber(2) val appId: Int, // 1
|
||||
@ProtoNumber(3) val instId: Int, // 1
|
||||
@ProtoNumber(4) val longMessageFlag: Int, // 0
|
||||
@ProtoNumber(5) val reserved: ByteArray? = null // struct{ boolean(1), boolean(2) }
|
||||
) : ProtoBuf
|
||||
|
||||
|
||||
// uSubMsgType to vProtobuf
|
||||
// 138 or 139: top_package/akln.java:1568
|
||||
// 66: top_package/nhz.java:269
|
||||
@ -527,35 +557,6 @@ internal inline fun lambda528(crossinline block: suspend MsgType0x210.(QQAndroid
|
||||
internal object Transformers528 : Map<Long, Lambda528> by mapOf(
|
||||
|
||||
0x8AL to lambda528 { bot ->
|
||||
@Serializable
|
||||
class Wording(
|
||||
@ProtoNumber(1) val itemID: Int = 0,
|
||||
@ProtoNumber(2) val itemName: String = ""
|
||||
) : ProtoBuf
|
||||
|
||||
@Serializable
|
||||
class Sub8AMsgInfo(
|
||||
@ProtoNumber(1) val fromUin: Long,
|
||||
@ProtoNumber(2) val botUin: Long,
|
||||
@ProtoNumber(3) val srcId: Int,
|
||||
@ProtoNumber(4) val srcInternalId: Long,
|
||||
@ProtoNumber(5) val time: Long,
|
||||
@ProtoNumber(6) val random: Int,
|
||||
@ProtoNumber(7) val pkgNum: Int, // 1
|
||||
@ProtoNumber(8) val pkgIndex: Int, // 0
|
||||
@ProtoNumber(9) val devSeq: Int, // 0
|
||||
@ProtoNumber(12) val flag: Int, // 1
|
||||
@ProtoNumber(13) val wording: Wording
|
||||
) : ProtoBuf
|
||||
|
||||
@Serializable
|
||||
class Sub8A(
|
||||
@ProtoNumber(1) val msgInfo: List<Sub8AMsgInfo>,
|
||||
@ProtoNumber(2) val appId: Int, // 1
|
||||
@ProtoNumber(3) val instId: Int, // 1
|
||||
@ProtoNumber(4) val longMessageFlag: Int, // 0
|
||||
@ProtoNumber(5) val reserved: ByteArray? = null // struct{ boolean(1), boolean(2) }
|
||||
) : ProtoBuf
|
||||
|
||||
return@lambda528 vProtobuf.loadAs(Sub8A.serializer()).msgInfo.asSequence()
|
||||
.filter { it.botUin == bot.id }.mapNotNull { info ->
|
||||
|
@ -137,7 +137,7 @@ internal class StatSvc {
|
||||
fun online(
|
||||
client: QQAndroidClient,
|
||||
regPushReason: RegPushReason = RegPushReason.appRegister
|
||||
) = impl("online", client, 1 or 2 or 4, client.onlineStatus, regPushReason) {
|
||||
) = impl("online", client, 1L or 2 or 4, client.onlineStatus, regPushReason) {
|
||||
client.bot.components[ContactCacheService].friendListCache?.let { friendListCache: FriendListCache ->
|
||||
iLargeSeq = friendListCache.friendListSeq
|
||||
// timeStamp = friendListCache.timeStamp
|
||||
|
@ -126,25 +126,25 @@ internal class MessageSerializationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class W(
|
||||
val m: FileMessage
|
||||
)
|
||||
|
||||
@Test
|
||||
fun `test FileMessage serialization`() {
|
||||
@Serializable
|
||||
data class W(
|
||||
val m: FileMessage
|
||||
)
|
||||
|
||||
val w = W(FileMessageImpl("id", 2, "name", 1))
|
||||
println(w.serialize(W.serializer()))
|
||||
assertEquals(w, w.serialize(W.serializer()).deserialize(W.serializer()))
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class RichWrapper(
|
||||
val richMessage: RichMessage
|
||||
)
|
||||
|
||||
@Test
|
||||
fun `test polymorphic serialization`() {
|
||||
@Serializable
|
||||
data class RichWrapper(
|
||||
val richMessage: RichMessage
|
||||
)
|
||||
|
||||
val string = format.encodeToString(RichWrapper.serializer(), RichWrapper(SimpleServiceMessage(1, "content")))
|
||||
println(string)
|
||||
var element = format.parseToJsonElement(string)
|
||||
@ -155,13 +155,13 @@ internal class MessageSerializationTest {
|
||||
assertEquals(1, element["serviceId"]?.cast<JsonPrimitive>()?.content?.toInt())
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class Wrapper(
|
||||
val message: @Polymorphic SingleMessage
|
||||
)
|
||||
|
||||
@Test
|
||||
fun `test ShowImageFlag serialization`() {
|
||||
@Serializable
|
||||
data class Wrapper(
|
||||
val message: @Polymorphic SingleMessage
|
||||
)
|
||||
|
||||
val string = format.encodeToString(Wrapper.serializer(), Wrapper(ShowImageFlag))
|
||||
println(string)
|
||||
var element = format.parseToJsonElement(string)
|
||||
|
Loading…
Reference in New Issue
Block a user