fixed bugs in types, added more tests
This commit is contained in:
1 parent
0e8f3daf99
commit
0b1cd2d9cf
5 files changed
+70
-14
No files matched your search
@@ -13,7 +13,7 @@ interface DataSource {
|
||||
/**
|
||||
* Exception that implementations must throw on end of data
|
||||
*/
|
||||
class EndOfData: Exception("no more data available")
|
||||
class EndOfData : Exception("no more data available")
|
||||
|
||||
fun readByte(): Byte
|
||||
|
||||
@@ -32,6 +32,7 @@ interface DataSource {
|
||||
fun readI64(): Long = bytesToLong(readBytes(8))
|
||||
|
||||
fun readDouble() = Double.fromBits(readI64())
|
||||
|
||||
fun readFloat() = Float.fromBits(readI32())
|
||||
|
||||
}
|
||||
@@ -42,11 +43,11 @@ fun ByteArray.toDataSource(): DataSource =
|
||||
private set
|
||||
|
||||
override fun readByte(): Byte =
|
||||
if( position < size ) this@toDataSource[position++]
|
||||
else throw DataSource.EndOfData()
|
||||
if (position < size) this@toDataSource[position++]
|
||||
else throw DataSource.EndOfData()
|
||||
}
|
||||
|
||||
inline fun <reified T : Any> DataSource.readNumber(): T = when(typeOf<T>()) {
|
||||
inline fun <reified T : Any> DataSource.readNumber(): T = when (typeOf<T>()) {
|
||||
typeOf<Double>() -> readDouble() as T
|
||||
typeOf<Float>() -> readFloat() as T
|
||||
else -> Smartint.decode(this)
|
||||
|
||||
Reference in new issue
Block a user