refactored ./src/types/path-set (#84)

Refactored PathSet, Path, and Hop types. Constructing these types with Buffers, and using class instead of makeClass.
This commit is contained in:
Nathan Nichols
2020-07-13 16:35:08 -05:00
parent ba04ea5f1f
commit 51ad4e36fc
9 changed files with 330 additions and 178 deletions

View File

@@ -16,6 +16,16 @@ class BinaryParser {
this.bytes = Buffer.from(hexBytes, "hex");
}
/**
* Peek the first byte of the BinaryParser
*
* @returns The first byte of the BinaryParser
*/
peek(): number {
assert(this.bytes.byteLength !== 0);
return this.bytes[0];
}
/**
* Consume the first n bytes of the BinaryParser
*
@@ -33,7 +43,10 @@ class BinaryParser {
* @return The bytes
*/
read(n: number): Buffer {
assert(n <= this.bytes.byteLength, n + " greater than " + this.bytes.byteLength);
assert(
n <= this.bytes.byteLength,
n + " greater than " + this.bytes.byteLength
);
const slice = this.bytes.slice(0, n);
this.skip(n);