😴 Improve code quality
This commit is contained in:
parent
ce86ab55c3
commit
7b9694e660
@ -45,24 +45,30 @@ object Encode {
|
|||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun varInt(value: Number, buffer: ByteBuffer) {
|
fun varInt(value: Number, buffer: ByteBuffer) {
|
||||||
val longValue = value.toLong()
|
val longValue = value.toLong()
|
||||||
if (longValue < 0) {
|
when {
|
||||||
// This is due to the fact that Java doesn't really support unsigned values.
|
longValue < 0 -> {
|
||||||
// Please be aware that this might be an error due to a smaller negative value being cast to long.
|
// This is due to the fact that Java doesn't really support unsigned values.
|
||||||
// Normally, negative values shouldn't occur within the protocol, and longs large enough for being
|
// Please be aware that this might be an error due to a smaller negative value being cast to long.
|
||||||
// recognized as negatives aren't realistic.
|
// Normally, negative values shouldn't occur within the protocol, and longs large enough for being
|
||||||
buffer.put(0xff.toByte())
|
// recognized as negatives aren't realistic.
|
||||||
buffer.putLong(longValue)
|
buffer.put(0xff.toByte())
|
||||||
} else if (longValue < 0xfd) {
|
buffer.putLong(longValue)
|
||||||
buffer.put(value.toByte())
|
}
|
||||||
} else if (longValue <= 0xffffL) {
|
longValue < 0xfd -> {
|
||||||
buffer.put(0xfd.toByte())
|
buffer.put(value.toByte())
|
||||||
buffer.putShort(value.toShort())
|
}
|
||||||
} else if (longValue <= 0xffffffffL) {
|
longValue <= 0xffffL -> {
|
||||||
buffer.put(0xfe.toByte())
|
buffer.put(0xfd.toByte())
|
||||||
buffer.putInt(value.toInt())
|
buffer.putShort(value.toShort())
|
||||||
} else {
|
}
|
||||||
buffer.put(0xff.toByte())
|
longValue <= 0xffffffffL -> {
|
||||||
buffer.putLong(longValue)
|
buffer.put(0xfe.toByte())
|
||||||
|
buffer.putInt(value.toInt())
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
buffer.put(0xff.toByte())
|
||||||
|
buffer.putLong(longValue)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user