From e04021425a2b6571eb6920db6c1a2fa60f14ee79 Mon Sep 17 00:00:00 2001 From: Niklas Kapelle Date: Fri, 19 Apr 2024 13:00:13 +0200 Subject: [PATCH] added native serialization for kv store available as a flag: kv_use_native --- src/lib/KVStore.hx | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/lib/KVStore.hx b/src/lib/KVStore.hx index 40afb56..2237caa 100644 --- a/src/lib/KVStore.hx +++ b/src/lib/KVStore.hx @@ -1,12 +1,17 @@ package lib; -import haxe.Serializer; -import haxe.Unserializer; import kernel.fs.FS; import haxe.ds.StringMap; +#if kv_use_native +import cc.TextUtils; +#else +import haxe.Unserializer; +import haxe.Serializer; +#end /** Key value store with persistence. + Use flag kv_use_native to use the cc serialization. **/ class KVStore { private var kvStore:StringMap = new StringMap(); @@ -43,14 +48,21 @@ class KVStore { public function save() { var handle = FS.openWrite(getNamespaceFile(this.namespace)); + #if kv_use_native + handle.write(TextUtils.serialize(this.kvStore)); + #else handle.write(Serializer.run(this.kvStore)); - + #end handle.close(); } private function parseFile(content:String) { + #if kv_use_native + this.kvStore = TextUtils.unserialize(content); + #else var unserializer = new Unserializer(content); this.kvStore = unserializer.unserialize(); + #end } public inline function set(key:String, value:Dynamic) {