Extract Serializable.dumpMethodName()
This commit is contained in:
@@ -16,9 +16,9 @@ abstract class Serializable<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fromJsObject(jsObject: any): Serializable<T> {
|
fromJsObject(jsObject: any): Serializable<T> {
|
||||||
let indentation = new Array(Serializable.depth + 1).join(' ');
|
|
||||||
let isArray = this instanceof ClassArray;
|
let isArray = this instanceof ClassArray;
|
||||||
this.dump(`${indentation}${this.constructor.name}.fromJsObject: ${this.strintifyJsObject(jsObject)}` + (isArray ? '\n' : ` => `));
|
this.dumpMethodName('fromJsObject');
|
||||||
|
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--;
|
||||||
@@ -29,9 +29,9 @@ abstract class Serializable<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fromBinary(buffer: UhkBuffer): Serializable<T> {
|
fromBinary(buffer: UhkBuffer): Serializable<T> {
|
||||||
let indentation = new Array(Serializable.depth + 1).join(' ');
|
|
||||||
let isArray = this instanceof ClassArray;
|
let isArray = this instanceof ClassArray;
|
||||||
this.dump(`${indentation}${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);
|
||||||
@@ -44,9 +44,9 @@ abstract class Serializable<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toJsObject(): any {
|
toJsObject(): any {
|
||||||
let indentation = new Array(Serializable.depth + 1).join(' ');
|
|
||||||
let isArray = this instanceof ClassArray;
|
let isArray = this instanceof ClassArray;
|
||||||
this.dump(`${indentation}${this.constructor.name}.toJsObject: ${this}` + (isArray ? '\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--;
|
||||||
@@ -57,9 +57,9 @@ abstract class Serializable<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toBinary(buffer: UhkBuffer): void {
|
toBinary(buffer: UhkBuffer): void {
|
||||||
let indentation = new Array(Serializable.depth + 1).join(' ');
|
|
||||||
let isArray = this instanceof ClassArray;
|
let isArray = this instanceof ClassArray;
|
||||||
this.dump(`${indentation}${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);
|
||||||
@@ -76,9 +76,14 @@ abstract class Serializable<T> {
|
|||||||
abstract _toJsObject(): any;
|
abstract _toJsObject(): any;
|
||||||
abstract _toBinary(buffer: UhkBuffer): void;
|
abstract _toBinary(buffer: UhkBuffer): void;
|
||||||
|
|
||||||
dump(value) {
|
private dump(value) {
|
||||||
if (Serializable.enableDump) {
|
if (Serializable.enableDump) {
|
||||||
process.stdout.write(value);
|
process.stdout.write(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private dumpMethodName(methodName: string) {
|
||||||
|
let indentation = new Array(Serializable.depth + 1).join(' ');
|
||||||
|
this.dump(`${indentation}${this.constructor.name}.${methodName}: `);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user