Make test-serializer.ts serialize and deserialize the configuration.

This commit is contained in:
László Monda
2016-04-01 18:15:04 +02:00
parent 3840d0a623
commit d775a3db3c
5 changed files with 7 additions and 10 deletions

View File

@@ -1,3 +1,4 @@
typings
uhk-config.bin
uhk-config-serialized.json
test-serializer.js

View File

@@ -4,8 +4,9 @@ class UhkBuffer {
private static longCompactLengthPrefix = 0xFF;
private static stringEncoding = 'utf8';
offset: number;
private buffer: Buffer;
private offset: number;
private bytesToBacktrack: number;
constructor() {

View File

@@ -20,7 +20,7 @@ class KeyActions implements Serializable<KeyActions> {
toJsObject(): any {
let array = [];
for (let keyAction of this.keyActions) {
keyAction.toJsObject();
array.push(keyAction.toJsObject());
}
return array;
}

View File

@@ -1,7 +1,5 @@
class NoneAction extends KeyAction implements Serializable<NoneAction> {
static noneActionParam = 0;
fromJsObject(jsObject: any): NoneAction {
this.assertKeyActionType(jsObject, KeyActionType.NoneAction, 'NoneAction');
return this;
@@ -9,12 +7,6 @@ class NoneAction extends KeyAction implements Serializable<NoneAction> {
fromBinary(buffer: UhkBuffer): NoneAction {
this.readAndAssertKeyActionId(buffer, KeyActionId.NoneAction, 'NoneAction');
let keyActionParam = buffer.readUInt8();
if (keyActionParam !== NoneAction.noneActionParam) {
throw `Invalid NoneAction.param: ${keyActionParam}`;
}
return this;
}

View File

@@ -11,3 +11,6 @@ let keyActions = uhkConfig.keymaps[0].layers[0].modules[0].keyActions;
let keyActionObjects: KeyActions = new KeyActions().fromJsObject(keyActions);
keyActionObjects.toBinary(buffer);
fs.writeFileSync('uhk-config.bin', buffer.getBufferContent());
buffer.offset = 0;
let serializedKeyActions = JSON.stringify(new KeyActions().fromBinary(buffer).toJsObject(), undefined, 4);
fs.writeFileSync('uhk-config-serialized.json', serializedKeyActions);