Skip to content

Commit

Permalink
chore: fix based on comment
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSun90 committed Oct 18, 2023
1 parent 4dd82bd commit 0435a78
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/value-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const NULL = (1 << 16) - 1;
const MAX = (1 << 16) - 1;
const THREE_AND_A_THIRD = 3 + (1 / 3);
const MONEY_DIVISOR = 10000;
const PLP_NULL = Buffer.from([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
const UNKNOWN_PLP_LEN = Buffer.from([0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
const PLP_NULL = 0xFFFFFFFFFFFFFFFFn;
const UNKNOWN_PLP_LEN = 0xFFFFFFFFFFFFFFFEn;
const DEFAULT_ENCODING = 'utf8';

function readTinyInt(buf: Buffer, offset: number): Result<number> {
Expand Down Expand Up @@ -589,10 +589,11 @@ async function readPLPStream(parser: Parser): Promise<null | Buffer[]> {
await parser.waitForChunk();

Check warning on line 589 in src/value-parser.ts

View check run for this annotation

Codecov / codecov/patch

src/value-parser.ts#L589

Added line #L589 was not covered by tests
}

const type = parser.buffer.slice(parser.position, parser.position + 8);
const expectedLength = parser.buffer.readBigUInt64LE(parser.position)

Check failure on line 592 in src/value-parser.ts

View workflow job for this annotation

GitHub Actions / Linting

Missing semicolon

parser.position += 8;

if (type.equals(PLP_NULL)) {
if (expectedLength === PLP_NULL) {
return null;
}

Expand Down Expand Up @@ -620,9 +621,8 @@ async function readPLPStream(parser: Parser): Promise<null | Buffer[]> {
currentLength += chunkLength;
}

if (!type.equals(UNKNOWN_PLP_LEN)) {
const expectedLength = Number(type.readBigUInt64LE());
if (currentLength !== expectedLength) {
if (expectedLength !== UNKNOWN_PLP_LEN) {
if (currentLength !== Number(expectedLength)) {
throw new Error('Partially Length-prefixed Bytes unmatched lengths : expected ' + expectedLength + ', but got ' + currentLength + ' bytes');
}
}
Expand Down

0 comments on commit 0435a78

Please sign in to comment.