mirror of
https://github.com/whitechi73/OpenShamrock.git
synced 2024-08-14 13:12:17 +08:00
fix proto
This commit is contained in:
parent
617874fea1
commit
85cb9d221c
@ -60,7 +60,7 @@ val ProtoValue.asList: ProtoList
|
||||
|
||||
val ProtoValue.asByteArray: ByteArray
|
||||
get() = if (this is ProtoMap) {
|
||||
toByteArray()
|
||||
bytes?.toByteArray() ?: toByteArray()
|
||||
} else {
|
||||
(this as ProtoByteString).toByteArray()
|
||||
}
|
||||
|
@ -7,9 +7,11 @@ import kotlinx.serialization.json.JsonElement
|
||||
import moe.fuqiuluo.shamrock.tools.jsonObject
|
||||
|
||||
class ProtoMap(
|
||||
val value: HashMap<Int, ProtoValue>
|
||||
val value: HashMap<Int, ProtoValue>,
|
||||
val bytes: ByteString?
|
||||
): ProtoValue {
|
||||
constructor(): this(hashMapOf())
|
||||
constructor(): this(hashMapOf(), null)
|
||||
constructor(value: HashMap<Int, ProtoValue>): this(value, null)
|
||||
|
||||
override fun has(vararg tags: Int): Boolean {
|
||||
var curMap: ProtoMap = this
|
||||
@ -83,7 +85,7 @@ class ProtoMap(
|
||||
return@forEachIndexed
|
||||
}
|
||||
if (!curProtoMap.contains(tag)) {
|
||||
val tmp = ProtoMap(hashMapOf())
|
||||
val tmp = ProtoMap()
|
||||
curProtoMap[tag] = tmp
|
||||
curProtoMap = tmp
|
||||
} else {
|
||||
|
@ -7,7 +7,7 @@ import com.google.protobuf.UnknownFieldSet
|
||||
object ProtoUtils {
|
||||
fun decodeFromByteArray(data: ByteArray): ProtoMap {
|
||||
val unknownFieldSet = UnknownFieldSet.parseFrom(data)
|
||||
val dest = ProtoMap(hashMapOf())
|
||||
val dest = ProtoMap(hashMapOf(), ByteString.copyFrom(data))
|
||||
printUnknownFieldSet(unknownFieldSet, dest)
|
||||
return dest
|
||||
}
|
||||
@ -97,7 +97,7 @@ object ProtoUtils {
|
||||
field.lengthDelimitedList.forEach {
|
||||
try {
|
||||
val unknownFieldSet = UnknownFieldSet.parseFrom(it)
|
||||
val map = ProtoMap(hashMapOf())
|
||||
val map = ProtoMap(hashMapOf(), it)
|
||||
printUnknownFieldSet(unknownFieldSet, map)
|
||||
dest[tag] = map
|
||||
} catch (e: Throwable) {
|
||||
@ -105,7 +105,7 @@ object ProtoUtils {
|
||||
}
|
||||
}
|
||||
field.groupList.forEach {
|
||||
val map = ProtoMap(hashMapOf())
|
||||
val map = ProtoMap()
|
||||
printUnknownFieldSet(it, map)
|
||||
dest[tag] = map
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user