refs #35 bits in BitArray/input/output reordered for better performance; started typed serialization
This commit is contained in:
1 parent
7aee25ffef
commit
cffe4eaffc
13 files changed
+312
-60
No files matched your search
@@ -0,0 +1,35 @@
|
||||
package net.sergeych.lynon
|
||||
|
||||
import net.sergeych.lyng.Scope
|
||||
import net.sergeych.lyng.obj.Obj
|
||||
import net.sergeych.lyng.obj.ObjBuffer
|
||||
import net.sergeych.lyng.obj.ObjClass
|
||||
import net.sergeych.lyng.obj.ObjString
|
||||
|
||||
// Most often used types:
|
||||
|
||||
|
||||
val ObjLynonClass = object : ObjClass("Lynon") {
|
||||
|
||||
suspend fun Scope.encodeAny(obj: Obj): Obj {
|
||||
val bout = MemoryBitOutput()
|
||||
val serializer = LynonEncoder(bout)
|
||||
serializer.encodeAny(this, obj)
|
||||
return ObjBuffer(bout.toBitArray().bytes)
|
||||
}
|
||||
|
||||
suspend fun Scope.decodeAny(buffer: ObjBuffer): Obj {
|
||||
val bin = BitArray(buffer.byteArray,8).toInput()
|
||||
val deserializer = LynonDecoder(bin)
|
||||
return deserializer.decodeAny(this)
|
||||
}
|
||||
|
||||
}.apply {
|
||||
addClassConst("test", ObjString("test_const"))
|
||||
addClassFn("encode") {
|
||||
encodeAny(requireOnlyArg<Obj>())
|
||||
}
|
||||
addClassFn("decode") {
|
||||
decodeAny(requireOnlyArg<ObjBuffer>())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user