initial: varing and smarting packing tools
This commit is contained in:
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++]
|
||||
}
|
||||
Reference in new issue
Block a user