🔥 Remove unnecessary methods
This commit is contained in:
parent
cbebc38579
commit
25e118b88e
@ -43,36 +43,31 @@ object Encode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun varInt(value: Int, buffer: ByteBuffer) = varInt(value.toLong(), buffer)
|
fun varInt(value: Number, buffer: ByteBuffer) {
|
||||||
|
val longValue = value.toLong()
|
||||||
@JvmStatic
|
if (longValue < 0) {
|
||||||
fun varInt(value: Long, buffer: ByteBuffer) {
|
|
||||||
if (value < 0) {
|
|
||||||
// This is due to the fact that Java doesn't really support unsigned values.
|
// This is due to the fact that Java doesn't really support unsigned values.
|
||||||
// Please be aware that this might be an error due to a smaller negative value being cast to long.
|
// Please be aware that this might be an error due to a smaller negative value being cast to long.
|
||||||
// Normally, negative values shouldn't occur within the protocol, and longs large enough for being
|
// Normally, negative values shouldn't occur within the protocol, and longs large enough for being
|
||||||
// recognized as negatives aren't realistic.
|
// recognized as negatives aren't realistic.
|
||||||
buffer.put(0xff.toByte())
|
buffer.put(0xff.toByte())
|
||||||
buffer.putLong(value)
|
buffer.putLong(longValue)
|
||||||
} else if (value < 0xfd) {
|
} else if (longValue < 0xfd) {
|
||||||
buffer.put(value.toByte())
|
buffer.put(value.toByte())
|
||||||
} else if (value <= 0xffffL) {
|
} else if (longValue <= 0xffffL) {
|
||||||
buffer.put(0xfd.toByte())
|
buffer.put(0xfd.toByte())
|
||||||
buffer.putShort(value.toShort())
|
buffer.putShort(value.toShort())
|
||||||
} else if (value <= 0xffffffffL) {
|
} else if (longValue <= 0xffffffffL) {
|
||||||
buffer.put(0xfe.toByte())
|
buffer.put(0xfe.toByte())
|
||||||
buffer.putInt(value.toInt())
|
buffer.putInt(value.toInt())
|
||||||
} else {
|
} else {
|
||||||
buffer.put(0xff.toByte())
|
buffer.put(0xff.toByte())
|
||||||
buffer.putLong(value)
|
buffer.putLong(longValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun varInt(value: Int) = varInt(value.toLong())
|
fun varInt(value: Number): ByteArray {
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun varInt(value: Long): ByteArray {
|
|
||||||
val buffer = ByteBuffer.allocate(9)
|
val buffer = ByteBuffer.allocate(9)
|
||||||
varInt(value, buffer)
|
varInt(value, buffer)
|
||||||
buffer.flip()
|
buffer.flip()
|
||||||
@ -81,11 +76,7 @@ object Encode {
|
|||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun varInt(value: Int, stream: OutputStream, counter: AccessCounter? = null) = varInt(value.toLong(), stream, counter)
|
fun varInt(value: Number, stream: OutputStream, counter: AccessCounter? = null) {
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
@JvmOverloads
|
|
||||||
fun varInt(value: Long, stream: OutputStream, counter: AccessCounter? = null) {
|
|
||||||
val buffer = ByteBuffer.allocate(9)
|
val buffer = ByteBuffer.allocate(9)
|
||||||
varInt(value, buffer)
|
varInt(value, buffer)
|
||||||
buffer.flip()
|
buffer.flip()
|
||||||
@ -95,70 +86,45 @@ object Encode {
|
|||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun int8(value: Long, stream: OutputStream, counter: AccessCounter? = null) = int8(value.toInt(), stream, counter)
|
fun int8(value: Number, stream: OutputStream, counter: AccessCounter? = null) {
|
||||||
|
stream.write(value.toInt())
|
||||||
@JvmStatic
|
|
||||||
@JvmOverloads
|
|
||||||
fun int8(value: Int, stream: OutputStream, counter: AccessCounter? = null) {
|
|
||||||
stream.write(value)
|
|
||||||
AccessCounter.inc(counter)
|
AccessCounter.inc(counter)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun int16(value: Long, stream: OutputStream, counter: AccessCounter? = null) = int16(value.toShort(), stream, counter)
|
fun int16(value: Number, stream: OutputStream, counter: AccessCounter? = null) {
|
||||||
|
stream.write(ByteBuffer.allocate(2).putShort(value.toShort()).array())
|
||||||
@JvmStatic
|
|
||||||
@JvmOverloads
|
|
||||||
fun int16(value: Int, stream: OutputStream, counter: AccessCounter? = null) = int16(value.toShort(), stream, counter)
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
@JvmOverloads
|
|
||||||
fun int16(value: Short, stream: OutputStream, counter: AccessCounter? = null) {
|
|
||||||
stream.write(ByteBuffer.allocate(2).putShort(value).array())
|
|
||||||
AccessCounter.inc(counter, 2)
|
AccessCounter.inc(counter, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun int16(value: Long, buffer: ByteBuffer) = int16(value.toShort(), buffer)
|
fun int16(value: Number, buffer: ByteBuffer) {
|
||||||
|
buffer.putShort(value.toShort())
|
||||||
@JvmStatic
|
|
||||||
fun int16(value: Int, buffer: ByteBuffer) = int16(value.toShort(), buffer)
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun int16(value: Short, buffer: ByteBuffer) {
|
|
||||||
buffer.putShort(value)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun int32(value: Long, stream: OutputStream, counter: AccessCounter? = null) = int32(value.toInt(), stream, counter)
|
fun int32(value: Number, stream: OutputStream, counter: AccessCounter? = null) {
|
||||||
|
stream.write(ByteBuffer.allocate(4).putInt(value.toInt()).array())
|
||||||
@JvmStatic
|
|
||||||
@JvmOverloads
|
|
||||||
fun int32(value: Int, stream: OutputStream, counter: AccessCounter? = null) {
|
|
||||||
stream.write(ByteBuffer.allocate(4).putInt(value).array())
|
|
||||||
AccessCounter.inc(counter, 4)
|
AccessCounter.inc(counter, 4)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun int32(value: Long, buffer: ByteBuffer) = int32(value.toInt(), buffer)
|
fun int32(value: Number, buffer: ByteBuffer) {
|
||||||
|
buffer.putInt(value.toInt())
|
||||||
@JvmStatic
|
|
||||||
fun int32(value: Int, buffer: ByteBuffer) {
|
|
||||||
buffer.putInt(value)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun int64(value: Long, stream: OutputStream, counter: AccessCounter? = null) {
|
fun int64(value: Number, stream: OutputStream, counter: AccessCounter? = null) {
|
||||||
stream.write(ByteBuffer.allocate(8).putLong(value).array())
|
stream.write(ByteBuffer.allocate(8).putLong(value.toLong()).array())
|
||||||
AccessCounter.inc(counter, 8)
|
AccessCounter.inc(counter, 8)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun int64(value: Long, buffer: ByteBuffer) {
|
fun int64(value: Number, buffer: ByteBuffer) {
|
||||||
buffer.putLong(value)
|
buffer.putLong(value.toLong())
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
Loading…
Reference in New Issue
Block a user