Skip to content

Commit

Permalink
提供几个快捷方法
Browse files Browse the repository at this point in the history
  • Loading branch information
fuqiuluo committed Sep 3, 2023
1 parent 7c98547 commit af08214
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/main/kotlin/moe/fuqiuluo/proto2json/Proto.kt
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ val Proto.asString: ByteString
val Proto.asNumber: Number
get() = (this as ProtoNumber).value

val Proto.asInt: Int
get() = (this as ProtoNumber).value.toInt()

val Proto.asLong: Long
get() = (this as ProtoNumber).value.toLong()

val Proto.asMap: ProtoMap
get() = (this as ProtoMap)

Expand Down
6 changes: 3 additions & 3 deletions src/test/kotlin/net/oicq/parse_pb_3.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ fun main() {


val face = obj[2].asList.first { elem ->
elem.asMap.let { 53 in it && it[53, 1].asNumber.toInt() == 33 }
elem.asMap.let { 53 in it && it[53, 1].asInt == 33 }
}
println("表情ID: " + face.asMap[53, 2, 1].asNumber)
println("表情简介: " + face.asMap[53, 2, 2].asUtf8String)
println("表情ID: " + face[53, 2, 1].asInt)
println("表情简介: " + face[53, 2, 2].asUtf8String)
}

0 comments on commit af08214

Please sign in to comment.