Add easy serialization to String

This commit is contained in:
Vladimir Grichina
2019-01-11 13:11:55 -08:00
parent 2f5e74136e
commit 9b13c7c5ee
2 changed files with 7 additions and 1 deletions

View File

@ -16,6 +16,10 @@ export class JSONEncoder {
return buffer.subarray(0, buffer.length - 1); return buffer.subarray(0, buffer.length - 1);
} }
toString(): String {
return this.result;
}
setString(name: string, value: string): void { setString(name: string, value: string): void {
this.writeKey(name); this.writeKey(name);
this.writeString(value); this.writeString(value);

View File

@ -104,7 +104,9 @@ export class StringConversionTests {
let resultBuffer = this.handler.serialize(); let resultBuffer = this.handler.serialize();
let resultString = String.fromUTF8(resultBuffer.buffer.data, resultBuffer.length); let resultString = String.fromUTF8(resultBuffer.buffer.data, resultBuffer.length);
assert(resultString == expectedString, assert(resultString == expectedString,
"Expected:\n" + expectedString + "\n" + "Actual:\n" + resultString) "Expected:\n" + expectedString + "\n" + "Actual:\n" + resultString);
assert(this.handler.toString() == expectedString,
"Expected:\n" + expectedString + "\n" + "Actual:\n" + resultString);
return true; return true;
} }
} }