@bufbuild/protobuf 2.6.2 → 2.7.0

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.
@@ -20,6 +20,7 @@ const descriptors_js_1 = require("./descriptors.js");
20
20
  const scalar_js_1 = require("./reflect/scalar.js");
21
21
  const reflect_js_1 = require("./reflect/reflect.js");
22
22
  const binary_encoding_js_1 = require("./wire/binary-encoding.js");
23
+ const varint_js_1 = require("./wire/varint.js");
23
24
  // Default options for parsing binary data.
24
25
  const readDefaults = {
25
26
  readUnknownFields: true,
@@ -106,9 +107,14 @@ function readField(message, reader, field, wireType, options) {
106
107
  message.set(field, val);
107
108
  }
108
109
  else if (options.readUnknownFields) {
109
- const data = new binary_encoding_js_1.BinaryWriter().int32(val).finish();
110
+ const bytes = [];
111
+ (0, varint_js_1.varint32write)(val, bytes);
110
112
  const unknownFields = (_a = message.getUnknown()) !== null && _a !== void 0 ? _a : [];
111
- unknownFields.push({ no: field.number, wireType, data });
113
+ unknownFields.push({
114
+ no: field.number,
115
+ wireType,
116
+ data: new Uint8Array(bytes),
117
+ });
112
118
  message.setUnknown(unknownFields);
113
119
  }
114
120
  }
@@ -129,7 +135,11 @@ function readMapEntry(reader, map, options) {
129
135
  const field = map.field();
130
136
  let key;
131
137
  let val;
132
- const end = reader.pos + reader.uint32();
138
+ // Read the length of the map entry, which is a varint.
139
+ const len = reader.uint32();
140
+ // WARNING: Calculate end AFTER advancing reader.pos (above), so that
141
+ // reader.pos is at the start of the map entry.
142
+ const end = reader.pos + len;
133
143
  while (reader.pos < end) {
134
144
  const [fieldNo] = reader.tag();
135
145
  switch (fieldNo) {
@@ -17,7 +17,7 @@ export interface BinaryWriteOptions {
17
17
  */
18
18
  writeUnknownFields: boolean;
19
19
  }
20
- export declare function toBinary<Desc extends DescMessage>(schema: Desc, message: MessageShape<Desc>, options?: Partial<BinaryWriteOptions>): Uint8Array;
20
+ export declare function toBinary<Desc extends DescMessage>(schema: Desc, message: MessageShape<Desc>, options?: Partial<BinaryWriteOptions>): Uint8Array<ArrayBuffer>;
21
21
  /**
22
22
  * @private
23
23
  */
@@ -9,7 +9,7 @@
9
9
  * "_" instead of "/",
10
10
  * no padding
11
11
  */
12
- export declare function base64Decode(base64Str: string): Uint8Array;
12
+ export declare function base64Decode(base64Str: string): Uint8Array<ArrayBuffer>;
13
13
  /**
14
14
  * Encode a byte array to a base64 string.
15
15
  *
@@ -42,7 +42,7 @@ function base64Decode(base64Str) {
42
42
  b = table[base64Str.charCodeAt(i)];
43
43
  if (b === undefined) {
44
44
  switch (base64Str[i]) {
45
- // @ts-expect-error TS7029: Fallthrough case in switch
45
+ // @ts-ignore TS7029: Fallthrough case in switch -- ignore instead of expect-error for compiler settings without noFallthroughCasesInSwitch: true
46
46
  case "=":
47
47
  groupPos = 0; // reset state when padding found
48
48
  case "\n":
@@ -86,7 +86,7 @@ export declare class BinaryWriter {
86
86
  /**
87
87
  * Return all bytes written and reset this writer.
88
88
  */
89
- finish(): Uint8Array;
89
+ finish(): Uint8Array<ArrayBuffer>;
90
90
  /**
91
91
  * Start a new fork for length-delimited data like a message
92
92
  * or a packed repeated field.
@@ -329,7 +329,7 @@ class BinaryReader {
329
329
  // ignore
330
330
  }
331
331
  break;
332
- // @ts-expect-error TS7029: Fallthrough case in switch
332
+ // @ts-ignore TS7029: Fallthrough case in switch -- ignore instead of expect-error for compiler settings without noFallthroughCasesInSwitch: true
333
333
  case WireType.Bit64:
334
334
  this.pos += 4;
335
335
  case WireType.Bit32:
@@ -6,7 +6,7 @@ interface TextEncoding {
6
6
  /**
7
7
  * Encode UTF-8 text to binary.
8
8
  */
9
- encodeUtf8: (text: string) => Uint8Array;
9
+ encodeUtf8: (text: string) => Uint8Array<ArrayBuffer>;
10
10
  /**
11
11
  * Decode UTF-8 text from binary.
12
12
  */
@@ -14,7 +14,8 @@
14
14
  import { ScalarType } from "./descriptors.js";
15
15
  import { scalarZeroValue } from "./reflect/scalar.js";
16
16
  import { reflect } from "./reflect/reflect.js";
17
- import { BinaryReader, BinaryWriter, WireType, } from "./wire/binary-encoding.js";
17
+ import { BinaryReader, WireType } from "./wire/binary-encoding.js";
18
+ import { varint32write } from "./wire/varint.js";
18
19
  // Default options for parsing binary data.
19
20
  const readDefaults = {
20
21
  readUnknownFields: true,
@@ -101,9 +102,14 @@ export function readField(message, reader, field, wireType, options) {
101
102
  message.set(field, val);
102
103
  }
103
104
  else if (options.readUnknownFields) {
104
- const data = new BinaryWriter().int32(val).finish();
105
+ const bytes = [];
106
+ varint32write(val, bytes);
105
107
  const unknownFields = (_a = message.getUnknown()) !== null && _a !== void 0 ? _a : [];
106
- unknownFields.push({ no: field.number, wireType, data });
108
+ unknownFields.push({
109
+ no: field.number,
110
+ wireType,
111
+ data: new Uint8Array(bytes),
112
+ });
107
113
  message.setUnknown(unknownFields);
108
114
  }
109
115
  }
@@ -124,7 +130,11 @@ function readMapEntry(reader, map, options) {
124
130
  const field = map.field();
125
131
  let key;
126
132
  let val;
127
- const end = reader.pos + reader.uint32();
133
+ // Read the length of the map entry, which is a varint.
134
+ const len = reader.uint32();
135
+ // WARNING: Calculate end AFTER advancing reader.pos (above), so that
136
+ // reader.pos is at the start of the map entry.
137
+ const end = reader.pos + len;
128
138
  while (reader.pos < end) {
129
139
  const [fieldNo] = reader.tag();
130
140
  switch (fieldNo) {
@@ -17,7 +17,7 @@ export interface BinaryWriteOptions {
17
17
  */
18
18
  writeUnknownFields: boolean;
19
19
  }
20
- export declare function toBinary<Desc extends DescMessage>(schema: Desc, message: MessageShape<Desc>, options?: Partial<BinaryWriteOptions>): Uint8Array;
20
+ export declare function toBinary<Desc extends DescMessage>(schema: Desc, message: MessageShape<Desc>, options?: Partial<BinaryWriteOptions>): Uint8Array<ArrayBuffer>;
21
21
  /**
22
22
  * @private
23
23
  */
@@ -9,7 +9,7 @@
9
9
  * "_" instead of "/",
10
10
  * no padding
11
11
  */
12
- export declare function base64Decode(base64Str: string): Uint8Array;
12
+ export declare function base64Decode(base64Str: string): Uint8Array<ArrayBuffer>;
13
13
  /**
14
14
  * Encode a byte array to a base64 string.
15
15
  *
@@ -38,7 +38,7 @@ export function base64Decode(base64Str) {
38
38
  b = table[base64Str.charCodeAt(i)];
39
39
  if (b === undefined) {
40
40
  switch (base64Str[i]) {
41
- // @ts-expect-error TS7029: Fallthrough case in switch
41
+ // @ts-ignore TS7029: Fallthrough case in switch -- ignore instead of expect-error for compiler settings without noFallthroughCasesInSwitch: true
42
42
  case "=":
43
43
  groupPos = 0; // reset state when padding found
44
44
  case "\n":
@@ -86,7 +86,7 @@ export declare class BinaryWriter {
86
86
  /**
87
87
  * Return all bytes written and reset this writer.
88
88
  */
89
- finish(): Uint8Array;
89
+ finish(): Uint8Array<ArrayBuffer>;
90
90
  /**
91
91
  * Start a new fork for length-delimited data like a message
92
92
  * or a packed repeated field.
@@ -325,7 +325,7 @@ export class BinaryReader {
325
325
  // ignore
326
326
  }
327
327
  break;
328
- // @ts-expect-error TS7029: Fallthrough case in switch
328
+ // @ts-ignore TS7029: Fallthrough case in switch -- ignore instead of expect-error for compiler settings without noFallthroughCasesInSwitch: true
329
329
  case WireType.Bit64:
330
330
  this.pos += 4;
331
331
  case WireType.Bit32:
@@ -6,7 +6,7 @@ interface TextEncoding {
6
6
  /**
7
7
  * Encode UTF-8 text to binary.
8
8
  */
9
- encodeUtf8: (text: string) => Uint8Array;
9
+ encodeUtf8: (text: string) => Uint8Array<ArrayBuffer>;
10
10
  /**
11
11
  * Decode UTF-8 text from binary.
12
12
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bufbuild/protobuf",
3
- "version": "2.6.2",
3
+ "version": "2.7.0",
4
4
  "license": "(Apache-2.0 AND BSD-3-Clause)",
5
5
  "description": "A complete implementation of Protocol Buffers in TypeScript, suitable for web browsers and Node.js.",
6
6
  "keywords": ["protobuf", "schema", "typescript", "ecmascript"],