Dump buffer operations in a nicer and more compact way.
This commit is contained in:
@@ -22,7 +22,7 @@ abstract class Serializable<T> {
|
|||||||
fromBinary(buffer: UhkBuffer): T {
|
fromBinary(buffer: UhkBuffer): T {
|
||||||
let indentation = new Array(Serializable.depth + 1).join(' ');
|
let indentation = new Array(Serializable.depth + 1).join(' ');
|
||||||
let isArray = this instanceof UhkArray;
|
let isArray = this instanceof UhkArray;
|
||||||
process.stdout.write(`${indentation}${this.constructor.name}.fromBinary: `);
|
process.stdout.write(`${indentation}${this.constructor.name}.fromBinary: [`);
|
||||||
if (isArray) {
|
if (isArray) {
|
||||||
process.stdout.write('\n');
|
process.stdout.write('\n');
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ abstract class Serializable<T> {
|
|||||||
buffer.enableDump = false;
|
buffer.enableDump = false;
|
||||||
Serializable.depth--;
|
Serializable.depth--;
|
||||||
if (!isArray) {
|
if (!isArray) {
|
||||||
process.stdout.write(`=> ${value}\n`);
|
process.stdout.write(`] => ${value}\n`);
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ class UhkBuffer {
|
|||||||
private static maxCompactLength = 0xFFFF;
|
private static maxCompactLength = 0xFFFF;
|
||||||
private static longCompactLengthPrefix = 0xFF;
|
private static longCompactLengthPrefix = 0xFF;
|
||||||
private static stringEncoding = 'utf8';
|
private static stringEncoding = 'utf8';
|
||||||
|
private static isFirstElementToDump = false;
|
||||||
|
|
||||||
offset: number;
|
offset: number;
|
||||||
enableDump = false;
|
enableDump = false;
|
||||||
@@ -33,14 +34,14 @@ class UhkBuffer {
|
|||||||
let value = this.buffer.readUInt8(this.offset);
|
let value = this.buffer.readUInt8(this.offset);
|
||||||
this.bytesToBacktrack = 1;
|
this.bytesToBacktrack = 1;
|
||||||
this.offset += this.bytesToBacktrack;
|
this.offset += this.bytesToBacktrack;
|
||||||
this.dump(`uint8(${value}) `);
|
this.dump(`u8(${value})`);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
writeUInt8(value: number): void {
|
writeUInt8(value: number): void {
|
||||||
this.buffer.writeUInt8(value, this.offset);
|
this.buffer.writeUInt8(value, this.offset);
|
||||||
this.offset += 1;
|
this.offset += 1;
|
||||||
this.dump(`uint8(${value}) `);
|
this.dump(`u8(${value})`);
|
||||||
}
|
}
|
||||||
|
|
||||||
readInt16(): number {
|
readInt16(): number {
|
||||||
@@ -140,7 +141,15 @@ class UhkBuffer {
|
|||||||
|
|
||||||
dump(value) {
|
dump(value) {
|
||||||
if (this.enableDump) {
|
if (this.enableDump) {
|
||||||
|
if (!UhkBuffer.isFirstElementToDump) {
|
||||||
|
process.stdout.write(' ');
|
||||||
|
}
|
||||||
process.stdout.write(value);
|
process.stdout.write(value);
|
||||||
|
if (UhkBuffer.isFirstElementToDump) {
|
||||||
|
UhkBuffer.isFirstElementToDump = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
UhkBuffer.isFirstElementToDump = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user