bin-serde 1.7.0 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.ts +8 -4
- package/lib/index.js +8 -4
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -59,9 +59,11 @@ export class Writer {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
writeUVarint(val: number) {
|
|
62
|
+
// Protobuf-style LEB128: little-endian, 7 bits per byte, MSB is continuation
|
|
63
|
+
// Use Math.floor instead of >>> to handle values > 32 bits
|
|
62
64
|
while (val >= 0x80) {
|
|
63
65
|
this.writeUInt8((val & 0x7f) | 0x80);
|
|
64
|
-
val
|
|
66
|
+
val = Math.floor(val / 128);
|
|
65
67
|
}
|
|
66
68
|
this.writeUInt8(val);
|
|
67
69
|
return this;
|
|
@@ -207,15 +209,17 @@ export class Reader {
|
|
|
207
209
|
}
|
|
208
210
|
|
|
209
211
|
readUVarint() {
|
|
212
|
+
// Protobuf-style LEB128: little-endian, 7 bits per byte, MSB is continuation
|
|
213
|
+
// Use multiplication instead of << to handle values > 32 bits
|
|
210
214
|
let result = 0;
|
|
211
|
-
let
|
|
215
|
+
let multiplier = 1;
|
|
212
216
|
while (true) {
|
|
213
217
|
const byte = this.readUInt8();
|
|
214
|
-
result
|
|
218
|
+
result += (byte & 0x7f) * multiplier;
|
|
215
219
|
if (byte < 0x80) {
|
|
216
220
|
return result;
|
|
217
221
|
}
|
|
218
|
-
|
|
222
|
+
multiplier *= 128;
|
|
219
223
|
}
|
|
220
224
|
}
|
|
221
225
|
|
package/lib/index.js
CHANGED
|
@@ -48,9 +48,11 @@ export class Writer {
|
|
|
48
48
|
return this;
|
|
49
49
|
}
|
|
50
50
|
writeUVarint(val) {
|
|
51
|
+
// Protobuf-style LEB128: little-endian, 7 bits per byte, MSB is continuation
|
|
52
|
+
// Use Math.floor instead of >>> to handle values > 32 bits
|
|
51
53
|
while (val >= 0x80) {
|
|
52
54
|
this.writeUInt8((val & 0x7f) | 0x80);
|
|
53
|
-
val
|
|
55
|
+
val = Math.floor(val / 128);
|
|
54
56
|
}
|
|
55
57
|
this.writeUInt8(val);
|
|
56
58
|
return this;
|
|
@@ -180,15 +182,17 @@ export class Reader {
|
|
|
180
182
|
return val;
|
|
181
183
|
}
|
|
182
184
|
readUVarint() {
|
|
185
|
+
// Protobuf-style LEB128: little-endian, 7 bits per byte, MSB is continuation
|
|
186
|
+
// Use multiplication instead of << to handle values > 32 bits
|
|
183
187
|
let result = 0;
|
|
184
|
-
let
|
|
188
|
+
let multiplier = 1;
|
|
185
189
|
while (true) {
|
|
186
190
|
const byte = this.readUInt8();
|
|
187
|
-
result
|
|
191
|
+
result += (byte & 0x7f) * multiplier;
|
|
188
192
|
if (byte < 0x80) {
|
|
189
193
|
return result;
|
|
190
194
|
}
|
|
191
|
-
|
|
195
|
+
multiplier *= 128;
|
|
192
196
|
}
|
|
193
197
|
}
|
|
194
198
|
readVarint() {
|