Dump Serializable.toBinary()
This commit is contained in:
@@ -48,7 +48,18 @@ abstract class Serializable<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toBinary(buffer: UhkBuffer): void {
|
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;
|
abstract _fromJsObject(jsObject: any): T;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ class UhkBuffer {
|
|||||||
private static isFirstElementToDump = false;
|
private static isFirstElementToDump = false;
|
||||||
|
|
||||||
offset: number;
|
offset: number;
|
||||||
enableDump = false;
|
private _enableDump = false;
|
||||||
|
|
||||||
private buffer: Buffer;
|
private buffer: Buffer;
|
||||||
private bytesToBacktrack: number;
|
private bytesToBacktrack: number;
|
||||||
@@ -139,6 +139,15 @@ class UhkBuffer {
|
|||||||
return this.buffer.slice(0, this.offset);
|
return this.buffer.slice(0, this.offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get enableDump() {
|
||||||
|
return this._enableDump;
|
||||||
|
}
|
||||||
|
|
||||||
|
set enableDump(value) {
|
||||||
|
UhkBuffer.isFirstElementToDump = true;
|
||||||
|
this._enableDump = value;
|
||||||
|
}
|
||||||
|
|
||||||
dump(value) {
|
dump(value) {
|
||||||
if (this.enableDump) {
|
if (this.enableDump) {
|
||||||
if (!UhkBuffer.isFirstElementToDump) {
|
if (!UhkBuffer.isFirstElementToDump) {
|
||||||
|
|||||||
Reference in New Issue
Block a user