😴 Improve code quality
This commit is contained in:
		@@ -45,26 +45,32 @@ 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 {
 | 
				
			||||||
 | 
					            longValue < 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(longValue)
 | 
					                buffer.putLong(longValue)
 | 
				
			||||||
        } else if (longValue < 0xfd) {
 | 
					            }
 | 
				
			||||||
 | 
					            longValue < 0xfd -> {
 | 
				
			||||||
                buffer.put(value.toByte())
 | 
					                buffer.put(value.toByte())
 | 
				
			||||||
        } else if (longValue <= 0xffffL) {
 | 
					            }
 | 
				
			||||||
 | 
					            longValue <= 0xffffL -> {
 | 
				
			||||||
                buffer.put(0xfd.toByte())
 | 
					                buffer.put(0xfd.toByte())
 | 
				
			||||||
                buffer.putShort(value.toShort())
 | 
					                buffer.putShort(value.toShort())
 | 
				
			||||||
        } else if (longValue <= 0xffffffffL) {
 | 
					            }
 | 
				
			||||||
 | 
					            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(longValue)
 | 
					                buffer.putLong(longValue)
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @JvmStatic
 | 
					    @JvmStatic
 | 
				
			||||||
    fun varInt(value: Number): ByteArray {
 | 
					    fun varInt(value: Number): ByteArray {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user