fix proto

This commit is contained in:
Simplxs 2023-10-27 17:32:02 +08:00
parent 617874fea1
commit 85cb9d221c
No known key found for this signature in database
GPG Key ID: E23537FF14DD6507
3 changed files with 9 additions and 7 deletions

View File

@ -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()
}

View File

@ -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 {

View File

@ -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
}