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
ef7dd73d
Commit
ef7dd73d
authored
Nov 25, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add debug functions
parent
9145eeb4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
22 deletions
+26
-22
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/Proto.kt
...core/src/commonMain/kotlin/net.mamoe.mirai/utils/Proto.kt
+24
-22
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/io/DebugUtil.kt
...c/commonMain/kotlin/net.mamoe.mirai/utils/io/DebugUtil.kt
+2
-0
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/Proto.kt
View file @
ef7dd73d
...
@@ -6,10 +6,7 @@ import kotlinx.io.core.ByteReadPacket
...
@@ -6,10 +6,7 @@ import kotlinx.io.core.ByteReadPacket
import
kotlinx.io.core.readBytes
import
kotlinx.io.core.readBytes
import
kotlinx.io.core.readUInt
import
kotlinx.io.core.readUInt
import
kotlinx.io.core.readULong
import
kotlinx.io.core.readULong
import
net.mamoe.mirai.utils.io.UVarInt
import
net.mamoe.mirai.utils.io.*
import
net.mamoe.mirai.utils.io.readUVarInt
import
net.mamoe.mirai.utils.io.toReadPacket
import
net.mamoe.mirai.utils.io.toUHexString
import
kotlin.jvm.JvmStatic
import
kotlin.jvm.JvmStatic
// ProtoBuf utilities
// ProtoBuf utilities
...
@@ -143,29 +140,34 @@ fun ByteReadPacket.readProtoMap(length: Long = this.remaining): ProtoMap {
...
@@ -143,29 +140,34 @@ fun ByteReadPacket.readProtoMap(length: Long = this.remaining): ProtoMap {
while
(
this
.
remaining
!=
expectingRemaining
)
{
while
(
this
.
remaining
!=
expectingRemaining
)
{
require
(
this
.
remaining
>
expectingRemaining
)
{
"Expecting to read $length bytes, but read ${expectingRemaining + length - this.remaining}"
}
require
(
this
.
remaining
>
expectingRemaining
)
{
"Expecting to read $length bytes, but read ${expectingRemaining + length - this.remaining}"
}
val
id
=
ProtoFieldId
(
readUVarInt
())
try
{
val
id
=
ProtoFieldId
(
readUVarInt
())
fun
readValue
():
Any
=
when
(
id
.
type
)
{
fun
readValue
():
Any
=
when
(
id
.
type
)
{
ProtoType
.
VAR_INT
->
UVarInt
(
readUVarInt
())
ProtoType
.
VAR_INT
->
UVarInt
(
readUVarInt
())
ProtoType
.
BIT_32
->
readUInt
()
ProtoType
.
BIT_32
->
readUInt
()
ProtoType
.
BIT_64
->
readULong
()
ProtoType
.
BIT_64
->
readULong
()
ProtoType
.
LENGTH_DELIMI
->
tryReadProtoMapOrByteArray
(
readUVarInt
().
toInt
())
ProtoType
.
LENGTH_DELIMI
->
tryReadProtoMapOrByteArray
(
readUVarInt
().
toInt
())
ProtoType
.
START_GROUP
->
Unit
ProtoType
.
START_GROUP
->
Unit
ProtoType
.
END_GROUP
->
Unit
ProtoType
.
END_GROUP
->
Unit
}
}
if
(
map
.
containsKey
(
id
))
{
if
(
map
.
containsKey
(
id
))
{
if
(
map
[
id
]
is
MutableList
<
*
>)
{
if
(
map
[
id
]
is
MutableList
<
*
>)
{
@Suppress
(
"UNCHECKED_CAST"
)
@Suppress
(
"UNCHECKED_CAST"
)
(
map
[
id
]
as
MutableList
<
Any
>)
+=
readValue
()
(
map
[
id
]
as
MutableList
<
Any
>)
+=
readValue
()
}
else
{
map
[
id
]
=
mutableListOf
(
map
[
id
]
!!
)
@Suppress
(
"UNCHECKED_CAST"
)
(
map
[
id
]
as
MutableList
<
Any
>)
+=
readValue
()
}
}
else
{
}
else
{
map
[
id
]
=
mutableListOf
(
map
[
id
]
!!
)
map
[
id
]
=
readValue
()
@Suppress
(
"UNCHECKED_CAST"
)
(
map
[
id
]
as
MutableList
<
Any
>)
+=
readValue
()
}
}
}
else
{
}
catch
(
e
:
IllegalStateException
)
{
map
[
id
]
=
readValue
()
e
.
logStacktrace
()
return
map
}
}
}
}
return
map
return
map
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/io/DebugUtil.kt
View file @
ef7dd73d
...
@@ -10,6 +10,8 @@ import net.mamoe.mirai.utils.internal.printCompareHex
...
@@ -10,6 +10,8 @@ import net.mamoe.mirai.utils.internal.printCompareHex
internal
object
DebugLogger
:
MiraiLogger
by
DefaultLogger
(
"Packet Debug"
)
internal
object
DebugLogger
:
MiraiLogger
by
DefaultLogger
(
"Packet Debug"
)
internal
fun
Throwable
.
logStacktrace
(
message
:
String
?
=
null
)
=
DebugLogger
.
error
(
message
,
this
)
internal
fun
debugPrintln
(
any
:
Any
?)
=
DebugLogger
.
debug
(
any
)
internal
fun
debugPrintln
(
any
:
Any
?)
=
DebugLogger
.
debug
(
any
)
@Deprecated
(
"Low efficiency, only for debug purpose"
,
ReplaceWith
(
"this"
))
@Deprecated
(
"Low efficiency, only for debug purpose"
,
ReplaceWith
(
"this"
))
...
...
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