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
|
typings
|
||||||
uhk-config.bin
|
uhk-config.bin
|
||||||
|
uhk-config-serialized.json
|
||||||
test-serializer.js
|
test-serializer.js
|
||||||
|
|||||||
@@ -4,8 +4,9 @@ class UhkBuffer {
|
|||||||
private static longCompactLengthPrefix = 0xFF;
|
private static longCompactLengthPrefix = 0xFF;
|
||||||
private static stringEncoding = 'utf8';
|
private static stringEncoding = 'utf8';
|
||||||
|
|
||||||
|
offset: number;
|
||||||
|
|
||||||
private buffer: Buffer;
|
private buffer: Buffer;
|
||||||
private offset: number;
|
|
||||||
private bytesToBacktrack: number;
|
private bytesToBacktrack: number;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class KeyActions implements Serializable<KeyActions> {
|
|||||||
toJsObject(): any {
|
toJsObject(): any {
|
||||||
let array = [];
|
let array = [];
|
||||||
for (let keyAction of this.keyActions) {
|
for (let keyAction of this.keyActions) {
|
||||||
keyAction.toJsObject();
|
array.push(keyAction.toJsObject());
|
||||||
}
|
}
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
class NoneAction extends KeyAction implements Serializable<NoneAction> {
|
class NoneAction extends KeyAction implements Serializable<NoneAction> {
|
||||||
|
|
||||||
static noneActionParam = 0;
|
|
||||||
|
|
||||||
fromJsObject(jsObject: any): NoneAction {
|
fromJsObject(jsObject: any): NoneAction {
|
||||||
this.assertKeyActionType(jsObject, KeyActionType.NoneAction, 'NoneAction');
|
this.assertKeyActionType(jsObject, KeyActionType.NoneAction, 'NoneAction');
|
||||||
return this;
|
return this;
|
||||||
@@ -9,12 +7,6 @@ class NoneAction extends KeyAction implements Serializable<NoneAction> {
|
|||||||
|
|
||||||
fromBinary(buffer: UhkBuffer): NoneAction {
|
fromBinary(buffer: UhkBuffer): NoneAction {
|
||||||
this.readAndAssertKeyActionId(buffer, KeyActionId.NoneAction, 'NoneAction');
|
this.readAndAssertKeyActionId(buffer, KeyActionId.NoneAction, 'NoneAction');
|
||||||
|
|
||||||
let keyActionParam = buffer.readUInt8();
|
|
||||||
if (keyActionParam !== NoneAction.noneActionParam) {
|
|
||||||
throw `Invalid NoneAction.param: ${keyActionParam}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,3 +11,6 @@ let keyActions = uhkConfig.keymaps[0].layers[0].modules[0].keyActions;
|
|||||||
let keyActionObjects: KeyActions = new KeyActions().fromJsObject(keyActions);
|
let keyActionObjects: KeyActions = new KeyActions().fromJsObject(keyActions);
|
||||||
keyActionObjects.toBinary(buffer);
|
keyActionObjects.toBinary(buffer);
|
||||||
fs.writeFileSync('uhk-config.bin', buffer.getBufferContent());
|
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