Fix writeJson and readJson trying to correct negative numbers, when writeVarLong already does this
This commit is contained in:
parent
09db4ad9e9
commit
ddc3850722
@ -149,18 +149,6 @@ private const val TYPE_STRING = 0x05
|
|||||||
private const val TYPE_ARRAY = 0x06
|
private const val TYPE_ARRAY = 0x06
|
||||||
private const val TYPE_OBJECT = 0x07
|
private const val TYPE_OBJECT = 0x07
|
||||||
|
|
||||||
private fun fixSignedInt(read: Long): Long {
|
|
||||||
val sign = read and 0x1L
|
|
||||||
@Suppress("name_shadowing")
|
|
||||||
val read = read ushr 1
|
|
||||||
|
|
||||||
if (sign == 1L) {
|
|
||||||
return -read - 1L
|
|
||||||
} else {
|
|
||||||
return read
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes binary json to stream in Starbound Object Notation format
|
* Writes binary json to stream in Starbound Object Notation format
|
||||||
*
|
*
|
||||||
@ -186,17 +174,9 @@ fun OutputStream.writeJson(element: JsonElement) {
|
|||||||
if (element.isNumber) {
|
if (element.isNumber) {
|
||||||
val num = element.asNumber
|
val num = element.asNumber
|
||||||
|
|
||||||
if (num is Int || num is Long) {
|
if (num is Int || num is Long || num is Short || num is Byte) {
|
||||||
write(TYPE_INT)
|
write(TYPE_INT)
|
||||||
var int = num.toLong()
|
writeVarLongLE(num.toLong())
|
||||||
|
|
||||||
if (int < 0) {
|
|
||||||
int = int.absoluteValue.shl(1).or(1)
|
|
||||||
} else {
|
|
||||||
int.shl(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
writeVarLongLE(int)
|
|
||||||
} else if (num is Float || num is Double) {
|
} else if (num is Float || num is Double) {
|
||||||
write(TYPE_DOUBLE)
|
write(TYPE_DOUBLE)
|
||||||
writeDouble(num.toDouble())
|
writeDouble(num.toDouble())
|
||||||
@ -237,7 +217,7 @@ fun InputStream.readJson(sizeLimit: NbtAccounter = NbtAccounter(1L shl 18 /* 256
|
|||||||
sizeLimit.accountBytes(1L)
|
sizeLimit.accountBytes(1L)
|
||||||
JsonPrimitive(read() > 1)
|
JsonPrimitive(read() > 1)
|
||||||
}
|
}
|
||||||
TYPE_INT -> JsonPrimitive(fixSignedInt(readVarLongLE(sizeLimit)))
|
TYPE_INT -> JsonPrimitive(readVarLongLE(sizeLimit))
|
||||||
TYPE_STRING -> JsonPrimitive(readBinaryString(sizeLimit))
|
TYPE_STRING -> JsonPrimitive(readBinaryString(sizeLimit))
|
||||||
TYPE_ARRAY -> {
|
TYPE_ARRAY -> {
|
||||||
val values = readVarIntLE(sizeLimit)
|
val values = readVarIntLE(sizeLimit)
|
||||||
|
Loading…
Reference in New Issue
Block a user