protobufjs 8.6.6 → 8.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.
@@ -2,14 +2,6 @@ syntax = "proto2";
2
2
 
3
3
  package google.protobuf;
4
4
 
5
- option go_package = "google.golang.org/protobuf/types/descriptorpb";
6
- option java_package = "com.google.protobuf";
7
- option java_outer_classname = "DescriptorProtos";
8
- option csharp_namespace = "Google.Protobuf.Reflection";
9
- option objc_class_prefix = "GPB";
10
- option cc_enable_arenas = true;
11
- option optimize_for = "SPEED";
12
-
13
5
  message FileDescriptorSet {
14
6
 
15
7
  repeated FileDescriptorProto file = 1;
@@ -8,7 +8,8 @@
8
8
  "fields": {
9
9
  "fileName": {
10
10
  "type": "string",
11
- "id": 1
11
+ "id": 1,
12
+ "protoName": "file_name"
12
13
  }
13
14
  }
14
15
  }
@@ -27,7 +27,8 @@
27
27
  },
28
28
  "sourceContext": {
29
29
  "type": "SourceContext",
30
- "id": 5
30
+ "id": 5,
31
+ "protoName": "source_context"
31
32
  },
32
33
  "syntax": {
33
34
  "type": "Syntax",
@@ -55,11 +56,13 @@
55
56
  },
56
57
  "typeUrl": {
57
58
  "type": "string",
58
- "id": 6
59
+ "id": 6,
60
+ "protoName": "type_url"
59
61
  },
60
62
  "oneofIndex": {
61
63
  "type": "int32",
62
- "id": 7
64
+ "id": 7,
65
+ "protoName": "oneof_index"
63
66
  },
64
67
  "packed": {
65
68
  "type": "bool",
@@ -72,11 +75,13 @@
72
75
  },
73
76
  "jsonName": {
74
77
  "type": "string",
75
- "id": 10
78
+ "id": 10,
79
+ "protoName": "json_name"
76
80
  },
77
81
  "defaultValue": {
78
82
  "type": "string",
79
- "id": 11
83
+ "id": 11,
84
+ "protoName": "default_value"
80
85
  }
81
86
  },
82
87
  "nested": {
@@ -131,7 +136,8 @@
131
136
  },
132
137
  "sourceContext": {
133
138
  "type": "SourceContext",
134
- "id": 4
139
+ "id": 4,
140
+ "protoName": "source_context"
135
141
  },
136
142
  "syntax": {
137
143
  "type": "Syntax",
@@ -190,7 +196,8 @@
190
196
  "fields": {
191
197
  "fileName": {
192
198
  "type": "string",
193
- "id": 1
199
+ "id": 1,
200
+ "protoName": "file_name"
194
201
  }
195
202
  }
196
203
  }
package/index.d.ts CHANGED
@@ -1212,7 +1212,7 @@ export interface IToJSONOptions {
1212
1212
  */
1213
1213
  export function parse(source: string, root: Root, options?: IParseOptions): IParserResult;
1214
1214
 
1215
- /** Wire format reader using `Uint8Array` if available, otherwise `Array`. */
1215
+ /** Wire format reader using `Uint8Array`. */
1216
1216
  export class Reader {
1217
1217
 
1218
1218
  /**
@@ -1230,6 +1230,9 @@ export class Reader {
1230
1230
  /** Read buffer length. */
1231
1231
  len: number;
1232
1232
 
1233
+ /** Cached DataView for packed reads. */
1234
+ view: (DataView|null);
1235
+
1233
1236
  /** Whether to discard unknown fields while decoding. */
1234
1237
  discardUnknown: boolean;
1235
1238
 
@@ -1333,6 +1336,97 @@ export class Reader {
1333
1336
  */
1334
1337
  double(): number;
1335
1338
 
1339
+ /**
1340
+ * Reads a packed repeated field of unsigned 32 bit varints.
1341
+ * @param [array] Array to read into; a new one is created if omitted
1342
+ * @returns Array read into
1343
+ */
1344
+ uint32s(array?: number[]): number[];
1345
+
1346
+ /**
1347
+ * Reads a packed repeated field of signed 32 bit varints.
1348
+ * @param [array] Array to read into; a new one is created if omitted
1349
+ * @returns Array read into
1350
+ */
1351
+ int32s(array?: number[]): number[];
1352
+
1353
+ /**
1354
+ * Reads a packed repeated field of zig-zag encoded signed 32 bit varints.
1355
+ * @param [array] Array to read into; a new one is created if omitted
1356
+ * @returns Array read into
1357
+ */
1358
+ sint32s(array?: number[]): number[];
1359
+
1360
+ /**
1361
+ * Reads a packed repeated field of booleans.
1362
+ * @param [array] Array to read into; a new one is created if omitted
1363
+ * @returns Array read into
1364
+ */
1365
+ bools(array?: boolean[]): boolean[];
1366
+
1367
+ /**
1368
+ * Reads a packed repeated field of unsigned 32 bit fixed values.
1369
+ * @param [array] Array to read into; a new one is created if omitted
1370
+ * @returns Array read into
1371
+ */
1372
+ fixed32s(array?: number[]): number[];
1373
+
1374
+ /**
1375
+ * Reads a packed repeated field of signed 32 bit fixed values.
1376
+ * @param [array] Array to read into; a new one is created if omitted
1377
+ * @returns Array read into
1378
+ */
1379
+ sfixed32s(array?: number[]): number[];
1380
+
1381
+ /**
1382
+ * Reads a packed repeated field of floats (32 bit).
1383
+ * @param [array] Array to read into; a new one is created if omitted
1384
+ * @returns Array read into
1385
+ */
1386
+ floats(array?: number[]): number[];
1387
+
1388
+ /**
1389
+ * Reads a packed repeated field of doubles (64 bit float).
1390
+ * @param [array] Array to read into; a new one is created if omitted
1391
+ * @returns Array read into
1392
+ */
1393
+ doubles(array?: number[]): number[];
1394
+
1395
+ /**
1396
+ * Reads a packed repeated field of unsigned 64 bit varints.
1397
+ * @param [array] Array to read into; a new one is created if omitted
1398
+ * @returns Array read into
1399
+ */
1400
+ uint64s(array?: (Long|number)[]): (Long|number)[];
1401
+
1402
+ /**
1403
+ * Reads a packed repeated field of signed 64 bit varints.
1404
+ * @param [array] Array to read into; a new one is created if omitted
1405
+ * @returns Array read into
1406
+ */
1407
+ int64s(array?: (Long|number)[]): (Long|number)[];
1408
+
1409
+ /**
1410
+ * Reads a packed repeated field of zig-zag encoded signed 64 bit varints.
1411
+ * @param [array] Array to read into; a new one is created if omitted
1412
+ * @returns Array read into
1413
+ */
1414
+ sint64s(array?: (Long|number)[]): (Long|number)[];
1415
+
1416
+ /**
1417
+ * Reads a packed repeated field of unsigned 64 bit fixed values.
1418
+ * @param [array] Array to read into; a new one is created if omitted
1419
+ * @returns Array read into
1420
+ */
1421
+ fixed64s(array?: (Long|number)[]): (Long|number)[];
1422
+
1423
+ /**
1424
+ * Reads a packed repeated field of signed 64 bit fixed values.
1425
+ * @param [array] Array to read into; a new one is created if omitted
1426
+ * @returns Array read into
1427
+ */
1428
+ sfixed64s(array?: (Long|number)[]): (Long|number)[];
1429
+
1336
1430
  /**
1337
1431
  * Reads a sequence of bytes preceeded by its length as a varint.
1338
1432
  * @returns Value read
@@ -2464,7 +2558,10 @@ export namespace util {
2464
2558
  */
2465
2559
  function newBuffer(sizeOrArray?: (number|number[])): (Uint8Array|Buffer);
2466
2560
 
2467
- /** Array implementation used in the browser. `Uint8Array` if supported, otherwise `Array`. */
2561
+ /**
2562
+ * Array implementation used in the browser.
2563
+ * @deprecated Use `Uint8Array` instead.
2564
+ */
2468
2565
  let Array: Constructor<Uint8Array>;
2469
2566
 
2470
2567
  /** Long.js's Long class if available. */
@@ -2626,7 +2723,7 @@ export namespace util {
2626
2723
  */
2627
2724
  function pool(alloc: PoolAllocator, slice: PoolSlicer, size?: number): PoolAllocator;
2628
2725
 
2629
- /** A minimal UTF8 implementation for number arrays. */
2726
+ /** A minimal UTF8 implementation. */
2630
2727
  namespace utf8 {
2631
2728
 
2632
2729
  /**
@@ -2803,23 +2900,29 @@ export interface IWrapper {
2803
2900
  toObject?: WrapperToObjectConverter;
2804
2901
  }
2805
2902
 
2806
- /** Wire format writer using `Uint8Array` if available, otherwise `Array`. */
2903
+ /** Wire format writer using `Uint8Array`. */
2807
2904
  export class Writer {
2808
2905
 
2809
2906
  /** Constructs a new writer instance. */
2810
2907
  constructor();
2811
2908
 
2812
- /** Current length. */
2813
- len: number;
2909
+ /** Write cursor into {@link Writer#buf}. */
2910
+ pos: number;
2814
2911
 
2815
- /** Operations head. */
2816
- head: object;
2912
+ /** Backing buffer. */
2913
+ buf: Uint8Array;
2817
2914
 
2818
- /** Operations tail */
2819
- tail: object;
2915
+ /** Cached DataView over {@link Writer#buf}. */
2916
+ view: (DataView|null);
2820
2917
 
2821
- /** Linked forked states. */
2822
- states: (object|null);
2918
+ /** Stack of forked length-prefix positions. */
2919
+ states: (number[]|null);
2920
+
2921
+ /**
2922
+ * Current write position.
2923
+ * @deprecated Use {@link Writer#pos} instead.
2924
+ */
2925
+ len: number;
2823
2926
 
2824
2927
  /**
2825
2928
  * Creates a new writer.
@@ -2951,9 +3054,99 @@ export class Writer {
2951
3054
  */
2952
3055
  string(value: string): Writer;
2953
3056
 
3057
+ /**
3058
+ * Writes an array of unsigned 32 bit values as a packed repeated field.
3059
+ * @param value Values to write
3060
+ * @returns `this`
3061
+ */
3062
+ uint32s(value: number[]): Writer;
3063
+
3064
+ /**
3065
+ * Writes an array of signed 32 bit values as a packed repeated field.
3066
+ * @param value Values to write
3067
+ * @returns `this`
3068
+ */
3069
+ int32s(value: number[]): Writer;
3070
+
3071
+ /**
3072
+ * Writes an array of 32 bit values as packed, zig-zag encoded varints.
3073
+ * @param value Values to write
3074
+ * @returns `this`
3075
+ */
3076
+ sint32s(value: number[]): Writer;
3077
+
3078
+ /**
3079
+ * Writes an array of unsigned 64 bit values as a packed repeated field.
3080
+ * @param value Values to write
3081
+ * @returns `this`
3082
+ */
3083
+ uint64s(value: (Long|number|string)[]): Writer;
3084
+
3085
+ /**
3086
+ * Writes an array of signed 64 bit values as a packed repeated field.
3087
+ * @param value Values to write
3088
+ * @returns `this`
3089
+ */
3090
+ int64s(value: (Long|number|string)[]): Writer;
3091
+
3092
+ /**
3093
+ * Writes an array of 64 bit values as packed, zig-zag encoded varints.
3094
+ * @param value Values to write
3095
+ * @returns `this`
3096
+ */
3097
+ sint64s(value: (Long|number|string)[]): Writer;
3098
+
3099
+ /**
3100
+ * Writes an array of boolish values as a packed repeated field.
3101
+ * @param value Values to write
3102
+ * @returns `this`
3103
+ */
3104
+ bools(value: boolean[]): Writer;
3105
+
3106
+ /**
3107
+ * Writes an array of unsigned 32 bit values as packed, fixed 32 bits.
3108
+ * @param value Values to write
3109
+ * @returns `this`
3110
+ */
3111
+ fixed32s(value: number[]): Writer;
3112
+
3113
+ /**
3114
+ * Writes an array of signed 32 bit values as packed, fixed 32 bits.
3115
+ * @param value Values to write
3116
+ * @returns `this`
3117
+ */
3118
+ sfixed32s(value: number[]): Writer;
3119
+
3120
+ /**
3121
+ * Writes an array of unsigned 64 bit values as packed, fixed 64 bits.
3122
+ * @param value Values to write
3123
+ * @returns `this`
3124
+ */
3125
+ fixed64s(value: (Long|number|string)[]): Writer;
3126
+
3127
+ /**
3128
+ * Writes an array of signed 64 bit values as packed, fixed 64 bits.
3129
+ * @param value Values to write
3130
+ * @returns `this`
3131
+ */
3132
+ sfixed64s(value: (Long|number|string)[]): Writer;
3133
+
3134
+ /**
3135
+ * Writes an array of floats (32 bit) as a packed repeated field.
3136
+ * @param value Values to write
3137
+ * @returns `this`
3138
+ */
3139
+ floats(value: number[]): Writer;
3140
+
3141
+ /**
3142
+ * Writes an array of doubles (64 bit float) as a packed repeated field.
3143
+ * @param value Values to write
3144
+ * @returns `this`
3145
+ */
3146
+ doubles(value: number[]): Writer;
3147
+
2954
3148
  /**
2955
3149
  * Forks this writer's state by pushing it to a stack.
2956
- * Calling {@link Writer#reset|reset} or {@link Writer#ldelim|ldelim} resets the writer to the previous state.
2957
3150
  * @returns `this`
2958
3151
  */
2959
3152
  fork(): Writer;
@@ -2965,21 +3158,23 @@ export class Writer {
2965
3158
  reset(): Writer;
2966
3159
 
2967
3160
  /**
2968
- * Resets to the last state and appends the fork state's current write length as a varint followed by its operations.
3161
+ * Resets to the last state and prepends the fork state's current write length as a varint.
2969
3162
  * @returns `this`
2970
3163
  */
2971
3164
  ldelim(): Writer;
2972
3165
 
2973
3166
  /**
2974
3167
  * Finishes the write operation.
3168
+ * Returns a buffer sized to the written data by default.
3169
+ * @param [shared=false] Whether to return a shared view instead of a unique copy
2975
3170
  * @returns Finished buffer
2976
3171
  */
2977
- finish(): Uint8Array;
3172
+ finish(shared?: boolean): Uint8Array;
2978
3173
 
2979
3174
  /**
2980
3175
  * Finishes the write operation, writing into the provided buffer.
2981
3176
  * The caller must ensure that `buf` has enough space starting at `offset`
2982
- * to hold {@link Writer#len} bytes.
3177
+ * to hold {@link Writer#pos} bytes.
2983
3178
  * @param buf Target buffer
2984
3179
  * @param [offset=0] Offset to start writing at
2985
3180
  * @returns The provided buffer
@@ -3000,13 +3195,6 @@ export class BufferWriter extends Writer {
3000
3195
  */
3001
3196
  static alloc(size: number): Buffer;
3002
3197
 
3003
- /**
3004
- * Writes raw bytes without a tag or length prefix.
3005
- * @param value Raw bytes
3006
- * @returns `this`
3007
- */
3008
- raw(value: Uint8Array): BufferWriter;
3009
-
3010
3198
  /**
3011
3199
  * Finishes the write operation.
3012
3200
  * @returns Finished buffer
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "protobufjs",
3
- "version": "8.6.6",
3
+ "version": "8.7.1",
4
4
  "description": "Protocol Buffers for JavaScript & TypeScript.",
5
5
  "author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
6
6
  "license": "BSD-3-Clause",
@@ -22,7 +22,7 @@
22
22
  "fs": false
23
23
  },
24
24
  "scripts": {
25
- "bench": "node bench",
25
+ "bench": "npm --prefix bench run bench",
26
26
  "build": "npm run build:bundle && npm run build:types",
27
27
  "build:bundle": "gulp --gulpfile scripts/gulpfile.js",
28
28
  "build:tests": "node ./scripts/gentests.js",
@@ -49,11 +49,11 @@
49
49
  },
50
50
  "devDependencies": {
51
51
  "@eslint/js": "^10.0.0",
52
- "@types/node": ">=13.7.0",
52
+ "@types/node": "^18.19.130",
53
53
  "browserify": "^17.0.0",
54
54
  "browserify-wrap": "^1.0.2",
55
55
  "bundle-collapser": "^1.3.0",
56
- "escodegen": "^1.13.0",
56
+ "escodegen": "^2.0.0",
57
57
  "eslint": "^10.0.0",
58
58
  "eslint-plugin-jsdoc": "^63.0.0",
59
59
  "espree": "^9.0.0",
@@ -71,7 +71,7 @@
71
71
  "reflect-metadata": "^0.2.0",
72
72
  "tape": "^5.0.0",
73
73
  "tslint": "^6.0.0",
74
- "typescript": "^3.7.5",
74
+ "typescript": "^4.9.5",
75
75
  "vinyl-buffer": "^1.0.1",
76
76
  "vinyl-fs": "^4.0.0",
77
77
  "vinyl-source-stream": "^2.0.0"
package/src/common.js CHANGED
@@ -163,27 +163,33 @@ common("struct", {
163
163
  fields: {
164
164
  nullValue: {
165
165
  type: "NullValue",
166
- id: 1
166
+ id: 1,
167
+ protoName: "null_value"
167
168
  },
168
169
  numberValue: {
169
170
  type: "double",
170
- id: 2
171
+ id: 2,
172
+ protoName: "number_value"
171
173
  },
172
174
  stringValue: {
173
175
  type: "string",
174
- id: 3
176
+ id: 3,
177
+ protoName: "string_value"
175
178
  },
176
179
  boolValue: {
177
180
  type: "bool",
178
- id: 4
181
+ id: 4,
182
+ protoName: "bool_value"
179
183
  },
180
184
  structValue: {
181
185
  type: "Struct",
182
- id: 5
186
+ id: 5,
187
+ protoName: "struct_value"
183
188
  },
184
189
  listValue: {
185
190
  type: "ListValue",
186
- id: 6
191
+ id: 6,
192
+ protoName: "list_value"
187
193
  }
188
194
  }
189
195
  },
package/src/converter.js CHANGED
@@ -298,7 +298,7 @@ converter.toObject = function toObject(mtype) {
298
298
  else if (field.bytes) {
299
299
  var arrayDefault = Array.prototype.slice.call(field.typeDefault);
300
300
  gen
301
- ("if(o.bytes===String)d%s=%j", prop, String.fromCharCode.apply(String, field.typeDefault))
301
+ ("if(o.bytes===String)d%s=%j", prop, util.base64.encode(field.typeDefault, 0, field.typeDefault.length))
302
302
  ("else{")
303
303
  ("d%s=%j", prop, arrayDefault)
304
304
  ("if(o.bytes!==Array)d%s=util.newBuffer(d%s)", prop, prop)
package/src/decoder.js CHANGED
@@ -102,7 +102,7 @@ function decoder(mtype) {
102
102
  ("break");
103
103
 
104
104
  if (types.basic[type] === undefined) gen
105
- ("v=types[%i].decode(r,r.uint32(),undefined,q+1)", i); // can't be groups
105
+ ("v=types[%i].decode(r,r.uint32(),undefined,q+1,v)", i); // can't be groups
106
106
  else gen
107
107
  ("v=r.%s()", type === "string" ? stringMethod(field) : type);
108
108
 
@@ -141,13 +141,9 @@ function decoder(mtype) {
141
141
  if (types.packed[type] !== undefined) {
142
142
  gen
143
143
  ("if(u===2){");
144
- if (!closed) gen
145
- ("if(!(%s&&%s.length))", ref, ref)
146
- ("%s=[]", ref);
147
- gen
148
- ("var c2=r.uint32()+r.pos");
149
144
  if (closed) {
150
145
  gen
146
+ ("var c2=r.uint32()+r.pos")
151
147
  ("while(r.pos<c2){")
152
148
  ("s=r.pos")
153
149
  ("v=r.%s()", type)
@@ -159,8 +155,9 @@ function decoder(mtype) {
159
155
  genPreserveUnknown(gen, "util.rawField(" + field.id + ",0,r.raw(s,r.pos))")
160
156
  ("}");
161
157
  } else gen
162
- ("while(r.pos<c2)")
163
- ("%s.push(r.%s())", ref, type);
158
+ ("if(!(%s&&%s.length))", ref, ref)
159
+ ("%s=[]", ref)
160
+ ("r.%ss(%s)", type, ref);
164
161
  gen
165
162
  ("continue")
166
163
  ("}");
package/src/encoder.js CHANGED
@@ -72,10 +72,7 @@ function encoder(mtype) {
72
72
  // Packed repeated
73
73
  if (field.packed && types.packed[type] !== undefined) { gen
74
74
 
75
- ("w.uint32(%i).fork()", (field.id << 3 | 2) >>> 0)
76
- ("for(var i=0;i<%s.length;++i)", ref)
77
- ("w.%s(%s[i])", type, ref)
78
- ("w.ldelim()");
75
+ ("w.uint32(%i).%ss(%s)", (field.id << 3 | 2) >>> 0, type, ref);
79
76
 
80
77
  // Non-packed
81
78
  } else { gen
@@ -26,7 +26,7 @@ exports.configure = configure;
26
26
  * @returns {undefined}
27
27
  */
28
28
  function configure() {
29
- exports.util._configure();
29
+ exports.util.LongBits._configure(exports.util.Long);
30
30
  exports.Writer._configure(exports.BufferWriter);
31
31
  exports.Reader._configure(exports.BufferReader);
32
32
  }