Extract Serializable.dumpMethodName()

This commit is contained in:
László Monda
2016-04-08 01:04:08 +02:00
parent 56aa1982b1
commit ccab8f0be2

View File

@@ -16,9 +16,9 @@ abstract class Serializable<T> {
}
fromJsObject(jsObject: any): Serializable<T> {
let indentation = new Array(Serializable.depth + 1).join(' ');
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++;
let value = this._fromJsObject(jsObject);
Serializable.depth--;
@@ -29,9 +29,9 @@ abstract class Serializable<T> {
}
fromBinary(buffer: UhkBuffer): Serializable<T> {
let indentation = new Array(Serializable.depth + 1).join(' ');
let isArray = this instanceof ClassArray;
this.dump(`${indentation}${this.constructor.name}.fromBinary: [`);
this.dumpMethodName('fromBinary');
this.dump('[');
Serializable.depth++;
buffer.enableDump = Serializable.enableDump;
let value = this._fromBinary(buffer);
@@ -44,9 +44,9 @@ abstract class Serializable<T> {
}
toJsObject(): any {
let indentation = new Array(Serializable.depth + 1).join(' ');
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++;
let value = this._toJsObject();
Serializable.depth--;
@@ -57,9 +57,9 @@ abstract class Serializable<T> {
}
toBinary(buffer: UhkBuffer): void {
let indentation = new Array(Serializable.depth + 1).join(' ');
let isArray = this instanceof ClassArray;
this.dump(`${indentation}${this.constructor.name}.toBinary: ${this} => ['`);
this.dumpMethodName('toBinary');
this.dump(`${this} => ['`);
Serializable.depth++;
buffer.enableDump = Serializable.enableDump;
let value = this._toBinary(buffer);
@@ -76,9 +76,14 @@ abstract class Serializable<T> {
abstract _toJsObject(): any;
abstract _toBinary(buffer: UhkBuffer): void;
dump(value) {
private dump(value) {
if (Serializable.enableDump) {
process.stdout.write(value);
}
}
private dumpMethodName(methodName: string) {
let indentation = new Array(Serializable.depth + 1).join(' ');
this.dump(`${indentation}${this.constructor.name}.${methodName}: `);
}
}