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
|
val ProtoValue.asByteArray: ByteArray
|
||||||
get() = if (this is ProtoMap) {
|
get() = if (this is ProtoMap) {
|
||||||
toByteArray()
|
bytes?.toByteArray() ?: toByteArray()
|
||||||
} else {
|
} else {
|
||||||
(this as ProtoByteString).toByteArray()
|
(this as ProtoByteString).toByteArray()
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,11 @@ import kotlinx.serialization.json.JsonElement
|
|||||||
import moe.fuqiuluo.shamrock.tools.jsonObject
|
import moe.fuqiuluo.shamrock.tools.jsonObject
|
||||||
|
|
||||||
class ProtoMap(
|
class ProtoMap(
|
||||||
val value: HashMap<Int, ProtoValue>
|
val value: HashMap<Int, ProtoValue>,
|
||||||
|
val bytes: ByteString?
|
||||||
): ProtoValue {
|
): ProtoValue {
|
||||||
constructor(): this(hashMapOf())
|
constructor(): this(hashMapOf(), null)
|
||||||
|
constructor(value: HashMap<Int, ProtoValue>): this(value, null)
|
||||||
|
|
||||||
override fun has(vararg tags: Int): Boolean {
|
override fun has(vararg tags: Int): Boolean {
|
||||||
var curMap: ProtoMap = this
|
var curMap: ProtoMap = this
|
||||||
@ -83,7 +85,7 @@ class ProtoMap(
|
|||||||
return@forEachIndexed
|
return@forEachIndexed
|
||||||
}
|
}
|
||||||
if (!curProtoMap.contains(tag)) {
|
if (!curProtoMap.contains(tag)) {
|
||||||
val tmp = ProtoMap(hashMapOf())
|
val tmp = ProtoMap()
|
||||||
curProtoMap[tag] = tmp
|
curProtoMap[tag] = tmp
|
||||||
curProtoMap = tmp
|
curProtoMap = tmp
|
||||||
} else {
|
} else {
|
||||||
|
@ -7,7 +7,7 @@ import com.google.protobuf.UnknownFieldSet
|
|||||||
object ProtoUtils {
|
object ProtoUtils {
|
||||||
fun decodeFromByteArray(data: ByteArray): ProtoMap {
|
fun decodeFromByteArray(data: ByteArray): ProtoMap {
|
||||||
val unknownFieldSet = UnknownFieldSet.parseFrom(data)
|
val unknownFieldSet = UnknownFieldSet.parseFrom(data)
|
||||||
val dest = ProtoMap(hashMapOf())
|
val dest = ProtoMap(hashMapOf(), ByteString.copyFrom(data))
|
||||||
printUnknownFieldSet(unknownFieldSet, dest)
|
printUnknownFieldSet(unknownFieldSet, dest)
|
||||||
return dest
|
return dest
|
||||||
}
|
}
|
||||||
@ -97,7 +97,7 @@ object ProtoUtils {
|
|||||||
field.lengthDelimitedList.forEach {
|
field.lengthDelimitedList.forEach {
|
||||||
try {
|
try {
|
||||||
val unknownFieldSet = UnknownFieldSet.parseFrom(it)
|
val unknownFieldSet = UnknownFieldSet.parseFrom(it)
|
||||||
val map = ProtoMap(hashMapOf())
|
val map = ProtoMap(hashMapOf(), it)
|
||||||
printUnknownFieldSet(unknownFieldSet, map)
|
printUnknownFieldSet(unknownFieldSet, map)
|
||||||
dest[tag] = map
|
dest[tag] = map
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
@ -105,7 +105,7 @@ object ProtoUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
field.groupList.forEach {
|
field.groupList.forEach {
|
||||||
val map = ProtoMap(hashMapOf())
|
val map = ProtoMap()
|
||||||
printUnknownFieldSet(it, map)
|
printUnknownFieldSet(it, map)
|
||||||
dest[tag] = map
|
dest[tag] = map
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user