protobufjs 8.7.2 → 8.8.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/README.md +24 -17
- package/dist/light/protobuf.js +179 -30
- package/dist/light/protobuf.js.map +1 -1
- package/dist/light/protobuf.min.js +3 -3
- package/dist/light/protobuf.min.js.map +1 -1
- package/dist/minimal/protobuf.js +113 -20
- package/dist/minimal/protobuf.js.map +1 -1
- package/dist/minimal/protobuf.min.js +3 -3
- package/dist/minimal/protobuf.min.js.map +1 -1
- package/dist/protobuf.js +202 -37
- package/dist/protobuf.js.map +1 -1
- package/dist/protobuf.min.js +3 -3
- package/dist/protobuf.min.js.map +1 -1
- package/ext/descriptor.generated.d.ts +7 -0
- package/ext/descriptor.js +33 -0
- package/ext/protojson.js +29 -8
- package/ext/textformat.js +8 -4
- package/google/protobuf/descriptor.json +24 -1
- package/google/protobuf/descriptor.proto +15 -1
- package/google/protobuf/json_enumvalue_options.json +56 -0
- package/google/protobuf/json_enumvalue_options.proto +31 -0
- package/index.d.ts +18 -0
- package/package.json +1 -1
- package/src/decoder.js +35 -6
- package/src/enum.js +10 -0
- package/src/object.js +5 -2
- package/src/parse.js +9 -4
- package/src/reader.js +110 -17
- package/src/reader_buffer.js +1 -1
- package/src/tokenize.js +14 -3
- package/src/type.js +11 -1
- package/src/wrappers.js +5 -1
|
@@ -215,6 +215,9 @@ export interface IDescriptorProto {
|
|
|
215
215
|
|
|
216
216
|
/** Reserved names */
|
|
217
217
|
reservedName?: string[];
|
|
218
|
+
|
|
219
|
+
/** Declared symbol visibility */
|
|
220
|
+
visibility?: number;
|
|
218
221
|
}
|
|
219
222
|
|
|
220
223
|
/** Properties of a MessageOptions message. */
|
|
@@ -311,6 +314,9 @@ export interface IEnumDescriptorProto {
|
|
|
311
314
|
|
|
312
315
|
/** Enum options */
|
|
313
316
|
options?: IEnumOptions;
|
|
317
|
+
|
|
318
|
+
/** Declared symbol visibility */
|
|
319
|
+
visibility?: number;
|
|
314
320
|
}
|
|
315
321
|
|
|
316
322
|
/** Properties of an EnumValueDescriptorProto message. */
|
|
@@ -353,6 +359,7 @@ export interface IFeatureSet {
|
|
|
353
359
|
jsonFormat?: number;
|
|
354
360
|
enforceNamingStyle?: number;
|
|
355
361
|
defaultSymbolVisibility?: number;
|
|
362
|
+
enforceProtoLimits?: number;
|
|
356
363
|
}
|
|
357
364
|
|
|
358
365
|
/** Properties of a OneofDescriptorProto message. */
|
package/ext/descriptor.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var $protobuf = require("../light");
|
|
3
3
|
module.exports = exports = $protobuf.descriptor = $protobuf.Root.fromJSON(require("../google/protobuf/descriptor.json")).lookup(".google.protobuf");
|
|
4
|
+
exports.root.define("pb").addJSON(require("../google/protobuf/json_enumvalue_options.json").nested.pb.nested);
|
|
4
5
|
|
|
5
6
|
var Namespace = $protobuf.Namespace,
|
|
6
7
|
Root = $protobuf.Root,
|
|
@@ -52,6 +53,7 @@ var integerRe = /^[+-]?[0-9]+$/,
|
|
|
52
53
|
* @property {number} EDITION_PROTO3=999
|
|
53
54
|
* @property {number} EDITION_2023=1000
|
|
54
55
|
* @property {number} EDITION_2024=1001
|
|
56
|
+
* @property {number} EDITION_2026=1002
|
|
55
57
|
* @property {number} EDITION_1_TEST_ONLY=1
|
|
56
58
|
* @property {number} EDITION_2_TEST_ONLY=2
|
|
57
59
|
* @property {number} EDITION_99997_TEST_ONLY=99997
|
|
@@ -208,6 +210,7 @@ function Root_toDescriptorRecursive(ns, files, edition) {
|
|
|
208
210
|
* @property {IMessageOptions} [options] Not supported
|
|
209
211
|
* @property {IDescriptorProtoReservedRange[]} [reservedRange] Reserved ranges
|
|
210
212
|
* @property {string[]} [reservedName] Reserved names
|
|
213
|
+
* @property {number} [visibility] Declared symbol visibility
|
|
211
214
|
*/
|
|
212
215
|
|
|
213
216
|
/**
|
|
@@ -252,6 +255,7 @@ function Type_fromDescriptor(descriptor, ctx, nested, depth) {
|
|
|
252
255
|
var type = new Type(descriptor.name.length ? descriptor.name : "Type" + unnamedMessageIndex++, fromDescriptorOptions(descriptor.options, exports.MessageOptions)),
|
|
253
256
|
i,
|
|
254
257
|
mapEntries = Object.create(null);
|
|
258
|
+
type.visibility = visibilityFromDescriptor(descriptor.visibility);
|
|
255
259
|
|
|
256
260
|
if (!nested) {
|
|
257
261
|
type._edition = ctx.edition;
|
|
@@ -317,6 +321,9 @@ Type.prototype.toDescriptor = function toDescriptor(edition) {
|
|
|
317
321
|
var descriptor = exports.DescriptorProto.create({ name: this.name }),
|
|
318
322
|
i;
|
|
319
323
|
|
|
324
|
+
if (this.visibility)
|
|
325
|
+
descriptor.visibility = visibilityToDescriptor(this.visibility);
|
|
326
|
+
|
|
320
327
|
/* Fields */ for (i = 0; i < this.fieldsArray.length; ++i) {
|
|
321
328
|
var fieldDescriptor;
|
|
322
329
|
descriptor.field.push(fieldDescriptor = this._fieldsArray[i].toDescriptor(edition));
|
|
@@ -655,6 +662,7 @@ Field.prototype.toDescriptor = function toDescriptor(edition) {
|
|
|
655
662
|
* @property {string} [name] Enum name
|
|
656
663
|
* @property {IEnumValueDescriptorProto[]} [value] Enum values
|
|
657
664
|
* @property {IEnumOptions} [options] Enum options
|
|
665
|
+
* @property {number} [visibility] Declared symbol visibility
|
|
658
666
|
*/
|
|
659
667
|
|
|
660
668
|
/**
|
|
@@ -693,6 +701,7 @@ Field.prototype.toDescriptor = function toDescriptor(edition) {
|
|
|
693
701
|
* @property {number} [jsonFormat]
|
|
694
702
|
* @property {number} [enforceNamingStyle]
|
|
695
703
|
* @property {number} [defaultSymbolVisibility]
|
|
704
|
+
* @property {number} [enforceProtoLimits]
|
|
696
705
|
*/
|
|
697
706
|
|
|
698
707
|
var unnamedEnumIndex = 0;
|
|
@@ -735,6 +744,7 @@ function Enum_fromDescriptor(descriptor, ctx, nested) {
|
|
|
735
744
|
undefined,
|
|
736
745
|
valuesOptions
|
|
737
746
|
);
|
|
747
|
+
enm.visibility = visibilityFromDescriptor(descriptor.visibility);
|
|
738
748
|
|
|
739
749
|
if (!nested) {
|
|
740
750
|
enm._edition = ctx.edition;
|
|
@@ -776,6 +786,8 @@ Enum.prototype.toDescriptor = function toDescriptor() {
|
|
|
776
786
|
value: values,
|
|
777
787
|
options: toDescriptorOptions(this.options, exports.EnumOptions)
|
|
778
788
|
});
|
|
789
|
+
if (this.visibility)
|
|
790
|
+
descriptor.visibility = visibilityToDescriptor(this.visibility);
|
|
779
791
|
|
|
780
792
|
/* Reserved... */ if (this.reserved)
|
|
781
793
|
for (i = 0; i < this.reserved.length; ++i)
|
|
@@ -1000,6 +1012,14 @@ function applyContextFeatures(object, ctx) {
|
|
|
1000
1012
|
return object;
|
|
1001
1013
|
}
|
|
1002
1014
|
|
|
1015
|
+
function visibilityFromDescriptor(visibility) {
|
|
1016
|
+
return visibility === 1 ? "local" : visibility === 2 ? "export" : undefined;
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
function visibilityToDescriptor(visibility) {
|
|
1020
|
+
return visibility === "local" ? 1 : visibility === "export" ? 2 : 0;
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1003
1023
|
// Converts a descriptor type to a protobuf.js basic type
|
|
1004
1024
|
function fromDescriptorType(type) {
|
|
1005
1025
|
switch (type) {
|
|
@@ -1072,6 +1092,10 @@ function fromDescriptorOptionsRecursive(obj, type) {
|
|
|
1072
1092
|
if ((key = (field = type._fieldsArray[i]).name) === "uninterpretedOption") continue;
|
|
1073
1093
|
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
1074
1094
|
|
|
1095
|
+
if (key === ".pb.enumvalue.json") {
|
|
1096
|
+
val["(pb.enumvalue.json).string"] = obj[key].string === undefined ? "" : obj[key].string;
|
|
1097
|
+
continue;
|
|
1098
|
+
}
|
|
1075
1099
|
var newKey = underScore(key);
|
|
1076
1100
|
if (field.resolvedType instanceof Type) {
|
|
1077
1101
|
val[newKey] = fromDescriptorOptionsRecursive(obj[key], field.resolvedType);
|
|
@@ -1096,6 +1120,10 @@ function toDescriptorOptionsRecursive(obj, type) {
|
|
|
1096
1120
|
var keys = Object.keys(obj);
|
|
1097
1121
|
for (var i = 0; i < keys.length; ++i) {
|
|
1098
1122
|
var key = keys[i];
|
|
1123
|
+
if (type === exports.EnumValueOptions && key === "(pb.enumvalue.json).string") {
|
|
1124
|
+
val[".pb.enumvalue.json"] = { string: obj[key] };
|
|
1125
|
+
continue;
|
|
1126
|
+
}
|
|
1099
1127
|
var newKey = $protobuf.util.camelCase(key);
|
|
1100
1128
|
if (!Object.prototype.hasOwnProperty.call(type.fields, newKey)) continue;
|
|
1101
1129
|
var field = type.fields[newKey];
|
|
@@ -1158,6 +1186,8 @@ function editionFromDescriptor(fileDescriptor) {
|
|
|
1158
1186
|
return "2023";
|
|
1159
1187
|
case exports.Edition.EDITION_2024:
|
|
1160
1188
|
return "2024";
|
|
1189
|
+
case exports.Edition.EDITION_2026:
|
|
1190
|
+
return "2026";
|
|
1161
1191
|
default:
|
|
1162
1192
|
throw new Error("Unsupported edition " + fileDescriptor.edition);
|
|
1163
1193
|
}
|
|
@@ -1181,6 +1211,9 @@ function editionToDescriptor(edition, fileDescriptor) {
|
|
|
1181
1211
|
case "2024":
|
|
1182
1212
|
fileDescriptor.edition = exports.Edition.EDITION_2024;
|
|
1183
1213
|
break;
|
|
1214
|
+
case "2026":
|
|
1215
|
+
fileDescriptor.edition = exports.Edition.EDITION_2026;
|
|
1216
|
+
break;
|
|
1184
1217
|
default:
|
|
1185
1218
|
throw new Error("Unsupported edition " + edition);
|
|
1186
1219
|
}
|
package/ext/protojson.js
CHANGED
|
@@ -91,6 +91,15 @@ function invalid(name, value, what) {
|
|
|
91
91
|
return Error(name + ": " + what + ": " + JSON.stringify(value));
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
function normalizeIntegerString(str, name, what) {
|
|
95
|
+
str = str.replace(/^\+/, "").replace(/^(-?)0+(?=\d)/, "$1");
|
|
96
|
+
if (str === "-0")
|
|
97
|
+
str = "0";
|
|
98
|
+
if (str.length > 20) // max uint64 and min int64
|
|
99
|
+
throw Error(name + ": out of range for " + what);
|
|
100
|
+
return str;
|
|
101
|
+
}
|
|
102
|
+
|
|
94
103
|
function parseIntegerString(value, type, name) {
|
|
95
104
|
var str;
|
|
96
105
|
if (typeof value === "number") {
|
|
@@ -113,6 +122,7 @@ function parseIntegerString(value, type, name) {
|
|
|
113
122
|
throw invalid(name, value, "expected integer (number or string)");
|
|
114
123
|
|
|
115
124
|
var range = INT_RANGE[type];
|
|
125
|
+
str = normalizeIntegerString(str, name, type);
|
|
116
126
|
if (LONG_TYPE[type]) {
|
|
117
127
|
if (hasBigInt) {
|
|
118
128
|
var big = BigInt(str);
|
|
@@ -128,17 +138,17 @@ function parseMapIntegerKey(key, type, name) {
|
|
|
128
138
|
var unsigned = type === "uint32" || type === "fixed32" || type === "uint64" || type === "fixed64";
|
|
129
139
|
if (!(unsigned ? /^[0-9]+$/ : /^-?[0-9]+$/).test(key))
|
|
130
140
|
throw invalid(name, key, "invalid " + type + " map key");
|
|
141
|
+
var range = INT_RANGE[type];
|
|
142
|
+
key = normalizeIntegerString(key, name, type + " map key");
|
|
131
143
|
if (hasBigInt) {
|
|
132
|
-
var big = BigInt(key)
|
|
133
|
-
range = INT_RANGE[type];
|
|
144
|
+
var big = BigInt(key);
|
|
134
145
|
if (big < BigInt(range[0]) || big > BigInt(range[1]))
|
|
135
146
|
throw invalid(name, key, "out of range for " + type + " map key");
|
|
136
147
|
return big.toString();
|
|
137
148
|
}
|
|
138
149
|
parseIntegerString(key, type, name);
|
|
139
150
|
if (LONG_TYPE[type]) {
|
|
140
|
-
|
|
141
|
-
return normalized === "-0" ? "0" : normalized;
|
|
151
|
+
return key;
|
|
142
152
|
}
|
|
143
153
|
return String(Number(key));
|
|
144
154
|
}
|
|
@@ -231,11 +241,19 @@ function readScalar(type, value, name) {
|
|
|
231
241
|
}
|
|
232
242
|
}
|
|
233
243
|
|
|
244
|
+
function enumJsonName(enm, name) {
|
|
245
|
+
var options = hasOwn(enm.valuesOptions, name) && enm.valuesOptions[name];
|
|
246
|
+
return hasOwn(options, "(pb.enumvalue.json).string") ? options["(pb.enumvalue.json).string"] : undefined;
|
|
247
|
+
}
|
|
248
|
+
|
|
234
249
|
function readEnum(enm, value, name, options) {
|
|
235
250
|
if (typeof value === "string") {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
251
|
+
if (hasOwn(enm.values, value))
|
|
252
|
+
return enm.values[value];
|
|
253
|
+
if (enm.valuesOptions)
|
|
254
|
+
for (var names = Object.keys(enm.valuesOptions), i = 0; i < names.length; ++i)
|
|
255
|
+
if (hasOwn(enm.values, names[i]) && enumJsonName(enm, names[i]) === value)
|
|
256
|
+
return enm.values[names[i]];
|
|
239
257
|
if (options.ignoreUnknownFields)
|
|
240
258
|
return SKIP;
|
|
241
259
|
throw invalid(name, value, "unknown enum value");
|
|
@@ -438,7 +456,10 @@ function writeSingular(field, value, options, depth) {
|
|
|
438
456
|
if (field.resolvedType.fullName === ".google.protobuf.NullValue")
|
|
439
457
|
return null;
|
|
440
458
|
var name = field.resolvedType.valuesById[value];
|
|
441
|
-
|
|
459
|
+
if (name === undefined)
|
|
460
|
+
return value;
|
|
461
|
+
var jsonName = enumJsonName(field.resolvedType, name);
|
|
462
|
+
return jsonName === undefined ? name : jsonName;
|
|
442
463
|
}
|
|
443
464
|
return writeScalar(field.type, value);
|
|
444
465
|
}
|
package/ext/textformat.js
CHANGED
|
@@ -586,14 +586,14 @@ Parser.prototype.parseScalar = function parseScalar(field) {
|
|
|
586
586
|
};
|
|
587
587
|
|
|
588
588
|
Parser.prototype.readStringBytes = function readStringBytes() {
|
|
589
|
-
var token = this.tn.next()
|
|
590
|
-
bytes = [];
|
|
589
|
+
var token = this.tn.next();
|
|
591
590
|
if (!token || token.type !== "string")
|
|
592
591
|
this.error("expected string");
|
|
593
|
-
|
|
592
|
+
var bytes = token.value;
|
|
594
593
|
while ((token = this.tn.peek()) && token.type === "string") {
|
|
595
594
|
token = this.tn.next();
|
|
596
|
-
|
|
595
|
+
for (var i = 0; i < token.value.length; ++i)
|
|
596
|
+
bytes.push(token.value[i]);
|
|
597
597
|
}
|
|
598
598
|
return bytes;
|
|
599
599
|
};
|
|
@@ -842,6 +842,10 @@ function parseInteger(token, sign, unsigned, bits) {
|
|
|
842
842
|
} else if (!/^(?:0|[1-9][0-9]*)$/.test(raw))
|
|
843
843
|
throw Error("integer value expected");
|
|
844
844
|
|
|
845
|
+
digits = digits.replace(/^0+(?=.)/, "");
|
|
846
|
+
if (digits.length > Math.ceil(bits / 3)) // 3 bits per octal digit
|
|
847
|
+
throw Error((unsigned ? "unsigned " : "") + "integer value out of range");
|
|
848
|
+
|
|
845
849
|
if (typeof util.global.BigInt === "function")
|
|
846
850
|
return parseIntegerBigInt(digits, radix, sign, unsigned, bits);
|
|
847
851
|
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"EDITION_PROTO3": 999,
|
|
30
30
|
"EDITION_2023": 1000,
|
|
31
31
|
"EDITION_2024": 1001,
|
|
32
|
+
"EDITION_2026": 1002,
|
|
32
33
|
"EDITION_1_TEST_ONLY": 1,
|
|
33
34
|
"EDITION_2_TEST_ONLY": 2,
|
|
34
35
|
"EDITION_99997_TEST_ONLY": 99997,
|
|
@@ -970,6 +971,10 @@
|
|
|
970
971
|
}
|
|
971
972
|
},
|
|
972
973
|
"extensions": [
|
|
974
|
+
[
|
|
975
|
+
990,
|
|
976
|
+
998
|
|
977
|
+
],
|
|
973
978
|
[
|
|
974
979
|
1000,
|
|
975
980
|
536870911
|
|
@@ -1199,6 +1204,11 @@
|
|
|
1199
1204
|
"edition_defaults.edition": "EDITION_2024",
|
|
1200
1205
|
"edition_defaults.value": "EXPORT_TOP_LEVEL"
|
|
1201
1206
|
}
|
|
1207
|
+
},
|
|
1208
|
+
"enforceProtoLimits": {
|
|
1209
|
+
"type": "ProtoLimitsFeature.EnforceProtoLimits",
|
|
1210
|
+
"id": 9,
|
|
1211
|
+
"protoName": "enforce_proto_limits"
|
|
1202
1212
|
}
|
|
1203
1213
|
},
|
|
1204
1214
|
"extensions": [
|
|
@@ -1269,7 +1279,8 @@
|
|
|
1269
1279
|
"values": {
|
|
1270
1280
|
"ENFORCE_NAMING_STYLE_UNKNOWN": 0,
|
|
1271
1281
|
"STYLE2024": 1,
|
|
1272
|
-
"STYLE_LEGACY": 2
|
|
1282
|
+
"STYLE_LEGACY": 2,
|
|
1283
|
+
"STYLE2026": 3
|
|
1273
1284
|
}
|
|
1274
1285
|
},
|
|
1275
1286
|
"VisibilityFeature": {
|
|
@@ -1291,6 +1302,18 @@
|
|
|
1291
1302
|
}
|
|
1292
1303
|
}
|
|
1293
1304
|
}
|
|
1305
|
+
},
|
|
1306
|
+
"ProtoLimitsFeature": {
|
|
1307
|
+
"fields": {},
|
|
1308
|
+
"nested": {
|
|
1309
|
+
"EnforceProtoLimits": {
|
|
1310
|
+
"values": {
|
|
1311
|
+
"PROTO_LIMITS_UNKNOWN": 0,
|
|
1312
|
+
"LEGACY_NO_EXPLICIT_LIMITS": 1,
|
|
1313
|
+
"PROTO_LIMITS2026": 2
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1294
1317
|
}
|
|
1295
1318
|
}
|
|
1296
1319
|
},
|
|
@@ -17,6 +17,7 @@ enum Edition {
|
|
|
17
17
|
EDITION_PROTO3 = 999;
|
|
18
18
|
EDITION_2023 = 1000;
|
|
19
19
|
EDITION_2024 = 1001;
|
|
20
|
+
EDITION_2026 = 1002;
|
|
20
21
|
EDITION_1_TEST_ONLY = 1;
|
|
21
22
|
EDITION_2_TEST_ONLY = 2;
|
|
22
23
|
EDITION_99997_TEST_ONLY = 99997;
|
|
@@ -340,6 +341,7 @@ message EnumValueOptions {
|
|
|
340
341
|
optional FieldOptions.FeatureSupport feature_support = 4;
|
|
341
342
|
repeated UninterpretedOption uninterpreted_option = 999;
|
|
342
343
|
|
|
344
|
+
extensions 990 to 998;
|
|
343
345
|
extensions 1000 to max;
|
|
344
346
|
}
|
|
345
347
|
|
|
@@ -396,6 +398,7 @@ message FeatureSet {
|
|
|
396
398
|
optional JsonFormat json_format = 6 [retention="RETENTION_RUNTIME", targets="TARGET_TYPE_FILE", feature_support.edition_introduced="EDITION_2023", edition_defaults.edition="EDITION_PROTO3", edition_defaults.value="ALLOW"];
|
|
397
399
|
optional EnforceNamingStyle enforce_naming_style = 7 [retention="RETENTION_SOURCE", targets="TARGET_TYPE_METHOD", feature_support.edition_introduced="EDITION_2024", edition_defaults.edition="EDITION_2024", edition_defaults.value="STYLE2024"];
|
|
398
400
|
optional VisibilityFeature.DefaultSymbolVisibility default_symbol_visibility = 8 [retention="RETENTION_SOURCE", targets="TARGET_TYPE_FILE", feature_support.edition_introduced="EDITION_2024", edition_defaults.edition="EDITION_2024", edition_defaults.value="EXPORT_TOP_LEVEL"];
|
|
401
|
+
optional ProtoLimitsFeature.EnforceProtoLimits enforce_proto_limits = 9;
|
|
399
402
|
|
|
400
403
|
enum FieldPresence {
|
|
401
404
|
|
|
@@ -445,6 +448,7 @@ message FeatureSet {
|
|
|
445
448
|
ENFORCE_NAMING_STYLE_UNKNOWN = 0;
|
|
446
449
|
STYLE2024 = 1;
|
|
447
450
|
STYLE_LEGACY = 2;
|
|
451
|
+
STYLE2026 = 3;
|
|
448
452
|
}
|
|
449
453
|
|
|
450
454
|
message VisibilityFeature {
|
|
@@ -461,6 +465,16 @@ message FeatureSet {
|
|
|
461
465
|
reserved 1 to max;
|
|
462
466
|
}
|
|
463
467
|
|
|
468
|
+
message ProtoLimitsFeature {
|
|
469
|
+
|
|
470
|
+
enum EnforceProtoLimits {
|
|
471
|
+
|
|
472
|
+
PROTO_LIMITS_UNKNOWN = 0;
|
|
473
|
+
LEGACY_NO_EXPLICIT_LIMITS = 1;
|
|
474
|
+
PROTO_LIMITS2026 = 2;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
464
478
|
extensions 1000 to 9994, 9995 to 9999, 10000;
|
|
465
479
|
|
|
466
480
|
reserved 999;
|
|
@@ -524,4 +538,4 @@ enum SymbolVisibility {
|
|
|
524
538
|
VISIBILITY_UNSET = 0;
|
|
525
539
|
VISIBILITY_LOCAL = 1;
|
|
526
540
|
VISIBILITY_EXPORT = 2;
|
|
527
|
-
}
|
|
541
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"nested": {
|
|
3
|
+
"pb": {
|
|
4
|
+
"nested": {
|
|
5
|
+
"enumvalue": {
|
|
6
|
+
"options": {
|
|
7
|
+
"java_package": "com.google.protobuf.util"
|
|
8
|
+
},
|
|
9
|
+
"nested": {
|
|
10
|
+
"JsonEnumValueOptions": {
|
|
11
|
+
"edition": "2024",
|
|
12
|
+
"fields": {
|
|
13
|
+
"string": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"id": 1
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"visibility": "local"
|
|
19
|
+
},
|
|
20
|
+
"json": {
|
|
21
|
+
"edition": "2024",
|
|
22
|
+
"type": "JsonEnumValueOptions",
|
|
23
|
+
"id": 998,
|
|
24
|
+
"extend": "google.protobuf.EnumValueOptions",
|
|
25
|
+
"options": {
|
|
26
|
+
"feature_support.edition_introduced": "EDITION_2026"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"google": {
|
|
34
|
+
"nested": {
|
|
35
|
+
"protobuf": {
|
|
36
|
+
"nested": {
|
|
37
|
+
"EnumValueOptions": {
|
|
38
|
+
"edition": "proto2",
|
|
39
|
+
"fields": {},
|
|
40
|
+
"extensions": [
|
|
41
|
+
[
|
|
42
|
+
990,
|
|
43
|
+
998
|
|
44
|
+
],
|
|
45
|
+
[
|
|
46
|
+
1000,
|
|
47
|
+
536870911
|
|
48
|
+
]
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Protocol Buffers - Google's data interchange format
|
|
2
|
+
// Copyright 2026 Google LLC. All rights reserved.
|
|
3
|
+
//
|
|
4
|
+
// Use of this source code is governed by a BSD-style
|
|
5
|
+
// license that can be found in the LICENSE file or at
|
|
6
|
+
// https://developers.google.com/open-source/licenses/bsd
|
|
7
|
+
|
|
8
|
+
edition = "2024";
|
|
9
|
+
|
|
10
|
+
package pb.enumvalue;
|
|
11
|
+
|
|
12
|
+
import "google/protobuf/descriptor.proto";
|
|
13
|
+
|
|
14
|
+
option java_package = "com.google.protobuf.util";
|
|
15
|
+
|
|
16
|
+
local message JsonEnumValueOptions {
|
|
17
|
+
// Allows user to specify a custom string to use when serializing an enum
|
|
18
|
+
// value to JSON.
|
|
19
|
+
//
|
|
20
|
+
// Sample usage:
|
|
21
|
+
// enum Foo {
|
|
22
|
+
// ...
|
|
23
|
+
// FOO_BAR = 42 [(pb.enumvalue.json).string = "my_custom_name"];
|
|
24
|
+
// }
|
|
25
|
+
string string = 1;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
extend google.protobuf.EnumValueOptions {
|
|
29
|
+
JsonEnumValueOptions json = 998
|
|
30
|
+
[feature_support = { edition_introduced: EDITION_2026 }];
|
|
31
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -190,6 +190,9 @@ export class Enum extends ReflectionObject {
|
|
|
190
190
|
/** Reserved ranges, if any. */
|
|
191
191
|
reserved: (number[]|string)[];
|
|
192
192
|
|
|
193
|
+
/** Declared symbol visibility, if any. */
|
|
194
|
+
visibility?: ("local"|"export");
|
|
195
|
+
|
|
193
196
|
/**
|
|
194
197
|
* Constructs an enum from an enum descriptor.
|
|
195
198
|
* @param name Enum name
|
|
@@ -260,6 +263,9 @@ export interface IEnum {
|
|
|
260
263
|
/** Reserved ranges */
|
|
261
264
|
reserved?: (number[]|string)[];
|
|
262
265
|
|
|
266
|
+
/** Declared symbol visibility */
|
|
267
|
+
visibility?: ("local"|"export");
|
|
268
|
+
|
|
263
269
|
/** Enum comment */
|
|
264
270
|
comment?: (string|null);
|
|
265
271
|
|
|
@@ -1264,6 +1270,12 @@ export class Reader {
|
|
|
1264
1270
|
*/
|
|
1265
1271
|
tag(): number;
|
|
1266
1272
|
|
|
1273
|
+
/**
|
|
1274
|
+
* Reads a varint length prefix within signed 32 bit range.
|
|
1275
|
+
* @returns Length read
|
|
1276
|
+
*/
|
|
1277
|
+
size(): number;
|
|
1278
|
+
|
|
1267
1279
|
/**
|
|
1268
1280
|
* Reads a varint as a signed 32 bit value.
|
|
1269
1281
|
* @returns Value read
|
|
@@ -1804,6 +1816,9 @@ export class Type extends NamespaceBase {
|
|
|
1804
1816
|
/** Reserved ranges, if any. */
|
|
1805
1817
|
reserved: (number[]|string)[];
|
|
1806
1818
|
|
|
1819
|
+
/** Declared symbol visibility, if any. */
|
|
1820
|
+
visibility?: ("local"|"export");
|
|
1821
|
+
|
|
1807
1822
|
/** Message fields by id. */
|
|
1808
1823
|
readonly fieldsById: { [k: number]: Field };
|
|
1809
1824
|
|
|
@@ -1982,6 +1997,9 @@ export interface IType extends INamespace {
|
|
|
1982
1997
|
/** Whether a legacy group or not */
|
|
1983
1998
|
group?: boolean;
|
|
1984
1999
|
|
|
2000
|
+
/** Declared symbol visibility */
|
|
2001
|
+
visibility?: ("local"|"export");
|
|
2002
|
+
|
|
1985
2003
|
/** Message type comment */
|
|
1986
2004
|
comment?: (string|null);
|
|
1987
2005
|
}
|
package/package.json
CHANGED
package/src/decoder.js
CHANGED
|
@@ -46,7 +46,17 @@ function decoder(mtype) {
|
|
|
46
46
|
("if(q===undefined)q=0")
|
|
47
47
|
("if(q>Reader.recursionLimit)")
|
|
48
48
|
("throw Error(\"max depth exceeded\")")
|
|
49
|
-
("var c
|
|
49
|
+
("var c,m" + (hasMapField ? ",k,v" : needsValueVar ? ",v" : ""))
|
|
50
|
+
("if(l===undefined)")
|
|
51
|
+
("c=r.len")
|
|
52
|
+
("else{")
|
|
53
|
+
("c=r.pos+l")
|
|
54
|
+
("if(c>r.len)")
|
|
55
|
+
("throw RangeError(\"index out of range\")")
|
|
56
|
+
("l=r.len")
|
|
57
|
+
("r.len=c")
|
|
58
|
+
("}")
|
|
59
|
+
("m=g||new C")
|
|
50
60
|
("while(r.pos<c){")
|
|
51
61
|
("var s=r.pos")
|
|
52
62
|
("var t=r.tag()")
|
|
@@ -73,7 +83,10 @@ function decoder(mtype) {
|
|
|
73
83
|
("if(%s===util.emptyObject)", ref)
|
|
74
84
|
("%s={}", ref);
|
|
75
85
|
gen
|
|
76
|
-
("var c2=r.
|
|
86
|
+
("var c2=r.size()+r.pos")
|
|
87
|
+
("if(c2>r.len)")
|
|
88
|
+
("throw RangeError(\"index out of range\")")
|
|
89
|
+
("r.len=c2");
|
|
77
90
|
|
|
78
91
|
if (types.defaults[field.keyType] !== undefined) gen
|
|
79
92
|
("k=%j", types.defaults[field.keyType]);
|
|
@@ -102,7 +115,7 @@ function decoder(mtype) {
|
|
|
102
115
|
("break");
|
|
103
116
|
|
|
104
117
|
if (types.basic[type] === undefined) gen
|
|
105
|
-
("v=types[%i].decode(r,r.
|
|
118
|
+
("v=types[%i].decode(r,r.size(),undefined,q+1,v)", i); // can't be groups
|
|
106
119
|
else gen
|
|
107
120
|
("v=r.%s()", type === "string" ? stringMethod(field) : type);
|
|
108
121
|
|
|
@@ -111,6 +124,10 @@ function decoder(mtype) {
|
|
|
111
124
|
("}")
|
|
112
125
|
("r.skipType(u,q,t2)")
|
|
113
126
|
("}");
|
|
127
|
+
gen
|
|
128
|
+
("if(r.pos!==c2)")
|
|
129
|
+
("throw RangeError(\"index out of range\")")
|
|
130
|
+
("r.len=c");
|
|
114
131
|
|
|
115
132
|
if (closed) { gen
|
|
116
133
|
("if(types[%i].valuesById[v]===undefined){", i);
|
|
@@ -143,7 +160,10 @@ function decoder(mtype) {
|
|
|
143
160
|
("if(u===2){");
|
|
144
161
|
if (closed) {
|
|
145
162
|
gen
|
|
146
|
-
("var c2=r.
|
|
163
|
+
("var c2=r.size()+r.pos")
|
|
164
|
+
("if(c2>r.len)")
|
|
165
|
+
("throw RangeError(\"index out of range\")")
|
|
166
|
+
("r.len=c2")
|
|
147
167
|
("while(r.pos<c2){")
|
|
148
168
|
("s=r.pos")
|
|
149
169
|
("v=r.%s()", type)
|
|
@@ -154,6 +174,10 @@ function decoder(mtype) {
|
|
|
154
174
|
("}else");
|
|
155
175
|
genPreserveUnknown(gen, "util.rawField(" + field.id + ",0,r.raw(s,r.pos))")
|
|
156
176
|
("}");
|
|
177
|
+
gen
|
|
178
|
+
("if(r.pos!==c2)")
|
|
179
|
+
("throw RangeError(\"index out of range\")")
|
|
180
|
+
("r.len=c");
|
|
157
181
|
} else gen
|
|
158
182
|
("if(!(%s&&%s.length))", ref, ref)
|
|
159
183
|
("%s=[]", ref)
|
|
@@ -174,7 +198,7 @@ function decoder(mtype) {
|
|
|
174
198
|
if (field.delimited) gen
|
|
175
199
|
("%s.push(types[%i].decode(r,undefined,%i,q+1))", ref, i, field.id * 8 + 4);
|
|
176
200
|
else gen
|
|
177
|
-
("%s.push(types[%i].decode(r,r.
|
|
201
|
+
("%s.push(types[%i].decode(r,r.size(),undefined,q+1))", ref, i);
|
|
178
202
|
} else if (closed) { gen
|
|
179
203
|
("v=r.%s()", type)
|
|
180
204
|
("if(types[%i].valuesById[v]!==undefined){", i)
|
|
@@ -195,7 +219,7 @@ function decoder(mtype) {
|
|
|
195
219
|
if (field.delimited) gen
|
|
196
220
|
("%s=types[%i].decode(r,undefined,%i,q+1,%s)", ref, i, field.id * 8 + 4, ref);
|
|
197
221
|
else gen
|
|
198
|
-
("%s=types[%i].decode(r,r.
|
|
222
|
+
("%s=types[%i].decode(r,r.size(),undefined,q+1,%s)", ref, i, ref);
|
|
199
223
|
}
|
|
200
224
|
else if (field.hasPresence) {
|
|
201
225
|
gen
|
|
@@ -262,6 +286,11 @@ function decoder(mtype) {
|
|
|
262
286
|
("r.skipType(%s,q,t)", i ? "u" : "t&7");
|
|
263
287
|
genPreserveUnknown(gen, "r.raw(s,r.pos)")
|
|
264
288
|
("}")
|
|
289
|
+
("if(l!==undefined){")
|
|
290
|
+
("if(r.pos!==c)")
|
|
291
|
+
("throw RangeError(\"index out of range\")")
|
|
292
|
+
("r.len=l")
|
|
293
|
+
("}")
|
|
265
294
|
("if(z!==undefined)")
|
|
266
295
|
("throw Error(\"missing end group\")");
|
|
267
296
|
|
package/src/enum.js
CHANGED
|
@@ -76,6 +76,12 @@ function Enum(name, values, options, comment, comments, valuesOptions) {
|
|
|
76
76
|
*/
|
|
77
77
|
this.reserved = undefined; // toJSON
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Declared symbol visibility, if any.
|
|
81
|
+
* @type {"local"|"export"|undefined}
|
|
82
|
+
*/
|
|
83
|
+
this.visibility = undefined; // toJSON
|
|
84
|
+
|
|
79
85
|
// Note that values inherit valuesById on their prototype which makes them a TypeScript-
|
|
80
86
|
// compatible enum. This is used by pbts to write actual enum definitions that work for
|
|
81
87
|
// static and reflection code alike instead of emitting generic object definitions.
|
|
@@ -112,6 +118,7 @@ Enum.prototype._resolveFeatures = function _resolveFeatures(edition) {
|
|
|
112
118
|
* @property {Object.<string,*>} [options] Enum options
|
|
113
119
|
* @property {Object.<string,Object.<string,*>>} [valuesOptions] Enum value options
|
|
114
120
|
* @property {Array.<number[]|string>} [reserved] Reserved ranges
|
|
121
|
+
* @property {"local"|"export"} [visibility] Declared symbol visibility
|
|
115
122
|
* @property {string|null} [comment] Enum comment
|
|
116
123
|
* @property {Object.<string,string|null>} [comments] Value comments
|
|
117
124
|
*/
|
|
@@ -126,6 +133,8 @@ Enum.prototype._resolveFeatures = function _resolveFeatures(edition) {
|
|
|
126
133
|
Enum.fromJSON = function fromJSON(name, json) {
|
|
127
134
|
var enm = new Enum(name, json.values, json.options, json.comment, json.comments, json.valuesOptions);
|
|
128
135
|
enm.reserved = json.reserved;
|
|
136
|
+
if (json.visibility)
|
|
137
|
+
enm.visibility = json.visibility;
|
|
129
138
|
if (json.edition)
|
|
130
139
|
enm._edition = json.edition;
|
|
131
140
|
enm._defaultEdition = "proto3"; // For backwards-compatibility.
|
|
@@ -145,6 +154,7 @@ Enum.prototype.toJSON = function toJSON(toJSONOptions) {
|
|
|
145
154
|
"valuesOptions" , this.valuesOptions,
|
|
146
155
|
"values" , this.values,
|
|
147
156
|
"reserved" , this.reserved && this.reserved.length ? this.reserved : undefined,
|
|
157
|
+
"visibility" , this.visibility,
|
|
148
158
|
"comment" , keepComments ? this.comment : undefined,
|
|
149
159
|
"comments" , keepComments ? this.comments : undefined
|
|
150
160
|
]);
|