example of array problem
This commit is contained in:
@@ -5,6 +5,7 @@ abstract class ClassArray<T> extends Serializable<T> {
|
|||||||
_fromJsObject(jsObjects: any): Serializable<T> {
|
_fromJsObject(jsObjects: any): Serializable<T> {
|
||||||
for (let jsObject of jsObjects) {
|
for (let jsObject of jsObjects) {
|
||||||
this.elements.push(this.jsObjectToClass(jsObject));
|
this.elements.push(this.jsObjectToClass(jsObject));
|
||||||
|
console.log("Elements: " + this.elements);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,13 @@ class Module extends Serializable<Module> {
|
|||||||
keyActions: Serializable<KeyActions>;
|
keyActions: Serializable<KeyActions>;
|
||||||
|
|
||||||
_fromJsObject(jsObject: any): Module {
|
_fromJsObject(jsObject: any): Module {
|
||||||
this.moduleId = jsObject.id;
|
this.moduleId = jsObject.moduleId;
|
||||||
this.role = PointerRole[<string> jsObject.pointerRole];
|
this.role = PointerRole[<string> jsObject.pointerRole];
|
||||||
this.keyActions = new KeyActions().fromJsObject(jsObject.keyActions);
|
this.keyActions = new KeyActions().fromJsObject(jsObject.keyActions);
|
||||||
|
/*
|
||||||
|
console.log("ModuleId: "+this.moduleId);
|
||||||
|
console.log("PointerRole:"+PointerRole[this.role]);
|
||||||
|
*/
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,7 +34,7 @@ class Module extends Serializable<Module> {
|
|||||||
|
|
||||||
_toJsObject(): any {
|
_toJsObject(): any {
|
||||||
return {
|
return {
|
||||||
id: this.moduleId,
|
moduleId: this.moduleId,
|
||||||
pointerRole: PointerRole[this.role],
|
pointerRole: PointerRole[this.role],
|
||||||
keyActions: this.keyActions.toJsObject()
|
keyActions: this.keyActions.toJsObject()
|
||||||
}
|
}
|
||||||
@@ -43,7 +47,7 @@ class Module extends Serializable<Module> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toString(): string {
|
toString(): string {
|
||||||
return `<Module id="${this.moduleId}">`;
|
return `<Module moduleId="${this.moduleId}" role="${this.role}">`;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ let assert = require('assert');
|
|||||||
let fs = require('fs');
|
let fs = require('fs');
|
||||||
|
|
||||||
let uhkConfig = JSON.parse(fs.readFileSync('uhk-config.json'));
|
let uhkConfig = JSON.parse(fs.readFileSync('uhk-config.json'));
|
||||||
|
/*
|
||||||
let keyActions1Js = uhkConfig.keymaps[0].layers[0].modules[0].keyActions;
|
let keyActions1Js = uhkConfig.keymaps[0].layers[0].modules[0].keyActions;
|
||||||
let keyActions1Ts: Serializable<KeyActions> = new KeyActions().fromJsObject(keyActions1Js);
|
let keyActions1Ts: Serializable<KeyActions> = new KeyActions().fromJsObject(keyActions1Js);
|
||||||
let keyActions1Buffer = new UhkBuffer();
|
let keyActions1Buffer = new UhkBuffer();
|
||||||
@@ -25,13 +25,34 @@ keyActions2Ts.toBinary(keyActions2Buffer);
|
|||||||
fs.writeFileSync('uhk-config-serialized.json', JSON.stringify(keyActions2Js, undefined, 4));
|
fs.writeFileSync('uhk-config-serialized.json', JSON.stringify(keyActions2Js, undefined, 4));
|
||||||
let keyActions2BufferContent = keyActions1Buffer.getBufferContent();
|
let keyActions2BufferContent = keyActions1Buffer.getBufferContent();
|
||||||
fs.writeFileSync('uhk-config-serialized.bin', keyActions2BufferContent);
|
fs.writeFileSync('uhk-config-serialized.bin', keyActions2BufferContent);
|
||||||
|
*/
|
||||||
|
|
||||||
|
let modulesbaseJs = uhkConfig.keymaps[0].layers[0].modules;
|
||||||
|
let modules1Ts: Serializable<Modules> = new Modules().fromJsObject(modulesbaseJs);
|
||||||
|
let modules1Js = modules1Ts.toJsObject();
|
||||||
|
let modules1Buffer = new UhkBuffer();
|
||||||
|
modules1Ts.toBinary(modules1Buffer);
|
||||||
|
let modules1BufferContent = modules1Buffer.getBufferContent();
|
||||||
|
fs.writeFileSync('uhk-config.bin', modules1BufferContent);
|
||||||
|
fs.writeFileSync('uhk-config-test.json',JSON.stringify(modules1Js,undefined,4));
|
||||||
|
|
||||||
|
modules1Buffer.offset = 0;
|
||||||
|
let modules2Ts = new Modules().fromBinary(modules1Buffer);
|
||||||
|
let modules2Js = modules2Ts.toJsObject();
|
||||||
|
let modules2Buffer = new UhkBuffer();
|
||||||
|
modules2Ts.toBinary(modules2Buffer);
|
||||||
|
fs.writeFileSync('uhk-config-serialized.json', JSON.stringify(modules2Js, undefined, 4));
|
||||||
|
let modules2BufferContent = modules1Buffer.getBufferContent();
|
||||||
|
fs.writeFileSync('uhk-config-serialized.bin', modules2BufferContent);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
assert.deepEqual(keyActions1Js, keyActions2Js);
|
/* wanted to also compare class->json & class->binary->class->json with original json */
|
||||||
|
assert.deepEqual(modulesbaseJs, modules1Js);
|
||||||
|
assert.deepEqual(modules1Js, modules2Js);
|
||||||
console.log('JSON configurations are identical.');
|
console.log('JSON configurations are identical.');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('JSON configurations differ.');
|
console.log('JSON configurations differ.');
|
||||||
}
|
}
|
||||||
|
|
||||||
let buffersContentsAreEqual = Buffer.compare(keyActions1BufferContent, keyActions2BufferContent) === 0;
|
let buffersContentsAreEqual = Buffer.compare(modules1BufferContent, modules2BufferContent) === 0;
|
||||||
console.log('Binary configurations ' + (buffersContentsAreEqual ? 'are identical' : 'differ') + '.');
|
console.log('Binary configurations ' + (buffersContentsAreEqual ? 'are identical' : 'differ') + '.');
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
{
|
{
|
||||||
"modules": [
|
"modules": [
|
||||||
{
|
{
|
||||||
"id": 0,
|
"moduleId": 0,
|
||||||
"pointerRole": "move",
|
"pointerRole": "move",
|
||||||
"keyActions": [
|
"keyActions": [
|
||||||
{
|
{
|
||||||
@@ -32,10 +32,18 @@
|
|||||||
"keyActionType": "keystroke",
|
"keyActionType": "keystroke",
|
||||||
"scancode": 110
|
"scancode": 110
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"keyActionType": "keystroke",
|
||||||
|
"scancode": 87
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"keyActionType": "keystrokeModifiers",
|
"keyActionType": "keystrokeModifiers",
|
||||||
"modifierMask":33
|
"modifierMask":33
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"keyActionType": "keystroke",
|
||||||
|
"scancode": 97
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"keyActionType": "keystrokeWithModifiers",
|
"keyActionType": "keystrokeWithModifiers",
|
||||||
"scancode": 120,
|
"scancode": 120,
|
||||||
@@ -66,13 +74,13 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 1,
|
"moduleId": 1,
|
||||||
"pointerRole": "scroll",
|
"pointerRole": "scroll",
|
||||||
"keyActions": []
|
"keyActions": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 2,
|
"moduleId": 2,
|
||||||
"pointerRole": "move",
|
"pointerRole": "none",
|
||||||
"keyActions": []
|
"keyActions": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user