Skip to content

Commit 32bc5b7

Browse files
committed
feat: Use 1-based unsigned VLQs for binding expressions
"0" becomes the unavailability marker.
1 parent d19865b commit 32bc5b7

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/decode/decode.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class Decoder {
163163
const valueIdxs: number[] = [];
164164

165165
while (iter.hasNext() && iter.peek() !== ",") {
166-
valueIdxs.push(iter.nextSignedVLQ());
166+
valueIdxs.push(iter.nextUnsignedVLQ());
167167
}
168168

169169
this.#handleGeneratedRangeBindingsItem(valueIdxs);
@@ -343,10 +343,10 @@ class Decoder {
343343
}
344344

345345
for (const valueIdx of valueIdxs) {
346-
if (valueIdx === -1) {
346+
if (valueIdx === 0) {
347347
range.values.push(null);
348348
} else {
349-
range.values.push(this.#resolveName(valueIdx));
349+
range.values.push(this.#resolveName(valueIdx - 1));
350350
}
351351
}
352352
}

src/encode/encoder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ export class Encoder {
204204
this.#encodeTag(EncodedTag.GENERATED_RANGE_BINDINGS);
205205
for (const val of range.values) {
206206
if (val === null || val == undefined) {
207-
this.#encodeSigned(-1);
207+
this.#encodeUnsigned(0);
208208
} else if (typeof val === "string") {
209-
this.#encodeSigned(this.#resolveNamesIdx(val));
209+
this.#encodeUnsigned(this.#resolveNamesIdx(val) + 1);
210210
} else {
211211
throw new Error("Sub-range bindings not implemented yet!");
212212
}

0 commit comments

Comments
 (0)