mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-12 18:50:20 +08:00
Annotate with MiraiDebugAPI
This commit is contained in:
parent
621809b94b
commit
2052159dc9
@ -2,9 +2,7 @@ package net.mamoe.mirai.utils.io
|
|||||||
|
|
||||||
import kotlinx.io.core.*
|
import kotlinx.io.core.*
|
||||||
import kotlinx.io.pool.useInstance
|
import kotlinx.io.pool.useInstance
|
||||||
import net.mamoe.mirai.utils.DefaultLogger
|
import net.mamoe.mirai.utils.*
|
||||||
import net.mamoe.mirai.utils.MiraiLogger
|
|
||||||
import net.mamoe.mirai.utils.withSwitch
|
|
||||||
import kotlin.contracts.ExperimentalContracts
|
import kotlin.contracts.ExperimentalContracts
|
||||||
import kotlin.contracts.InvocationKind
|
import kotlin.contracts.InvocationKind
|
||||||
import kotlin.contracts.contract
|
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)
|
fun Throwable.logStacktrace(message: String? = null) = DebugLogger.error(message, this)
|
||||||
|
|
||||||
|
@MiraiDebugAPI("Low efficiency.")
|
||||||
fun debugPrintln(any: Any?) = DebugLogger.debug(any)
|
fun debugPrintln(any: Any?) = DebugLogger.debug(any)
|
||||||
|
|
||||||
|
@MiraiDebugAPI("Low efficiency.")
|
||||||
fun String.debugPrint(name: String): String {
|
fun String.debugPrint(name: String): String {
|
||||||
DebugLogger.debug("$name=$this")
|
DebugLogger.debug("$name=$this")
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MiraiDebugAPI("Low efficiency.")
|
||||||
fun ByteArray.debugPrint(name: String): ByteArray {
|
fun ByteArray.debugPrint(name: String): ByteArray {
|
||||||
DebugLogger.debug(name + "=" + this.toUHexString())
|
DebugLogger.debug(name + "=" + this.toUHexString())
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MiraiDebugAPI("Low efficiency.")
|
||||||
fun IoBuffer.debugPrint(name: String): IoBuffer {
|
fun IoBuffer.debugPrint(name: String): IoBuffer {
|
||||||
ByteArrayPool.useInstance {
|
ByteArrayPool.useInstance {
|
||||||
val count = this.readAvailable(it)
|
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 {
|
inline fun IoBuffer.debugCopyUse(block: IoBuffer.() -> Unit): IoBuffer {
|
||||||
ByteArrayPool.useInstance {
|
ByteArrayPool.useInstance {
|
||||||
val count = this.readAvailable(it)
|
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 = "") {
|
fun Input.debugDiscardExact(n: Number, name: String = "") {
|
||||||
DebugLogger.debug("Discarded($n) $name=" + this.readBytes(n.toInt()).toUHexString())
|
DebugLogger.debug("Discarded($n) $name=" + this.readBytes(n.toInt()).toUHexString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MiraiDebugAPI("Low efficiency.")
|
||||||
fun ByteReadPacket.debugPrint(name: String = ""): ByteReadPacket {
|
fun ByteReadPacket.debugPrint(name: String = ""): ByteReadPacket {
|
||||||
ByteArrayPool.useInstance {
|
ByteArrayPool.useInstance {
|
||||||
val count = this.readAvailable(it)
|
val count = this.readAvailable(it)
|
||||||
@ -59,7 +64,7 @@ fun ByteReadPacket.debugPrint(name: String = ""): ByteReadPacket {
|
|||||||
*
|
*
|
||||||
* 此方法非常低效. 请仅在测试环境使用.
|
* 此方法非常低效. 请仅在测试环境使用.
|
||||||
*/
|
*/
|
||||||
@MiraiDebugAPI
|
@MiraiDebugAPI("Low efficiency")
|
||||||
@UseExperimental(ExperimentalContracts::class)
|
@UseExperimental(ExperimentalContracts::class)
|
||||||
inline fun <R> Input.debugIfFail(name: String = "", onFail: (ByteArray) -> ByteReadPacket = { it.toReadPacket() }, block: ByteReadPacket.() -> R): R {
|
inline fun <R> Input.debugIfFail(name: String = "", onFail: (ByteArray) -> ByteReadPacket = { it.toReadPacket() }, block: ByteReadPacket.() -> R): R {
|
||||||
contract {
|
contract {
|
||||||
|
Loading…
Reference in New Issue
Block a user