Skip to content

Commit adf0569

Browse files
jlucaso1emcfarlane
authored andcommitted
Refactor BinaryWriter to use a growable Uint8Array buffer
1 parent 6a1f209 commit adf0569

1 file changed

Lines changed: 0 additions & 16 deletions

File tree

packages/protobuf/src/wire/binary-encoding.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ export class BinaryWriter {
139139
this.stackPos = [];
140140
return result;
141141
}
142-
143142
/**
144143
* Start a new fork for length-delimited data like a message
145144
* or a packed repeated field.
@@ -150,7 +149,6 @@ export class BinaryWriter {
150149
this.stackPos.push(this.pos);
151150
return this;
152151
}
153-
154152
/**
155153
* Join the last fork. Write its length and bytes, then
156154
* return to the previous state.
@@ -186,7 +184,6 @@ export class BinaryWriter {
186184
tag(fieldNo: number, type: WireType): this {
187185
return this.uint32(((fieldNo << 3) | type) >>> 0);
188186
}
189-
190187
/**
191188
* Write a chunk of raw bytes.
192189
*/
@@ -196,7 +193,6 @@ export class BinaryWriter {
196193
this.pos += chunk.length;
197194
return this;
198195
}
199-
200196
/**
201197
* Write a `uint32` value, an unsigned 32 bit varint.
202198
*/
@@ -234,7 +230,6 @@ export class BinaryWriter {
234230
this.buffer[this.pos++] = 1;
235231
return this;
236232
}
237-
238233
/**
239234
* Write a `bool` value, a varint.
240235
*/
@@ -243,15 +238,13 @@ export class BinaryWriter {
243238
this.buffer[this.pos++] = value ? 1 : 0;
244239
return this;
245240
}
246-
247241
/**
248242
* Write a `bytes` value, length-delimited arbitrary data.
249243
*/
250244
bytes(value: Uint8Array): this {
251245
this.uint32(value.byteLength);
252246
return this.raw(value);
253247
}
254-
255248
/**
256249
* Write a `string` value, length-delimited data converted to UTF-8 text.
257250
*/
@@ -275,7 +268,6 @@ export class BinaryWriter {
275268
this.pos += 4;
276269
return this;
277270
}
278-
279271
/**
280272
* Write a `double` value, a 64-bit floating point number.
281273
*/
@@ -289,7 +281,6 @@ export class BinaryWriter {
289281
this.pos += 8;
290282
return this;
291283
}
292-
293284
/**
294285
* Write a `fixed32` value, an unsigned, fixed-length 32-bit integer.
295286
*/
@@ -304,7 +295,6 @@ export class BinaryWriter {
304295
this.pos += 4;
305296
return this;
306297
}
307-
308298
/**
309299
* Write a `sfixed32` value, a signed, fixed-length 32-bit integer.
310300
*/
@@ -319,7 +309,6 @@ export class BinaryWriter {
319309
this.pos += 4;
320310
return this;
321311
}
322-
323312
/**
324313
* Write a `sint32` value, a signed, zigzag-encoded 32-bit varint.
325314
*/
@@ -328,7 +317,6 @@ export class BinaryWriter {
328317
// zigzag encode then emit as uint32 varint
329318
return this.uint32(((value << 1) ^ (value >> 31)) >>> 0);
330319
}
331-
332320
/**
333321
* Write a `sfixed64` value, a signed, fixed-length 64-bit integer.
334322
*/
@@ -345,7 +333,6 @@ export class BinaryWriter {
345333
this.pos += 8;
346334
return this;
347335
}
348-
349336
/**
350337
* Write a `fixed64` value, an unsigned, fixed-length 64 bit integer.
351338
*/
@@ -362,15 +349,13 @@ export class BinaryWriter {
362349
this.pos += 8;
363350
return this;
364351
}
365-
366352
/**
367353
* Write a `int64` value, a signed 64-bit varint.
368354
*/
369355
int64(value: string | number | bigint): this {
370356
const tc = protoInt64.enc(value);
371357
return this.writeVarint64(tc.lo, tc.hi);
372358
}
373-
374359
/**
375360
* Write a `sint64` value, a signed, zig-zag-encoded 64-bit varint.
376361
*/
@@ -382,7 +367,6 @@ export class BinaryWriter {
382367
hi = ((tc.hi << 1) | (tc.lo >>> 31)) ^ sign;
383368
return this.writeVarint64(lo, hi);
384369
}
385-
386370
/**
387371
* Write a `uint64` value, an unsigned 64-bit varint.
388372
*/

0 commit comments

Comments
 (0)