Fix structure end reading

This commit is contained in:
Him188 2020-01-30 23:00:09 +08:00
parent db7d0e8372
commit 432a8690b1
2 changed files with 7 additions and 4 deletions

View File

@ -308,10 +308,10 @@ class Jce private constructor(private val charset: JceCharset, context: SerialMo
input: JceInput
) : JceDecoder(input) {
override fun endStructure(desc: SerialDescriptor) {
while (input.peakHead().type != STRUCT_END) {
input.readHead()
while (input.input.canRead() && input.peakHeadOrNull()?.type != STRUCT_END) {
input.readHeadOrNull() ?: return
}
input.readHead()
input.readHeadOrNull()
}
}
@ -513,6 +513,9 @@ class Jce private constructor(private val charset: JceCharset, context: SerialMo
@PublishedApi
internal fun peakHead(): JceHead = input.makeView().readHead() ?: error("no enough data to read head")
@PublishedApi
internal fun peakHeadOrNull(): JceHead? = input.makeView().readHead()
@Suppress("NOTHING_TO_INLINE") // 避免 stacktrace 出现两个 readHead
private inline fun IoBuffer.readHead(): JceHead? {
if (endOfInput) return null

View File

@ -349,7 +349,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
// 不要 `withTimeout`. timeout 的异常会不知道去哪了.
} ?: net.mamoe.mirai.qqandroid.utils.inline {
packetListeners.remove(handler)
error("timeout when sending $commandName")
error("timeout when receiving response of $commandName")
}
}