optimization: ise varint on field counter for extendable format (it's rare for a struct to have so many fields so smartint will be better).

This commit is contained in:
sergeych committed 2023-03-15 09:51:54 +01:00
1 parent e556d4bc3d
commit 149a0e1850
6 files changed
+23 -10

No files matched your search

@@ -22,6 +22,11 @@ interface DataSink {
fun writeBytes(data: ByteArray) {
for(d in data) writeByte(d)
}
fun writeVarUInt(value: UInt) { Varint.encodeUnsigned(value.toULong())}
fun writeVarInt(value: UInt) { Varint.encodeSigned(value.toLong())}
fun writeSmartUInt(value: UInt) { Smartint.encodeUnsigned(value.toULong())}
fun writeSmartInt(value: UInt) { Smartint.encodeSigned(value.toLong())}
}
inline fun <reified T:Any>DataSink.writeNumber(value: T) {
@@ -34,6 +34,14 @@ interface DataSource {
fun readFloat() = Float.fromBits(readI32()).toFloat()
fun readSmartUInt(): UInt = Smartint.decodeUnsigned(this).toUInt()
fun readSmartInt(): Int = Smartint.decodeSigned(this).toInt()
fun readVarUInt(): UInt = Varint.decodeUnsigned(this).toUInt()
fun readVarInt(): Int = Varint.decodeSigned(this).toInt()
}
fun ByteArray.toDataSource(): DataSource =