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) {
|
fun write(buff: FriendlyByteBuf) {
|
||||||
val whole = whole.toByteArray()
|
val whole = whole.toByteArray()
|
||||||
buff.writeByte(whole.size)
|
buff.writeByteArray(whole)
|
||||||
buff.writeBytes(whole)
|
buff.writeDouble(decimal)
|
||||||
buff.writeBytes(longToBytesBE(decimal.toBits()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toFloat(): Float {
|
override fun toFloat(): Float {
|
||||||
@ -635,14 +634,7 @@ class ImpreciseFraction @JvmOverloads constructor(whole: BigInteger, decimal: Do
|
|||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun read(buff: FriendlyByteBuf): ImpreciseFraction {
|
fun read(buff: FriendlyByteBuf): ImpreciseFraction {
|
||||||
val len = unsignedInt(buff.readByte())
|
return ImpreciseFraction(BigInteger(buff.readByteArray()), buff.readDouble())
|
||||||
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))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user