Annotate with MiraiDebugAPI

This commit is contained in:
Him188 2020-01-20 20:56:43 +08:00
parent 621809b94b
commit 2052159dc9

View File

@ -2,9 +2,7 @@ package net.mamoe.mirai.utils.io
import kotlinx.io.core.*
import kotlinx.io.pool.useInstance
import net.mamoe.mirai.utils.DefaultLogger
import net.mamoe.mirai.utils.MiraiLogger
import net.mamoe.mirai.utils.withSwitch
import net.mamoe.mirai.utils.*
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
@ -14,18 +12,22 @@ object DebugLogger : MiraiLogger by DefaultLogger("Packet Debug").withSwitch()
fun Throwable.logStacktrace(message: String? = null) = DebugLogger.error(message, this)
@MiraiDebugAPI("Low efficiency.")
fun debugPrintln(any: Any?) = DebugLogger.debug(any)
@MiraiDebugAPI("Low efficiency.")
fun String.debugPrint(name: String): String {
DebugLogger.debug("$name=$this")
return this
}
@MiraiDebugAPI("Low efficiency.")
fun ByteArray.debugPrint(name: String): ByteArray {
DebugLogger.debug(name + "=" + this.toUHexString())
return this
}
@MiraiDebugAPI("Low efficiency.")
fun IoBuffer.debugPrint(name: String): IoBuffer {
ByteArrayPool.useInstance {
val count = this.readAvailable(it)
@ -34,6 +36,7 @@ fun IoBuffer.debugPrint(name: String): IoBuffer {
}
}
@MiraiDebugAPI("Low efficiency.")
inline fun IoBuffer.debugCopyUse(block: IoBuffer.() -> Unit): IoBuffer {
ByteArrayPool.useInstance {
val count = this.readAvailable(it)
@ -42,10 +45,12 @@ inline fun IoBuffer.debugCopyUse(block: IoBuffer.() -> Unit): IoBuffer {
}
}
@MiraiDebugAPI("Low efficiency.")
fun Input.debugDiscardExact(n: Number, name: String = "") {
DebugLogger.debug("Discarded($n) $name=" + this.readBytes(n.toInt()).toUHexString())
}
@MiraiDebugAPI("Low efficiency.")
fun ByteReadPacket.debugPrint(name: String = ""): ByteReadPacket {
ByteArrayPool.useInstance {
val count = this.readAvailable(it)
@ -59,7 +64,7 @@ fun ByteReadPacket.debugPrint(name: String = ""): ByteReadPacket {
*
* 此方法非常低效. 请仅在测试环境使用.
*/
@MiraiDebugAPI
@MiraiDebugAPI("Low efficiency")
@UseExperimental(ExperimentalContracts::class)
inline fun <R> Input.debugIfFail(name: String = "", onFail: (ByteArray) -> ByteReadPacket = { it.toReadPacket() }, block: ByteReadPacket.() -> R): R {
contract {