Merge branch 'master' of https://github.com/UltimateHackingKeyboard/agent-mockup
This commit is contained in:
@@ -14,7 +14,6 @@ abstract class ClassArray<T> extends Serializable<T> {
|
|||||||
let arrayLength = buffer.readCompactLength();
|
let arrayLength = buffer.readCompactLength();
|
||||||
|
|
||||||
if (buffer.enableDump) {
|
if (buffer.enableDump) {
|
||||||
process.stdout.write(']\n');
|
|
||||||
buffer.enableDump = false;
|
buffer.enableDump = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +35,6 @@ abstract class ClassArray<T> extends Serializable<T> {
|
|||||||
buffer.writeCompactLength(this.elements.length);
|
buffer.writeCompactLength(this.elements.length);
|
||||||
|
|
||||||
if (buffer.enableDump) {
|
if (buffer.enableDump) {
|
||||||
process.stdout.write(']\n');
|
|
||||||
buffer.enableDump = false;
|
buffer.enableDump = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,58 +5,43 @@ abstract class Serializable<T> {
|
|||||||
private static enableDump = true;
|
private static enableDump = true;
|
||||||
|
|
||||||
fromJsObject(jsObject: any): Serializable<T> {
|
fromJsObject(jsObject: any): Serializable<T> {
|
||||||
let isArray = this instanceof ClassArray;
|
this.dump(`${this.getIndentation()}${this.constructor.name}.fromJsObject: ` +
|
||||||
this.dumpMethodName('fromJsObject');
|
`${this.strintifyJsObject(jsObject)}\n`);
|
||||||
this.dump(`${this.strintifyJsObject(jsObject)}` + (isArray ? '\n' : ` => `));
|
|
||||||
Serializable.depth++;
|
Serializable.depth++;
|
||||||
let value = this._fromJsObject(jsObject);
|
let value = this._fromJsObject(jsObject);
|
||||||
Serializable.depth--;
|
Serializable.depth--;
|
||||||
if (!isArray) {
|
this.dump(`${this.getIndentation()}=> ${value}\n`);
|
||||||
this.dump(`${value}\n`);
|
|
||||||
}
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
fromBinary(buffer: UhkBuffer): Serializable<T> {
|
fromBinary(buffer: UhkBuffer): Serializable<T> {
|
||||||
let isArray = this instanceof ClassArray;
|
this.dump(`\n${this.getIndentation()}${this.constructor.name}.fromBinary: [`);
|
||||||
this.dumpMethodName('fromBinary');
|
|
||||||
this.dump('[');
|
|
||||||
Serializable.depth++;
|
Serializable.depth++;
|
||||||
buffer.enableDump = Serializable.enableDump;
|
buffer.enableDump = Serializable.enableDump;
|
||||||
let value = this._fromBinary(buffer);
|
let value = this._fromBinary(buffer);
|
||||||
buffer.enableDump = false;
|
buffer.enableDump = false;
|
||||||
Serializable.depth--;
|
Serializable.depth--;
|
||||||
if (!isArray) {
|
this.dump(`]\n${this.getIndentation()}=> ${value}`);
|
||||||
this.dump(`] => ${value}\n`);
|
|
||||||
}
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
toJsObject(): any {
|
toJsObject(): any {
|
||||||
let isArray = this instanceof ClassArray;
|
this.dump(`${this.getIndentation()}${this.constructor.name}.toJsObject: ${this}\n`);
|
||||||
this.dumpMethodName('toJsObject');
|
|
||||||
this.dump(`${this}` + (isArray ? '\n' : ` => `));
|
|
||||||
Serializable.depth++;
|
Serializable.depth++;
|
||||||
let value = this._toJsObject();
|
let value = this._toJsObject();
|
||||||
Serializable.depth--;
|
Serializable.depth--;
|
||||||
if (!isArray) {
|
this.dump(`${this.getIndentation()}=> ${this.strintifyJsObject(value)}\n`);
|
||||||
this.dump(`${this.strintifyJsObject(value)}\n`);
|
|
||||||
}
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
toBinary(buffer: UhkBuffer): void {
|
toBinary(buffer: UhkBuffer): void {
|
||||||
let isArray = this instanceof ClassArray;
|
this.dump(`\n${this.getIndentation()}${this.constructor.name}.toBinary: ${this} [`);
|
||||||
this.dumpMethodName('toBinary');
|
|
||||||
this.dump(`${this} => ['`);
|
|
||||||
Serializable.depth++;
|
Serializable.depth++;
|
||||||
buffer.enableDump = Serializable.enableDump;
|
buffer.enableDump = Serializable.enableDump;
|
||||||
let value = this._toBinary(buffer);
|
let value = this._toBinary(buffer);
|
||||||
buffer.enableDump = false;
|
buffer.enableDump = false;
|
||||||
Serializable.depth--;
|
Serializable.depth--;
|
||||||
if (!isArray) {
|
this.dump(`]`);
|
||||||
this.dump(`]\n`);
|
|
||||||
}
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,9 +56,8 @@ abstract class Serializable<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private dumpMethodName(methodName: string) {
|
private getIndentation() {
|
||||||
let indentation = new Array(Serializable.depth + 1).join(' ');
|
return new Array(Serializable.depth + 1).join(' ');
|
||||||
this.dump(`${indentation}${this.constructor.name}.${methodName}: `);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private strintifyJsObject(jsObject: any): string {
|
private strintifyJsObject(jsObject: any): string {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
class UhkBuffer {
|
class UhkBuffer {
|
||||||
|
|
||||||
private static eepromSize = 32 * 1024;
|
private static eepromSize = 32 * 1024;
|
||||||
private static maxCompactLength = 0xFFFF;
|
private static maxCompactLength = 0xFFFF;
|
||||||
private static longCompactLengthPrefix = 0xFF;
|
private static longCompactLengthPrefix = 0xFF;
|
||||||
@@ -156,21 +157,25 @@ class UhkBuffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set enableDump(value) {
|
set enableDump(value) {
|
||||||
UhkBuffer.isFirstElementToDump = true;
|
if (value) {
|
||||||
|
UhkBuffer.isFirstElementToDump = true;
|
||||||
|
}
|
||||||
this._enableDump = value;
|
this._enableDump = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
dump(value) {
|
dump(value) {
|
||||||
if (this.enableDump) {
|
if (!this.enableDump) {
|
||||||
if (!UhkBuffer.isFirstElementToDump) {
|
return;
|
||||||
process.stdout.write(', ');
|
}
|
||||||
}
|
|
||||||
process.stdout.write(value);
|
if (!UhkBuffer.isFirstElementToDump) {
|
||||||
if (UhkBuffer.isFirstElementToDump) {
|
process.stdout.write(', ');
|
||||||
UhkBuffer.isFirstElementToDump = false;
|
}
|
||||||
}
|
|
||||||
} else {
|
process.stdout.write(value);
|
||||||
UhkBuffer.isFirstElementToDump = true;
|
|
||||||
|
if (UhkBuffer.isFirstElementToDump) {
|
||||||
|
UhkBuffer.isFirstElementToDump = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ let keyActions1BufferContent = keyActions1Buffer.getBufferContent();
|
|||||||
fs.writeFileSync('uhk-config.bin', keyActions1BufferContent);
|
fs.writeFileSync('uhk-config.bin', keyActions1BufferContent);
|
||||||
|
|
||||||
keyActions1Buffer.offset = 0;
|
keyActions1Buffer.offset = 0;
|
||||||
|
console.log();
|
||||||
let keyActions2Ts = new KeyActions().fromBinary(keyActions1Buffer);
|
let keyActions2Ts = new KeyActions().fromBinary(keyActions1Buffer);
|
||||||
|
console.log('\n');
|
||||||
let keyActions2Js = keyActions2Ts.toJsObject();
|
let keyActions2Js = keyActions2Ts.toJsObject();
|
||||||
let keyActions2Buffer = new UhkBuffer();
|
let keyActions2Buffer = new UhkBuffer();
|
||||||
keyActions2Ts.toBinary(keyActions2Buffer);
|
keyActions2Ts.toBinary(keyActions2Buffer);
|
||||||
@@ -45,6 +47,7 @@ fs.writeFileSync('uhk-config-serialized.json', JSON.stringify(modules2Js, undefi
|
|||||||
let modules2BufferContent = modules1Buffer.getBufferContent();
|
let modules2BufferContent = modules1Buffer.getBufferContent();
|
||||||
fs.writeFileSync('uhk-config-serialized.bin', modules2BufferContent);
|
fs.writeFileSync('uhk-config-serialized.bin', modules2BufferContent);
|
||||||
|
|
||||||
|
console.log('\n');
|
||||||
try {
|
try {
|
||||||
/* wanted to also compare class->json & class->binary->class->json with original json */
|
/* wanted to also compare class->json & class->binary->class->json with original json */
|
||||||
assert.deepEqual(modulesbaseJs, modules1Js);
|
assert.deepEqual(modulesbaseJs, modules1Js);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
|
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 63 KiB |
File diff suppressed because it is too large
Load Diff
|
Before Width: | Height: | Size: 84 KiB After Width: | Height: | Size: 91 KiB |
Reference in New Issue
Block a user