From 69532e0e577bcfb540bf4bea65895eff265127eb Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 14 Dec 2019 21:27:24 +0800 Subject: [PATCH] Add internal ByteReadPacket.debugPrintIfFail --- .../kotlin/net.mamoe.mirai/utils/io/DebugUtil.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/io/DebugUtil.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/io/DebugUtil.kt index 253c2c8dc..1f1e3770f 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/io/DebugUtil.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/io/DebugUtil.kt @@ -54,6 +54,17 @@ internal fun ByteReadPacket.debugPrint(name: String = ""): ByteReadPacket { return bytes.toReadPacket() } +@Deprecated("Low efficiency, only for debug purpose", ReplaceWith("this")) +internal inline fun ByteReadPacket.debugPrintIfFail(name: String = "", block: ByteReadPacket.() -> R): R { + val bytes = this.readBytes() + try { + return block(bytes.toReadPacket()) + } catch (e: Throwable) { + DebugLogger.debug("Error in ByteReadPacket $name=" + bytes.toUHexString()) + throw e + } +} + @Deprecated("Low efficiency, only for debug purpose", ReplaceWith("this")) internal fun ByteReadPacket.debugColorizedPrint(name: String = "", ignoreUntilFirstConst: Boolean = false): ByteReadPacket { val bytes = this.readBytes()