Skip to content

Commit

Permalink
Merge pull request #47 from anton-trunov/fix-readStringOpt-and-readBu…
Browse files Browse the repository at this point in the history
…fferOpt

fix: always pop current element in `readStringOpt` and `readBufferOpt`
  • Loading branch information
dvlkv authored Oct 8, 2024
2 parents 9c1b8f7 + bf64d50 commit 8e47fe1
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/tuple/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,16 @@ export class TupleReader {
}

readBufferOpt() {
let popped = this.peek();
if (popped.type === 'null') {
let r = this.readCellOpt();
if (r !== null) {
let s = r.beginParse();
if (s.remainingRefs !== 0 || s.remainingBits % 8 !== 0) {
throw Error('Not a buffer');
}
return s.loadBuffer(s.remainingBits / 8);
} else {
return null;
}
let s = this.readCell().beginParse();
if (s.remainingRefs !== 0) {
throw Error('Not a buffer');
}
if (s.remainingBits % 8 !== 0) {
throw Error('Not a buffer');
}
return s.loadBuffer(s.remainingBits / 8);
}
}

readString() {
Expand All @@ -205,11 +203,13 @@ export class TupleReader {
}

readStringOpt() {
let popped = this.peek();
if (popped.type === 'null') {
let r = this.readCellOpt();
if (r !== null) {
let s = r.beginParse();
return s.loadStringTail();
} else {
return null;
}
let s = this.readCell().beginParse();
return s.loadStringTail();
}
}
}

0 comments on commit 8e47fe1

Please sign in to comment.