Use buffer functions to read parts of imprecise fraction
This commit is contained in:
parent
51fa3a012c
commit
a5ca7af63e
@ -500,9 +500,8 @@ class ImpreciseFraction @JvmOverloads constructor(whole: BigInteger, decimal: Do
|
||||
|
||||
fun write(buff: FriendlyByteBuf) {
|
||||
val whole = whole.toByteArray()
|
||||
buff.writeByte(whole.size)
|
||||
buff.writeBytes(whole)
|
||||
buff.writeBytes(longToBytesBE(decimal.toBits()))
|
||||
buff.writeByteArray(whole)
|
||||
buff.writeDouble(decimal)
|
||||
}
|
||||
|
||||
override fun toFloat(): Float {
|
||||
@ -635,14 +634,7 @@ class ImpreciseFraction @JvmOverloads constructor(whole: BigInteger, decimal: Do
|
||||
|
||||
@JvmStatic
|
||||
fun read(buff: FriendlyByteBuf): ImpreciseFraction {
|
||||
val len = unsignedInt(buff.readByte())
|
||||
val slice = ByteArray(len)
|
||||
|
||||
for (i in 0 until len)
|
||||
slice[i] = buff.readByte()
|
||||
|
||||
val bits = bytesToLongBE(buff.readByte(), buff.readByte(), buff.readByte(), buff.readByte(), buff.readByte(), buff.readByte(), buff.readByte(), buff.readByte())
|
||||
return ImpreciseFraction(BigInteger(slice), Double.fromBits(bits))
|
||||
return ImpreciseFraction(BigInteger(buff.readByteArray()), buff.readDouble())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user