Make test-serializer.ts serialize and deserialize the configuration.
This commit is contained in:
1
config-serializer/.gitignore
vendored
1
config-serializer/.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
typings
|
||||
uhk-config.bin
|
||||
uhk-config-serialized.json
|
||||
test-serializer.js
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user