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
05a0bc64
Commit
05a0bc64
authored
Jan 11, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add doc
parent
d7f67e51
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
1 deletion
+17
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/cryptor/Proto.kt
.../commonMain/kotlin/net.mamoe.mirai/utils/cryptor/Proto.kt
+17
-1
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/cryptor/Proto.kt
View file @
05a0bc64
...
...
@@ -117,10 +117,24 @@ class ProtoMap(map: MutableMap<ProtoFieldId, Any>) : MutableMap<ProtoFieldId, An
}*/
}
/**
* 将所有元素加入转换为多行的字符串表示.
*/
fun
<
T
>
Sequence
<
T
>.
joinToStringPrefixed
(
prefix
:
String
,
transform
:
(
T
)
->
CharSequence
):
String
{
return
this
.
joinToString
(
prefix
=
"$prefix${ProtoMap.indent}"
,
separator
=
"\n$prefix${ProtoMap.indent}"
,
transform
=
transform
)
}
/**
* 将内容格式化为较可读的字符串输出.
*
* 各数字类型极其无符号类型: 十六进制表示 + 十进制表示. e.g. `0x1000(4096)`
* [ByteArray] 和 [UByteaArray]: 十六进制表示, 通过 [ByteArray.toUHexString]
* [ProtoMap]: 调用 [ProtoMap.toStringPrefixed]
* [Iterable], [Iterator], [Sequence]: 调用各自的 joinToString.
* [Map]: 多行输出. 每行显示一个值. 递归调用 [contentToString]. 嵌套结构将会以缩进表示
* `data class`: 调用其 [toString]
* 其他类型: 反射获取它和它的所有来自 Mirai 的 super 类型的所有自有属性并递归调用 [contentToString]. 嵌套结构将会以缩进表示
*/
fun
Any
?.
contentToString
(
prefix
:
String
=
""
):
String
=
when
(
this
)
{
is
Unit
->
"Unit"
is
UInt
->
"0x"
+
this
.
toUHexString
(
""
)
+
"($this)"
...
...
@@ -146,7 +160,9 @@ fun Any?.contentToString(prefix: String = ""): String = when (this) {
}
is
ProtoMap
->
"ProtoMap(size=$size){\n"
+
this
.
toStringPrefixed
(
"$prefix${ProtoMap.indent}${ProtoMap.indent}"
)
+
"\n$prefix${ProtoMap.indent}}"
is
Collection
<
*
>
->
this
.
joinToString
(
prefix
=
"["
,
postfix
=
"]"
)
{
it
.
contentToString
()
}
is
Iterable
<
*
>
->
this
.
joinToString
(
prefix
=
"["
,
postfix
=
"]"
)
{
it
.
contentToString
()
}
is
Iterator
<
*
>
->
this
.
asSequence
().
joinToString
(
prefix
=
"["
,
postfix
=
"]"
)
{
it
.
contentToString
()
}
is
Sequence
<
*
>
->
this
.
joinToString
(
prefix
=
"["
,
postfix
=
"]"
)
{
it
.
contentToString
()
}
is
Map
<
*
,
*
>
->
this
.
entries
.
joinToString
(
prefix
=
"{"
,
postfix
=
"}"
)
{
it
.
key
.
contentToString
()
+
"="
+
it
.
value
.
contentToString
()
}
else
->
{
if
(
this
==
null
)
"null"
...
...
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