protobufjs 5.0.0 → 5.0.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/bower.json +1 -1
- package/cli/pbjs/targets/json.js +1 -1
- package/cli/pbjs/targets/proto.js +10 -2
- package/dist/protobuf-light.js +38 -21
- package/dist/protobuf-light.min.js +78 -78
- package/dist/protobuf-light.min.js.gz +0 -0
- package/dist/protobuf-light.min.map +2 -2
- package/dist/protobuf.js +81 -55
- package/dist/protobuf.min.js +92 -92
- package/dist/protobuf.min.js.gz +0 -0
- package/dist/protobuf.min.map +2 -2
- package/docs/ProtoBuf.Builder.Message.html +106 -37
- package/docs/ProtoBuf.Builder.Service.html +9 -9
- package/docs/ProtoBuf.Builder.html +22 -22
- package/docs/ProtoBuf.DotProto.Parser.html +3 -3
- package/docs/ProtoBuf.DotProto.Tokenizer.html +1 -1
- package/docs/ProtoBuf.DotProto.html +1 -1
- package/docs/ProtoBuf.Map.html +6 -6
- package/docs/ProtoBuf.Reflect.Element.html +7 -7
- package/docs/ProtoBuf.Reflect.Enum.Value.html +10 -10
- package/docs/ProtoBuf.Reflect.Enum.html +21 -21
- package/docs/ProtoBuf.Reflect.Extension.html +3 -3
- package/docs/ProtoBuf.Reflect.Message.ExtensionField.html +29 -29
- package/docs/ProtoBuf.Reflect.Message.Field.html +28 -28
- package/docs/ProtoBuf.Reflect.Message.OneOf.html +10 -10
- package/docs/ProtoBuf.Reflect.Message.html +31 -28
- package/docs/ProtoBuf.Reflect.Namespace.html +19 -19
- package/docs/ProtoBuf.Reflect.Service.Method.html +11 -11
- package/docs/ProtoBuf.Reflect.Service.RPCMethod.html +17 -17
- package/docs/ProtoBuf.Reflect.Service.html +20 -20
- package/docs/ProtoBuf.Reflect.T.html +9 -9
- package/docs/ProtoBuf.Reflect.html +2 -2
- package/docs/ProtoBuf.Util.html +1 -1
- package/docs/ProtoBuf.html +8 -8
- package/docs/ProtoBuf.js.html +82 -56
- package/docs/index.html +1 -1
- package/externs/protobuf.js +2 -1
- package/package.json +1 -1
- package/src/ProtoBuf/Builder/Message.js +8 -3
- package/src/ProtoBuf/Builder/Service.js +3 -0
- package/src/ProtoBuf/Builder.js +15 -8
- package/src/ProtoBuf/DotProto/Parser.js +43 -34
- package/src/ProtoBuf/Reflect/Element.js +4 -3
- package/src/ProtoBuf/Reflect/Message/Field.js +4 -3
- package/src/ProtoBuf/Reflect/Message.js +3 -3
- package/src/google/protobuf/descriptor.json +28 -14
- package/tests/imports-weak.proto +7 -0
- package/tests/suite.js +63 -83
- package/tests/gtfs-realtime.proto +0 -552
package/dist/protobuf.js
CHANGED
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
* @const
|
|
58
58
|
* @expose
|
|
59
59
|
*/
|
|
60
|
-
ProtoBuf.VERSION = "5.0.
|
|
60
|
+
ProtoBuf.VERSION = "5.0.1";
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* Wire types.
|
|
@@ -725,7 +725,8 @@
|
|
|
725
725
|
// "syntax": undefined
|
|
726
726
|
};
|
|
727
727
|
var token,
|
|
728
|
-
head = true
|
|
728
|
+
head = true,
|
|
729
|
+
weak;
|
|
729
730
|
try {
|
|
730
731
|
while (token = this.tn.next()) {
|
|
731
732
|
switch (token) {
|
|
@@ -742,11 +743,12 @@
|
|
|
742
743
|
if (!head)
|
|
743
744
|
throw Error("unexpected 'import'");
|
|
744
745
|
token = this.tn.peek();
|
|
745
|
-
if (token === "public") // ignored
|
|
746
|
+
if (token === "public" || (weak = token === "weak")) // token ignored
|
|
746
747
|
this.tn.next();
|
|
747
748
|
token = this._readString();
|
|
748
749
|
this.tn.skip(";");
|
|
749
|
-
|
|
750
|
+
if (!weak) // import ignored
|
|
751
|
+
topLevel["imports"].push(token);
|
|
750
752
|
break;
|
|
751
753
|
case 'syntax':
|
|
752
754
|
if (!head)
|
|
@@ -1101,11 +1103,11 @@
|
|
|
1101
1103
|
else if (token === "service")
|
|
1102
1104
|
this._parseService(msg);
|
|
1103
1105
|
else if (token === "extensions")
|
|
1104
|
-
this.
|
|
1106
|
+
msg["extensions"] = this._parseExtensionRanges();
|
|
1107
|
+
else if (token === "reserved")
|
|
1108
|
+
this._parseIgnored(); // TODO
|
|
1105
1109
|
else if (token === "extend")
|
|
1106
1110
|
this._parseExtend(msg);
|
|
1107
|
-
else if (token === "reserved")
|
|
1108
|
-
this._parseMessageReserved(msg);
|
|
1109
1111
|
else if (Lang.TYPEREF.test(token)) {
|
|
1110
1112
|
if (!this.proto3)
|
|
1111
1113
|
throw Error("illegal field rule: "+token);
|
|
@@ -1119,17 +1121,10 @@
|
|
|
1119
1121
|
};
|
|
1120
1122
|
|
|
1121
1123
|
/**
|
|
1122
|
-
* Parses
|
|
1123
|
-
* @param {!Object} msg Message definition
|
|
1124
|
+
* Parses an ignored statement.
|
|
1124
1125
|
* @private
|
|
1125
1126
|
*/
|
|
1126
|
-
ParserPrototype.
|
|
1127
|
-
// TODO: This currently just skips a reserved statement for compatibility.
|
|
1128
|
-
// Valid formats are
|
|
1129
|
-
// reserved 2, 15, 9 to 11;
|
|
1130
|
-
// for reserved ids or
|
|
1131
|
-
// reserved "foo", "bar";
|
|
1132
|
-
// for reserved names.
|
|
1127
|
+
ParserPrototype._parseIgnored = function() {
|
|
1133
1128
|
while (this.tn.peek() !== ';')
|
|
1134
1129
|
this.tn.next();
|
|
1135
1130
|
this.tn.skip(";");
|
|
@@ -1297,29 +1292,43 @@
|
|
|
1297
1292
|
};
|
|
1298
1293
|
|
|
1299
1294
|
/**
|
|
1300
|
-
* Parses
|
|
1301
|
-
* @
|
|
1295
|
+
* Parses extension / reserved ranges.
|
|
1296
|
+
* @returns {!Array.<!Array.<number>>}
|
|
1302
1297
|
* @private
|
|
1303
1298
|
*/
|
|
1304
|
-
ParserPrototype.
|
|
1305
|
-
var
|
|
1299
|
+
ParserPrototype._parseExtensionRanges = function() {
|
|
1300
|
+
var ranges = [];
|
|
1301
|
+
var token,
|
|
1302
|
+
range,
|
|
1303
|
+
value;
|
|
1304
|
+
do {
|
|
1306
1305
|
range = [];
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1306
|
+
while (true) {
|
|
1307
|
+
token = this.tn.next();
|
|
1308
|
+
switch (token) {
|
|
1309
|
+
case "min":
|
|
1310
|
+
value = ProtoBuf.ID_MIN;
|
|
1311
|
+
break;
|
|
1312
|
+
case "max":
|
|
1313
|
+
value = ProtoBuf.ID_MAX;
|
|
1314
|
+
break;
|
|
1315
|
+
default:
|
|
1316
|
+
value = mkNumber(token);
|
|
1317
|
+
break;
|
|
1318
|
+
}
|
|
1319
|
+
range.push(value);
|
|
1320
|
+
if (range.length === 2)
|
|
1321
|
+
break;
|
|
1322
|
+
if (this.tn.peek() !== "to") {
|
|
1323
|
+
range.push(value);
|
|
1324
|
+
break;
|
|
1325
|
+
}
|
|
1326
|
+
this.tn.next();
|
|
1327
|
+
}
|
|
1328
|
+
ranges.push(range);
|
|
1329
|
+
} while (this.tn.omit(","));
|
|
1321
1330
|
this.tn.skip(";");
|
|
1322
|
-
|
|
1331
|
+
return ranges;
|
|
1323
1332
|
};
|
|
1324
1333
|
|
|
1325
1334
|
/**
|
|
@@ -1787,9 +1796,10 @@
|
|
|
1787
1796
|
* @expose
|
|
1788
1797
|
*/
|
|
1789
1798
|
ElementPrototype.verifyValue = function(value) {
|
|
1790
|
-
var
|
|
1791
|
-
|
|
1792
|
-
|
|
1799
|
+
var self = this;
|
|
1800
|
+
function fail(val, msg) {
|
|
1801
|
+
throw Error("Illegal value for "+self.toString(true)+" of type "+self.type.name+": "+val+" ("+msg+")");
|
|
1802
|
+
}
|
|
1793
1803
|
switch (this.type) {
|
|
1794
1804
|
// Signed 32bit
|
|
1795
1805
|
case ProtoBuf.TYPES["int32"]:
|
|
@@ -2279,10 +2289,10 @@
|
|
|
2279
2289
|
|
|
2280
2290
|
/**
|
|
2281
2291
|
* Extensions range.
|
|
2282
|
-
* @type {!Array.<number
|
|
2292
|
+
* @type {!Array.<number>|undefined}
|
|
2283
2293
|
* @expose
|
|
2284
2294
|
*/
|
|
2285
|
-
this.extensions =
|
|
2295
|
+
this.extensions = undefined;
|
|
2286
2296
|
|
|
2287
2297
|
/**
|
|
2288
2298
|
* Runtime message class.
|
|
@@ -2681,18 +2691,19 @@
|
|
|
2681
2691
|
* @name ProtoBuf.Builder.Message#encodeDelimited
|
|
2682
2692
|
* @function
|
|
2683
2693
|
* @param {(!ByteBuffer|boolean)=} buffer ByteBuffer to encode to. Will create a new one and flip it if omitted.
|
|
2694
|
+
* @param {boolean=} noVerify Whether to not verify field values, defaults to `false`
|
|
2684
2695
|
* @return {!ByteBuffer} Encoded message as a ByteBuffer
|
|
2685
2696
|
* @throws {Error} If the message cannot be encoded or if required fields are missing. The later still
|
|
2686
2697
|
* returns the encoded ByteBuffer in the `encoded` property on the error.
|
|
2687
2698
|
* @expose
|
|
2688
2699
|
*/
|
|
2689
|
-
MessagePrototype.encodeDelimited = function(buffer) {
|
|
2700
|
+
MessagePrototype.encodeDelimited = function(buffer, noVerify) {
|
|
2690
2701
|
var isNew = false;
|
|
2691
2702
|
if (!buffer)
|
|
2692
2703
|
buffer = new ByteBuffer(),
|
|
2693
2704
|
isNew = true;
|
|
2694
2705
|
var enc = new ByteBuffer().LE();
|
|
2695
|
-
T.encode(this, enc).flip();
|
|
2706
|
+
T.encode(this, enc, noVerify).flip();
|
|
2696
2707
|
buffer.writeVarint32(enc.remaining());
|
|
2697
2708
|
buffer.append(enc);
|
|
2698
2709
|
return isNew ? buffer.flip() : buffer;
|
|
@@ -2901,6 +2912,7 @@
|
|
|
2901
2912
|
* @name ProtoBuf.Builder.Message.decode
|
|
2902
2913
|
* @function
|
|
2903
2914
|
* @param {!ByteBuffer|!ArrayBuffer|!Buffer|string} buffer Buffer to decode from
|
|
2915
|
+
* @param {(number|string)=} length Message length. Defaults to decode all the remainig data.
|
|
2904
2916
|
* @param {string=} enc Encoding if buffer is a string: hex, utf8 (not recommended), defaults to base64
|
|
2905
2917
|
* @return {!ProtoBuf.Builder.Message} Decoded message
|
|
2906
2918
|
* @throws {Error} If the message cannot be decoded or if required fields are missing. The later still
|
|
@@ -2909,7 +2921,10 @@
|
|
|
2909
2921
|
* @see ProtoBuf.Builder.Message.decode64
|
|
2910
2922
|
* @see ProtoBuf.Builder.Message.decodeHex
|
|
2911
2923
|
*/
|
|
2912
|
-
Message.decode = function(buffer, enc) {
|
|
2924
|
+
Message.decode = function(buffer, length, enc) {
|
|
2925
|
+
if (typeof length === 'string')
|
|
2926
|
+
enc = length,
|
|
2927
|
+
length = -1;
|
|
2913
2928
|
if (typeof buffer === 'string')
|
|
2914
2929
|
buffer = ByteBuffer.wrap(buffer, enc ? enc : "base64");
|
|
2915
2930
|
buffer = ByteBuffer.isByteBuffer(buffer) ? buffer : ByteBuffer.wrap(buffer); // May throw
|
|
@@ -3170,7 +3185,7 @@
|
|
|
3170
3185
|
/**
|
|
3171
3186
|
* Decodes an encoded message and returns the decoded message.
|
|
3172
3187
|
* @param {ByteBuffer} buffer ByteBuffer to decode from
|
|
3173
|
-
* @param {number=} length Message length. Defaults to decode all
|
|
3188
|
+
* @param {number=} length Message length. Defaults to decode all remaining data.
|
|
3174
3189
|
* @param {number=} expectedGroupEndId Expected GROUPEND id if this is a legacy group
|
|
3175
3190
|
* @return {ProtoBuf.Builder.Message} Decoded message
|
|
3176
3191
|
* @throws {Error} If the message cannot be decoded
|
|
@@ -3420,9 +3435,10 @@
|
|
|
3420
3435
|
*/
|
|
3421
3436
|
FieldPrototype.verifyValue = function(value, skipRepeated) {
|
|
3422
3437
|
skipRepeated = skipRepeated || false;
|
|
3423
|
-
var
|
|
3424
|
-
|
|
3425
|
-
|
|
3438
|
+
var self = this;
|
|
3439
|
+
function fail(val, msg) {
|
|
3440
|
+
throw Error("Illegal value for "+self.toString(true)+" of type "+self.type.name+": "+val+" ("+msg+")");
|
|
3441
|
+
}
|
|
3426
3442
|
if (value === null) { // NULL values for optional fields
|
|
3427
3443
|
if (this.required)
|
|
3428
3444
|
fail(typeof value, "required");
|
|
@@ -4036,6 +4052,9 @@
|
|
|
4036
4052
|
callback(err);
|
|
4037
4053
|
return;
|
|
4038
4054
|
}
|
|
4055
|
+
// Coalesce to empty string when service response has empty content
|
|
4056
|
+
if (res === null)
|
|
4057
|
+
res = ''
|
|
4039
4058
|
try { res = method.resolvedResponseType.clazz.decode(res); } catch (notABuffer) {}
|
|
4040
4059
|
if (!res || !(res instanceof method.resolvedResponseType.clazz)) {
|
|
4041
4060
|
callback(Error("Illegal response type received in service method "+ T.name+"#"+method.name));
|
|
@@ -4479,13 +4498,12 @@
|
|
|
4479
4498
|
subObj.push(svc);
|
|
4480
4499
|
});
|
|
4481
4500
|
|
|
4482
|
-
// Set extension
|
|
4501
|
+
// Set extension ranges
|
|
4483
4502
|
if (def["extensions"]) {
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
obj.extensions[1] = ProtoBuf.ID_MAX;
|
|
4503
|
+
if (typeof def["extensions"][0] === 'number') // pre 5.0.1
|
|
4504
|
+
obj.extensions = [ def["extensions"] ];
|
|
4505
|
+
else
|
|
4506
|
+
obj.extensions = def["extensions"];
|
|
4489
4507
|
}
|
|
4490
4508
|
|
|
4491
4509
|
// Create on top of current namespace
|
|
@@ -4524,8 +4542,16 @@
|
|
|
4524
4542
|
def["fields"].forEach(function(fld) {
|
|
4525
4543
|
if (obj.getChild(fld['id']|0) !== null)
|
|
4526
4544
|
throw Error("duplicate extended field id in "+obj.name+": "+fld['id']);
|
|
4527
|
-
if
|
|
4528
|
-
|
|
4545
|
+
// Check if field id is allowed to be extended
|
|
4546
|
+
if (obj.extensions) {
|
|
4547
|
+
var valid = false;
|
|
4548
|
+
obj.extensions.forEach(function(range) {
|
|
4549
|
+
if (fld["id"] >= range[0] && fld["id"] <= range[1])
|
|
4550
|
+
valid = true;
|
|
4551
|
+
});
|
|
4552
|
+
if (!valid)
|
|
4553
|
+
throw Error("illegal extended field id in "+obj.name+": "+fld['id']+" (not within valid ranges)");
|
|
4554
|
+
}
|
|
4529
4555
|
// Convert extension field names to camel case notation if the override is set
|
|
4530
4556
|
var name = fld["name"];
|
|
4531
4557
|
if (this.options['convertFieldsToCamelCase'])
|