initial: varing and smarting packing tools

This commit is contained in:
sergeych committed 2023-02-03 13:10:43 +01:00
commit 0f9702b1dc
15 files changed
+914

No files matched your search

@@ -0,0 +1,30 @@
package net.sergeych.bintools
/**
* data input stream-like abstraction. We need it because
* kotlinx serialization is synchronous and there us nothing
* like multiplatform version of DataInput
*
*/
abstract class DataSource {
abstract fun readByte(): Byte
abstract val position: Int
open fun readUByte() = readByte().toUByte()
@Suppress("unused")
open fun readBytes(size: Int): ByteArray =
ByteArray(size).also { a ->
for( i in 0..size)
a[i] = readByte()
}
}
fun ByteArray.toDataSource(): DataSource =
object : DataSource() {
override var position = 0
override fun readByte(): Byte = this@toDataSource[position++]
}