Dump Serializable.toBinary()

This commit is contained in:
László Monda
2016-04-03 19:18:01 +02:00
parent b0b7a642a4
commit 5c4e9d5912
2 changed files with 22 additions and 2 deletions

View File

@@ -48,7 +48,18 @@ abstract class Serializable<T> {
}
toBinary(buffer: UhkBuffer): void {
this._toBinary(buffer);
let indentation = new Array(Serializable.depth + 1).join(' ');
let isArray = this instanceof UhkArray;
process.stdout.write(`${indentation}${this.constructor.name}.fromBinary: ${this}` + (isArray ? '\n' : ' => ['));
Serializable.depth++;
buffer.enableDump = !isArray;
let value = this._toBinary(buffer);
buffer.enableDump = false;
Serializable.depth--;
if (!isArray) {
process.stdout.write(`]\n`);
}
return value;
}
abstract _fromJsObject(jsObject: any): T;

View File

@@ -6,7 +6,7 @@ class UhkBuffer {
private static isFirstElementToDump = false;
offset: number;
enableDump = false;
private _enableDump = false;
private buffer: Buffer;
private bytesToBacktrack: number;
@@ -139,6 +139,15 @@ class UhkBuffer {
return this.buffer.slice(0, this.offset);
}
get enableDump() {
return this._enableDump;
}
set enableDump(value) {
UhkBuffer.isFirstElementToDump = true;
this._enableDump = value;
}
dump(value) {
if (this.enableDump) {
if (!UhkBuffer.isFirstElementToDump) {