Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
2052159d
Commit
2052159d
authored
Jan 20, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Annotate with MiraiDebugAPI
parent
621809b9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
4 deletions
+9
-4
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/io/DebugUtil.kt
...c/commonMain/kotlin/net.mamoe.mirai/utils/io/DebugUtil.kt
+9
-4
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/io/DebugUtil.kt
View file @
2052159d
...
@@ -2,9 +2,7 @@ package net.mamoe.mirai.utils.io
...
@@ -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()
...
@@ -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 {
...
@@ -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 {
...
@@ -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 {
...
@@ -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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment