0.0.7: oendOfData support, correct decoding with default values past it
This commit is contained in:
1 parent
06f8bc7ef2
commit
47b450c597
5 files changed
+34
-5
No files matched your search
@@ -16,6 +16,12 @@ interface DataSource {
|
||||
|
||||
fun readByte(): Byte
|
||||
|
||||
/**
|
||||
* true if there is no more data available and next read operation will surely
|
||||
* throw EndOfData. Can return null if it is impossible to determine (for some
|
||||
* async sources)
|
||||
*/
|
||||
fun isEnd(): Boolean? = null
|
||||
|
||||
fun readUByte() = readByte().toUByte()
|
||||
|
||||
@@ -50,6 +56,9 @@ fun ByteArray.toDataSource(): DataSource =
|
||||
var position = 0
|
||||
private set
|
||||
|
||||
@Suppress("RedundantNullableReturnType")
|
||||
override fun isEnd(): Boolean? = position == size
|
||||
|
||||
override fun readByte(): Byte =
|
||||
if (position < size) this@toDataSource[position++]
|
||||
else throw DataSource.EndOfData()
|
||||
@@ -65,6 +74,9 @@ fun UByteArray.toDataSource(): DataSource =
|
||||
var position = 0
|
||||
private set
|
||||
|
||||
@Suppress("RedundantNullableReturnType")
|
||||
override fun isEnd(): Boolean? = position == size
|
||||
|
||||
override fun readByte(): Byte =
|
||||
if (position < size) this@toDataSource[position++].toByte()
|
||||
else throw DataSource.EndOfData()
|
||||
|
||||
Reference in new issue
Block a user