protobufjs 4.1.2 → 5.0.2
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/.travis.yml +3 -1
- package/README.md +147 -25
- package/bin/pbjs +2 -2
- package/bower.json +3 -3
- package/cli/pbjs/targets/amd.js +1 -1
- package/cli/pbjs/targets/json.js +9 -1
- package/cli/pbjs/targets/proto.js +48 -24
- package/cli/pbjs/util.js +1 -1
- package/cli/pbjs.js +9 -2
- package/dist/README.md +10 -10
- package/dist/{ProtoBuf-light.js → protobuf-light.js} +207 -152
- package/dist/protobuf-light.min.js +94 -0
- package/dist/protobuf-light.min.js.gz +0 -0
- package/dist/protobuf-light.min.map +8 -0
- package/dist/{ProtoBuf.js → protobuf.js} +265 -175
- package/dist/protobuf.min.js +116 -0
- package/dist/protobuf.min.js.gz +0 -0
- package/dist/protobuf.min.map +8 -0
- package/docs/ProtoBuf.Builder.Message.html +1473 -967
- package/docs/ProtoBuf.Builder.Service.html +266 -197
- package/docs/ProtoBuf.Builder.html +758 -542
- package/docs/ProtoBuf.DotProto.Parser.html +223 -161
- package/docs/ProtoBuf.DotProto.Tokenizer.html +344 -248
- package/docs/ProtoBuf.DotProto.html +20 -12
- package/docs/ProtoBuf.Element.html +554 -554
- package/docs/ProtoBuf.Map.html +158 -123
- package/docs/ProtoBuf.Reflect.Element.html +286 -143
- package/docs/ProtoBuf.Reflect.Enum.Value.html +329 -228
- package/docs/ProtoBuf.Reflect.Enum.html +757 -537
- package/docs/ProtoBuf.Reflect.Extension.html +73 -56
- package/docs/ProtoBuf.Reflect.Message.ExtensionField.html +1013 -740
- package/docs/ProtoBuf.Reflect.Message.Field.html +926 -649
- package/docs/ProtoBuf.Reflect.Message.OneOf.html +327 -245
- package/docs/ProtoBuf.Reflect.Message.html +919 -652
- package/docs/ProtoBuf.Reflect.Namespace.html +648 -447
- package/docs/ProtoBuf.Reflect.Service.Method.html +363 -251
- package/docs/ProtoBuf.Reflect.Service.RPCMethod.html +545 -397
- package/docs/ProtoBuf.Reflect.Service.html +721 -511
- package/docs/ProtoBuf.Reflect.T.html +268 -197
- package/docs/ProtoBuf.Reflect.html +20 -12
- package/docs/ProtoBuf.Util.html +169 -118
- package/docs/ProtoBuf.html +840 -628
- package/docs/ProtoBuf.js.html +271 -180
- package/docs/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Bold-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Italic-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Light-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Light-webfont.svg +1831 -0
- package/docs/fonts/OpenSans-Light-webfont.woff +0 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Regular-webfont.svg +1831 -0
- package/docs/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/docs/index.html +7 -5
- package/docs/styles/jsdoc-default.css +95 -75
- package/docs/styles/prettify-tomorrow.css +1 -1
- package/donate.png +0 -0
- package/examples/protoify/json.js +123 -123
- package/examples/protoify/json.json +123 -123
- package/examples/websocket/server.js +4 -4
- package/externs/{ProtoBuf.js → protobuf.js} +933 -922
- package/index.js +1 -18
- package/jsdoc.json +1 -1
- package/package.json +11 -11
- package/protobuf.png +0 -0
- package/scripts/build.js +53 -58
- package/src/ProtoBuf/Builder/Message.js +18 -9
- package/src/ProtoBuf/Builder/Service.js +3 -0
- package/src/ProtoBuf/Builder.js +34 -10
- package/src/ProtoBuf/DotProto/Parser.js +58 -23
- package/src/ProtoBuf/Reflect/Element.js +17 -4
- package/src/ProtoBuf/Reflect/Message/Field.js +6 -5
- package/src/ProtoBuf/Reflect/Message.js +9 -4
- package/src/ProtoBuf/Util.js +116 -116
- package/src/bower.json +2 -2
- package/src/google/protobuf/descriptor.json +55 -15
- package/src/{ProtoBuf.js → protobuf.js} +0 -0
- package/src/wrap.js +4 -4
- package/tests/bench.txt +373 -373
- package/tests/complex.json +8 -1
- package/tests/custom-options.json +169 -169
- package/tests/extend.json +71 -71
- package/tests/imports-weak.proto +7 -0
- package/tests/imports.json +83 -83
- package/tests/nodeunit-browser/nodeunit.css +70 -70
- package/tests/nodeunit-browser/nodeunit.js +2108 -2108
- package/tests/options.json +32 -32
- package/tests/proto2js/Bar.json +46 -46
- package/tests/suite.js +107 -82
- package/ProtoBuf.png +0 -0
- package/dist/ProtoBuf-light.min.js +0 -87
- package/dist/ProtoBuf-light.min.js.gz +0 -0
- package/dist/ProtoBuf-light.min.map +0 -8
- package/dist/ProtoBuf.min.js +0 -108
- package/dist/ProtoBuf.min.js.gz +0 -0
- package/dist/ProtoBuf.min.map +0 -8
- package/externs/ByteBuffer.js +0 -767
- package/externs/Long.js +0 -328
- package/sandbox/gapi/googleapis/google/api/annotations.proto +0 -29
- package/sandbox/gapi/googleapis/google/api/http.proto +0 -245
- package/sandbox/gapi/googleapis/google/datastore/v1beta3/datastore.proto +0 -281
- package/sandbox/gapi/googleapis/google/datastore/v1beta3/entity.proto +0 -189
- package/sandbox/gapi/googleapis/google/datastore/v1beta3/query.proto +0 -281
- package/sandbox/gapi/googleapis/google/longrunning/operations.proto +0 -144
- package/sandbox/gapi/googleapis/google/protobuf/any.proto +0 -98
- package/sandbox/gapi/googleapis/google/protobuf/any_test.proto +0 -41
- package/sandbox/gapi/googleapis/google/protobuf/api.proto +0 -201
- package/sandbox/gapi/googleapis/google/protobuf/descriptor.proto +0 -773
- package/sandbox/gapi/googleapis/google/protobuf/duration.proto +0 -95
- package/sandbox/gapi/googleapis/google/protobuf/empty.proto +0 -50
- package/sandbox/gapi/googleapis/google/protobuf/field_mask.proto +0 -167
- package/sandbox/gapi/googleapis/google/protobuf/map_lite_unittest.proto +0 -130
- package/sandbox/gapi/googleapis/google/protobuf/map_proto2_unittest.proto +0 -60
- package/sandbox/gapi/googleapis/google/protobuf/map_unittest.proto +0 -129
- package/sandbox/gapi/googleapis/google/protobuf/map_unittest_proto3.proto +0 -120
- package/sandbox/gapi/googleapis/google/protobuf/source_context.proto +0 -47
- package/sandbox/gapi/googleapis/google/protobuf/struct.proto +0 -94
- package/sandbox/gapi/googleapis/google/protobuf/timestamp.proto +0 -107
- package/sandbox/gapi/googleapis/google/protobuf/type.proto +0 -176
- package/sandbox/gapi/googleapis/google/protobuf/unittest.proto +0 -878
- package/sandbox/gapi/googleapis/google/protobuf/unittest_arena.proto +0 -46
- package/sandbox/gapi/googleapis/google/protobuf/unittest_custom_options.proto +0 -394
- package/sandbox/gapi/googleapis/google/protobuf/unittest_drop_unknown_fields.proto +0 -58
- package/sandbox/gapi/googleapis/google/protobuf/unittest_embed_optimize_for.proto +0 -51
- package/sandbox/gapi/googleapis/google/protobuf/unittest_empty.proto +0 -38
- package/sandbox/gapi/googleapis/google/protobuf/unittest_enormous_descriptor.proto +0 -1048
- package/sandbox/gapi/googleapis/google/protobuf/unittest_import.proto +0 -66
- package/sandbox/gapi/googleapis/google/protobuf/unittest_import_lite.proto +0 -52
- package/sandbox/gapi/googleapis/google/protobuf/unittest_import_proto3.proto +0 -68
- package/sandbox/gapi/googleapis/google/protobuf/unittest_import_public.proto +0 -41
- package/sandbox/gapi/googleapis/google/protobuf/unittest_import_public_lite.proto +0 -43
- package/sandbox/gapi/googleapis/google/protobuf/unittest_import_public_proto3.proto +0 -42
- package/sandbox/gapi/googleapis/google/protobuf/unittest_lite.proto +0 -385
- package/sandbox/gapi/googleapis/google/protobuf/unittest_lite_imports_nonlite.proto +0 -44
- package/sandbox/gapi/googleapis/google/protobuf/unittest_mset.proto +0 -82
- package/sandbox/gapi/googleapis/google/protobuf/unittest_mset_wire_format.proto +0 -52
- package/sandbox/gapi/googleapis/google/protobuf/unittest_no_arena.proto +0 -202
- package/sandbox/gapi/googleapis/google/protobuf/unittest_no_arena_import.proto +0 -37
- package/sandbox/gapi/googleapis/google/protobuf/unittest_no_arena_lite.proto +0 -42
- package/sandbox/gapi/googleapis/google/protobuf/unittest_no_field_presence.proto +0 -138
- package/sandbox/gapi/googleapis/google/protobuf/unittest_no_generic_services.proto +0 -54
- package/sandbox/gapi/googleapis/google/protobuf/unittest_optimize_for.proto +0 -67
- package/sandbox/gapi/googleapis/google/protobuf/unittest_preserve_unknown_enum.proto +0 -71
- package/sandbox/gapi/googleapis/google/protobuf/unittest_preserve_unknown_enum2.proto +0 -50
- package/sandbox/gapi/googleapis/google/protobuf/unittest_proto3.proto +0 -388
- package/sandbox/gapi/googleapis/google/protobuf/unittest_proto3_arena.proto +0 -206
- package/sandbox/gapi/googleapis/google/protobuf/unittest_well_known_types.proto +0 -112
- package/sandbox/gapi/googleapis/google/protobuf/unknown_enum_test.proto +0 -62
- package/sandbox/gapi/googleapis/google/protobuf/wrappers.proto +0 -117
- package/sandbox/gapi/googleapis/google/rpc/code.proto +0 -190
- package/sandbox/gapi/googleapis/google/rpc/error_details.proto +0 -157
- package/sandbox/gapi/googleapis/google/rpc/status.proto +0 -90
- package/sandbox/gapi/googleapis/google/type/color.proto +0 -163
- package/sandbox/gapi/googleapis/google/type/date.proto +0 -43
- package/sandbox/gapi/googleapis/google/type/dayofweek.proto +0 -50
- package/sandbox/gapi/googleapis/google/type/latlng.proto +0 -36
- package/sandbox/gapi/googleapis/google/type/money.proto +0 -40
- package/sandbox/gapi/googleapis/google/type/timeofday.proto +0 -42
- package/sandbox/gapi/test.js +0 -17
- package/sandbox/gapi/test.proto +0 -12
- package/sandbox/issue146/MyOptions.proto +0 -28
- package/sandbox/issue146/Sample.proto +0 -21
- package/sandbox/issue146/main.js +0 -3
- package/sandbox/issue147/enum.proto +0 -8
- package/sandbox/issue147/main.js +0 -3
- package/sandbox/issue182/commands.proto +0 -10
- package/sandbox/issue182/execute.js +0 -22
- package/sandbox/issue182/session_commands.proto +0 -14
- package/sandbox/issue289/A.proto +0 -8
- package/sandbox/issue289/B.proto +0 -8
- package/sandbox/issue289/common.proto +0 -5
- package/sandbox/issue289/main.js +0 -7
- package/sandbox/issue300/IAuth.proto +0 -14
- package/sandbox/issue300/Request.proto +0 -14
- package/sandbox/issue300/main.js +0 -26
- package/sandbox/issue42/innerextend.proto +0 -18
- package/sandbox/issue42/main.js +0 -8
- package/sandbox/issue42/outerextend.proto +0 -17
- package/tests/gtfs-realtime.proto +0 -552
- package/webpack.config.js +0 -9
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* @license
|
|
18
|
+
* @license protobuf.js (c) 2013 Daniel Wirtz <dcode@dcode.io>
|
|
19
19
|
* Released under the Apache License, Version 2.0
|
|
20
|
-
* see: https://github.com/dcodeIO/
|
|
20
|
+
* see: https://github.com/dcodeIO/protobuf.js for details
|
|
21
21
|
*/
|
|
22
22
|
(function(global, factory) {
|
|
23
23
|
|
|
24
24
|
/* AMD */ if (typeof define === 'function' && define["amd"])
|
|
25
|
-
define(["
|
|
25
|
+
define(["bytebuffer"], factory);
|
|
26
26
|
/* CommonJS */ else if (typeof require === "function" && typeof module === "object" && module && module["exports"])
|
|
27
27
|
module["exports"] = factory(require("bytebuffer"), true);
|
|
28
28
|
/* Global */ else
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
* @const
|
|
58
58
|
* @expose
|
|
59
59
|
*/
|
|
60
|
-
ProtoBuf.VERSION = "
|
|
60
|
+
ProtoBuf.VERSION = "5.0.2";
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* Wire types.
|
|
@@ -289,122 +289,122 @@
|
|
|
289
289
|
*/
|
|
290
290
|
ProtoBuf.populateDefaults = true;
|
|
291
291
|
|
|
292
|
-
/**
|
|
293
|
-
* @alias ProtoBuf.Util
|
|
294
|
-
* @expose
|
|
295
|
-
*/
|
|
296
|
-
ProtoBuf.Util = (function() {
|
|
297
|
-
"use strict";
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* ProtoBuf utilities.
|
|
301
|
-
* @exports ProtoBuf.Util
|
|
302
|
-
* @namespace
|
|
303
|
-
*/
|
|
304
|
-
var Util = {};
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
* Flag if running in node or not.
|
|
308
|
-
* @type {boolean}
|
|
309
|
-
* @const
|
|
310
|
-
* @expose
|
|
311
|
-
*/
|
|
312
|
-
Util.IS_NODE = !!(
|
|
313
|
-
typeof process === 'object' && process+'' === '[object process]' && !process['browser']
|
|
314
|
-
);
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* Constructs a XMLHttpRequest object.
|
|
318
|
-
* @return {XMLHttpRequest}
|
|
319
|
-
* @throws {Error} If XMLHttpRequest is not supported
|
|
320
|
-
* @expose
|
|
321
|
-
*/
|
|
322
|
-
Util.XHR = function() {
|
|
323
|
-
// No dependencies please, ref: http://www.quirksmode.org/js/xmlhttp.html
|
|
324
|
-
var XMLHttpFactories = [
|
|
325
|
-
function () {return new XMLHttpRequest()},
|
|
326
|
-
function () {return new ActiveXObject("Msxml2.XMLHTTP")},
|
|
327
|
-
function () {return new ActiveXObject("Msxml3.XMLHTTP")},
|
|
328
|
-
function () {return new ActiveXObject("Microsoft.XMLHTTP")}
|
|
329
|
-
];
|
|
330
|
-
/** @type {?XMLHttpRequest} */
|
|
331
|
-
var xhr = null;
|
|
332
|
-
for (var i=0;i<XMLHttpFactories.length;i++) {
|
|
333
|
-
try { xhr = XMLHttpFactories[i](); }
|
|
334
|
-
catch (e) { continue; }
|
|
335
|
-
break;
|
|
336
|
-
}
|
|
337
|
-
if (!xhr)
|
|
338
|
-
throw Error("XMLHttpRequest is not supported");
|
|
339
|
-
return xhr;
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
* Fetches a resource.
|
|
344
|
-
* @param {string} path Resource path
|
|
345
|
-
* @param {function(?string)=} callback Callback receiving the resource's contents. If omitted the resource will
|
|
346
|
-
* be fetched synchronously. If the request failed, contents will be null.
|
|
347
|
-
* @return {?string|undefined} Resource contents if callback is omitted (null if the request failed), else undefined.
|
|
348
|
-
* @expose
|
|
349
|
-
*/
|
|
350
|
-
Util.fetch = function(path, callback) {
|
|
351
|
-
if (callback && typeof callback != 'function')
|
|
352
|
-
callback = null;
|
|
353
|
-
if (Util.IS_NODE) {
|
|
354
|
-
var fs = require("fs");
|
|
355
|
-
if (callback) {
|
|
356
|
-
fs.readFile(path, function(err, data) {
|
|
357
|
-
if (err)
|
|
358
|
-
callback(null);
|
|
359
|
-
else
|
|
360
|
-
callback(""+data);
|
|
361
|
-
});
|
|
362
|
-
} else
|
|
363
|
-
try {
|
|
364
|
-
return fs.readFileSync(path);
|
|
365
|
-
} catch (e) {
|
|
366
|
-
return null;
|
|
367
|
-
}
|
|
368
|
-
} else {
|
|
369
|
-
var xhr = Util.XHR();
|
|
370
|
-
xhr.open('GET', path, callback ? true : false);
|
|
371
|
-
// xhr.setRequestHeader('User-Agent', 'XMLHTTP/1.0');
|
|
372
|
-
xhr.setRequestHeader('Accept', 'text/plain');
|
|
373
|
-
if (typeof xhr.overrideMimeType === 'function') xhr.overrideMimeType('text/plain');
|
|
374
|
-
if (callback) {
|
|
375
|
-
xhr.onreadystatechange = function() {
|
|
376
|
-
if (xhr.readyState != 4) return;
|
|
377
|
-
if (/* remote */ xhr.status == 200 || /* local */ (xhr.status == 0 && typeof xhr.responseText === 'string'))
|
|
378
|
-
callback(xhr.responseText);
|
|
379
|
-
else
|
|
380
|
-
callback(null);
|
|
381
|
-
};
|
|
382
|
-
if (xhr.readyState == 4)
|
|
383
|
-
return;
|
|
384
|
-
xhr.send(null);
|
|
385
|
-
} else {
|
|
386
|
-
xhr.send(null);
|
|
387
|
-
if (/* remote */ xhr.status == 200 || /* local */ (xhr.status == 0 && typeof xhr.responseText === 'string'))
|
|
388
|
-
return xhr.responseText;
|
|
389
|
-
return null;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
};
|
|
393
|
-
|
|
394
|
-
/**
|
|
395
|
-
* Converts a string to camel case.
|
|
396
|
-
* @param {string} str
|
|
397
|
-
* @returns {string}
|
|
398
|
-
* @expose
|
|
399
|
-
*/
|
|
400
|
-
Util.toCamelCase = function(str) {
|
|
401
|
-
return str.replace(/_([a-zA-Z])/g, function ($0, $1) {
|
|
402
|
-
return $1.toUpperCase();
|
|
403
|
-
});
|
|
404
|
-
};
|
|
405
|
-
|
|
406
|
-
return Util;
|
|
407
|
-
})();
|
|
292
|
+
/**
|
|
293
|
+
* @alias ProtoBuf.Util
|
|
294
|
+
* @expose
|
|
295
|
+
*/
|
|
296
|
+
ProtoBuf.Util = (function() {
|
|
297
|
+
"use strict";
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* ProtoBuf utilities.
|
|
301
|
+
* @exports ProtoBuf.Util
|
|
302
|
+
* @namespace
|
|
303
|
+
*/
|
|
304
|
+
var Util = {};
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Flag if running in node or not.
|
|
308
|
+
* @type {boolean}
|
|
309
|
+
* @const
|
|
310
|
+
* @expose
|
|
311
|
+
*/
|
|
312
|
+
Util.IS_NODE = !!(
|
|
313
|
+
typeof process === 'object' && process+'' === '[object process]' && !process['browser']
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Constructs a XMLHttpRequest object.
|
|
318
|
+
* @return {XMLHttpRequest}
|
|
319
|
+
* @throws {Error} If XMLHttpRequest is not supported
|
|
320
|
+
* @expose
|
|
321
|
+
*/
|
|
322
|
+
Util.XHR = function() {
|
|
323
|
+
// No dependencies please, ref: http://www.quirksmode.org/js/xmlhttp.html
|
|
324
|
+
var XMLHttpFactories = [
|
|
325
|
+
function () {return new XMLHttpRequest()},
|
|
326
|
+
function () {return new ActiveXObject("Msxml2.XMLHTTP")},
|
|
327
|
+
function () {return new ActiveXObject("Msxml3.XMLHTTP")},
|
|
328
|
+
function () {return new ActiveXObject("Microsoft.XMLHTTP")}
|
|
329
|
+
];
|
|
330
|
+
/** @type {?XMLHttpRequest} */
|
|
331
|
+
var xhr = null;
|
|
332
|
+
for (var i=0;i<XMLHttpFactories.length;i++) {
|
|
333
|
+
try { xhr = XMLHttpFactories[i](); }
|
|
334
|
+
catch (e) { continue; }
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
if (!xhr)
|
|
338
|
+
throw Error("XMLHttpRequest is not supported");
|
|
339
|
+
return xhr;
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Fetches a resource.
|
|
344
|
+
* @param {string} path Resource path
|
|
345
|
+
* @param {function(?string)=} callback Callback receiving the resource's contents. If omitted the resource will
|
|
346
|
+
* be fetched synchronously. If the request failed, contents will be null.
|
|
347
|
+
* @return {?string|undefined} Resource contents if callback is omitted (null if the request failed), else undefined.
|
|
348
|
+
* @expose
|
|
349
|
+
*/
|
|
350
|
+
Util.fetch = function(path, callback) {
|
|
351
|
+
if (callback && typeof callback != 'function')
|
|
352
|
+
callback = null;
|
|
353
|
+
if (Util.IS_NODE) {
|
|
354
|
+
var fs = require("fs");
|
|
355
|
+
if (callback) {
|
|
356
|
+
fs.readFile(path, function(err, data) {
|
|
357
|
+
if (err)
|
|
358
|
+
callback(null);
|
|
359
|
+
else
|
|
360
|
+
callback(""+data);
|
|
361
|
+
});
|
|
362
|
+
} else
|
|
363
|
+
try {
|
|
364
|
+
return fs.readFileSync(path);
|
|
365
|
+
} catch (e) {
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
} else {
|
|
369
|
+
var xhr = Util.XHR();
|
|
370
|
+
xhr.open('GET', path, callback ? true : false);
|
|
371
|
+
// xhr.setRequestHeader('User-Agent', 'XMLHTTP/1.0');
|
|
372
|
+
xhr.setRequestHeader('Accept', 'text/plain');
|
|
373
|
+
if (typeof xhr.overrideMimeType === 'function') xhr.overrideMimeType('text/plain');
|
|
374
|
+
if (callback) {
|
|
375
|
+
xhr.onreadystatechange = function() {
|
|
376
|
+
if (xhr.readyState != 4) return;
|
|
377
|
+
if (/* remote */ xhr.status == 200 || /* local */ (xhr.status == 0 && typeof xhr.responseText === 'string'))
|
|
378
|
+
callback(xhr.responseText);
|
|
379
|
+
else
|
|
380
|
+
callback(null);
|
|
381
|
+
};
|
|
382
|
+
if (xhr.readyState == 4)
|
|
383
|
+
return;
|
|
384
|
+
xhr.send(null);
|
|
385
|
+
} else {
|
|
386
|
+
xhr.send(null);
|
|
387
|
+
if (/* remote */ xhr.status == 200 || /* local */ (xhr.status == 0 && typeof xhr.responseText === 'string'))
|
|
388
|
+
return xhr.responseText;
|
|
389
|
+
return null;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Converts a string to camel case.
|
|
396
|
+
* @param {string} str
|
|
397
|
+
* @returns {string}
|
|
398
|
+
* @expose
|
|
399
|
+
*/
|
|
400
|
+
Util.toCamelCase = function(str) {
|
|
401
|
+
return str.replace(/_([a-zA-Z])/g, function ($0, $1) {
|
|
402
|
+
return $1.toUpperCase();
|
|
403
|
+
});
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
return Util;
|
|
407
|
+
})();
|
|
408
408
|
|
|
409
409
|
/**
|
|
410
410
|
* Language expressions.
|
|
@@ -801,9 +801,11 @@
|
|
|
801
801
|
* converted to string form if so.
|
|
802
802
|
* @param {string} syntax Syntax level of defining message type, e.g.,
|
|
803
803
|
* proto2 or proto3.
|
|
804
|
+
* @param {string} name Name of the field containing this element (for error
|
|
805
|
+
* messages)
|
|
804
806
|
* @constructor
|
|
805
807
|
*/
|
|
806
|
-
var Element = function(type, resolvedType, isMapKey, syntax) {
|
|
808
|
+
var Element = function(type, resolvedType, isMapKey, syntax, name) {
|
|
807
809
|
|
|
808
810
|
/**
|
|
809
811
|
* Element type, as a string (e.g., int32).
|
|
@@ -829,6 +831,12 @@
|
|
|
829
831
|
*/
|
|
830
832
|
this.syntax = syntax;
|
|
831
833
|
|
|
834
|
+
/**
|
|
835
|
+
* Name of the field containing this element (for error messages)
|
|
836
|
+
* @type {string}
|
|
837
|
+
*/
|
|
838
|
+
this.name = name;
|
|
839
|
+
|
|
832
840
|
if (isMapKey && ProtoBuf.MAP_KEY_TYPES.indexOf(type) < 0)
|
|
833
841
|
throw Error("Invalid map key type: " + type.name);
|
|
834
842
|
};
|
|
@@ -879,6 +887,10 @@
|
|
|
879
887
|
throw Error("not convertible to Long");
|
|
880
888
|
}
|
|
881
889
|
|
|
890
|
+
ElementPrototype.toString = function() {
|
|
891
|
+
return (this.name || '') + (this.isMapKey ? 'map' : 'value') + ' element';
|
|
892
|
+
}
|
|
893
|
+
|
|
882
894
|
/**
|
|
883
895
|
* Checks if the given value can be set for an element of this type (singular
|
|
884
896
|
* field or one element of a repeated field or map).
|
|
@@ -888,9 +900,10 @@
|
|
|
888
900
|
* @expose
|
|
889
901
|
*/
|
|
890
902
|
ElementPrototype.verifyValue = function(value) {
|
|
891
|
-
var
|
|
892
|
-
|
|
893
|
-
|
|
903
|
+
var self = this;
|
|
904
|
+
function fail(val, msg) {
|
|
905
|
+
throw Error("Illegal value for "+self.toString(true)+" of type "+self.type.name+": "+val+" ("+msg+")");
|
|
906
|
+
}
|
|
894
907
|
switch (this.type) {
|
|
895
908
|
// Signed 32bit
|
|
896
909
|
case ProtoBuf.TYPES["int32"]:
|
|
@@ -1380,10 +1393,10 @@
|
|
|
1380
1393
|
|
|
1381
1394
|
/**
|
|
1382
1395
|
* Extensions range.
|
|
1383
|
-
* @type {!Array.<number
|
|
1396
|
+
* @type {!Array.<number>|undefined}
|
|
1384
1397
|
* @expose
|
|
1385
1398
|
*/
|
|
1386
|
-
this.extensions =
|
|
1399
|
+
this.extensions = undefined;
|
|
1387
1400
|
|
|
1388
1401
|
/**
|
|
1389
1402
|
* Runtime message class.
|
|
@@ -1552,9 +1565,11 @@
|
|
|
1552
1565
|
MessagePrototype.set = function(keyOrObj, value, noAssert) {
|
|
1553
1566
|
if (keyOrObj && typeof keyOrObj === 'object') {
|
|
1554
1567
|
noAssert = value;
|
|
1555
|
-
for (var ikey in keyOrObj)
|
|
1556
|
-
if
|
|
1568
|
+
for (var ikey in keyOrObj) {
|
|
1569
|
+
// Check if virtual oneof field - don't set these
|
|
1570
|
+
if (keyOrObj.hasOwnProperty(ikey) && typeof (value = keyOrObj[ikey]) !== 'undefined' && T._oneofsByName[ikey] === undefined)
|
|
1557
1571
|
this.$set(ikey, value, noAssert);
|
|
1572
|
+
}
|
|
1558
1573
|
return this;
|
|
1559
1574
|
}
|
|
1560
1575
|
var field = T._fieldsByName[keyOrObj];
|
|
@@ -1782,18 +1797,19 @@
|
|
|
1782
1797
|
* @name ProtoBuf.Builder.Message#encodeDelimited
|
|
1783
1798
|
* @function
|
|
1784
1799
|
* @param {(!ByteBuffer|boolean)=} buffer ByteBuffer to encode to. Will create a new one and flip it if omitted.
|
|
1800
|
+
* @param {boolean=} noVerify Whether to not verify field values, defaults to `false`
|
|
1785
1801
|
* @return {!ByteBuffer} Encoded message as a ByteBuffer
|
|
1786
1802
|
* @throws {Error} If the message cannot be encoded or if required fields are missing. The later still
|
|
1787
1803
|
* returns the encoded ByteBuffer in the `encoded` property on the error.
|
|
1788
1804
|
* @expose
|
|
1789
1805
|
*/
|
|
1790
|
-
MessagePrototype.encodeDelimited = function(buffer) {
|
|
1806
|
+
MessagePrototype.encodeDelimited = function(buffer, noVerify) {
|
|
1791
1807
|
var isNew = false;
|
|
1792
1808
|
if (!buffer)
|
|
1793
1809
|
buffer = new ByteBuffer(),
|
|
1794
1810
|
isNew = true;
|
|
1795
1811
|
var enc = new ByteBuffer().LE();
|
|
1796
|
-
T.encode(this, enc).flip();
|
|
1812
|
+
T.encode(this, enc, noVerify).flip();
|
|
1797
1813
|
buffer.writeVarint32(enc.remaining());
|
|
1798
1814
|
buffer.append(enc);
|
|
1799
1815
|
return isNew ? buffer.flip() : buffer;
|
|
@@ -1940,7 +1956,7 @@
|
|
|
1940
1956
|
return binaryAsBase64 ? obj.toBase64() : obj.toBuffer();
|
|
1941
1957
|
// Convert Longs to proper objects or strings
|
|
1942
1958
|
if (ProtoBuf.Long.isLong(obj))
|
|
1943
|
-
return longsAsStrings ? obj.toString() :
|
|
1959
|
+
return longsAsStrings ? obj.toString() : ProtoBuf.Long.fromValue(obj);
|
|
1944
1960
|
var clone;
|
|
1945
1961
|
// Clone arrays
|
|
1946
1962
|
if (Array.isArray(obj)) {
|
|
@@ -2002,6 +2018,7 @@
|
|
|
2002
2018
|
* @name ProtoBuf.Builder.Message.decode
|
|
2003
2019
|
* @function
|
|
2004
2020
|
* @param {!ByteBuffer|!ArrayBuffer|!Buffer|string} buffer Buffer to decode from
|
|
2021
|
+
* @param {(number|string)=} length Message length. Defaults to decode all the remainig data.
|
|
2005
2022
|
* @param {string=} enc Encoding if buffer is a string: hex, utf8 (not recommended), defaults to base64
|
|
2006
2023
|
* @return {!ProtoBuf.Builder.Message} Decoded message
|
|
2007
2024
|
* @throws {Error} If the message cannot be decoded or if required fields are missing. The later still
|
|
@@ -2010,13 +2027,17 @@
|
|
|
2010
2027
|
* @see ProtoBuf.Builder.Message.decode64
|
|
2011
2028
|
* @see ProtoBuf.Builder.Message.decodeHex
|
|
2012
2029
|
*/
|
|
2013
|
-
Message.decode = function(buffer, enc) {
|
|
2030
|
+
Message.decode = function(buffer, length, enc) {
|
|
2031
|
+
if (typeof length === 'string')
|
|
2032
|
+
enc = length,
|
|
2033
|
+
length = -1;
|
|
2014
2034
|
if (typeof buffer === 'string')
|
|
2015
2035
|
buffer = ByteBuffer.wrap(buffer, enc ? enc : "base64");
|
|
2016
|
-
|
|
2036
|
+
else if (!ByteBuffer.isByteBuffer(buffer))
|
|
2037
|
+
buffer = ByteBuffer.wrap(buffer); // May throw
|
|
2017
2038
|
var le = buffer.littleEndian;
|
|
2018
2039
|
try {
|
|
2019
|
-
var msg = T.decode(buffer.LE());
|
|
2040
|
+
var msg = T.decode(buffer.LE(), length);
|
|
2020
2041
|
buffer.LE(le);
|
|
2021
2042
|
return msg;
|
|
2022
2043
|
} catch (e) {
|
|
@@ -2039,7 +2060,8 @@
|
|
|
2039
2060
|
Message.decodeDelimited = function(buffer, enc) {
|
|
2040
2061
|
if (typeof buffer === 'string')
|
|
2041
2062
|
buffer = ByteBuffer.wrap(buffer, enc ? enc : "base64");
|
|
2042
|
-
|
|
2063
|
+
else if (!ByteBuffer.isByteBuffer(buffer))
|
|
2064
|
+
buffer = ByteBuffer.wrap(buffer); // May throw
|
|
2043
2065
|
if (buffer.remaining() < 1)
|
|
2044
2066
|
return null;
|
|
2045
2067
|
var off = buffer.offset,
|
|
@@ -2161,6 +2183,7 @@
|
|
|
2161
2183
|
this._fields = [];
|
|
2162
2184
|
this._fieldsById = {};
|
|
2163
2185
|
this._fieldsByName = {};
|
|
2186
|
+
this._oneofsByName = {};
|
|
2164
2187
|
for (var i=0, k=this.children.length, child; i<k; i++) {
|
|
2165
2188
|
child = this.children[i];
|
|
2166
2189
|
if (child instanceof Enum || child instanceof Message || child instanceof Service) {
|
|
@@ -2172,6 +2195,9 @@
|
|
|
2172
2195
|
this._fields.push(child),
|
|
2173
2196
|
this._fieldsById[child.id] = child,
|
|
2174
2197
|
this._fieldsByName[child.name] = child;
|
|
2198
|
+
else if (child instanceof Message.OneOf) {
|
|
2199
|
+
this._oneofsByName[child.name] = child;
|
|
2200
|
+
}
|
|
2175
2201
|
else if (!(child instanceof Message.OneOf) && !(child instanceof Extension)) // Not built
|
|
2176
2202
|
throw Error("Illegal reflect child of "+this.toString(true)+": "+this.children[i].toString(true));
|
|
2177
2203
|
}
|
|
@@ -2271,14 +2297,15 @@
|
|
|
2271
2297
|
/**
|
|
2272
2298
|
* Decodes an encoded message and returns the decoded message.
|
|
2273
2299
|
* @param {ByteBuffer} buffer ByteBuffer to decode from
|
|
2274
|
-
* @param {number=} length Message length. Defaults to decode all
|
|
2300
|
+
* @param {number=} length Message length. Defaults to decode all remaining data.
|
|
2275
2301
|
* @param {number=} expectedGroupEndId Expected GROUPEND id if this is a legacy group
|
|
2276
2302
|
* @return {ProtoBuf.Builder.Message} Decoded message
|
|
2277
2303
|
* @throws {Error} If the message cannot be decoded
|
|
2278
2304
|
* @expose
|
|
2279
2305
|
*/
|
|
2280
2306
|
MessagePrototype.decode = function(buffer, length, expectedGroupEndId) {
|
|
2281
|
-
|
|
2307
|
+
if (typeof length !== 'number')
|
|
2308
|
+
length = -1;
|
|
2282
2309
|
var start = buffer.offset,
|
|
2283
2310
|
msg = new (this.clazz)(),
|
|
2284
2311
|
tag, wireType, id, field;
|
|
@@ -2497,9 +2524,9 @@
|
|
|
2497
2524
|
* @expose
|
|
2498
2525
|
*/
|
|
2499
2526
|
FieldPrototype.build = function() {
|
|
2500
|
-
this.element = new Element(this.type, this.resolvedType, false, this.syntax);
|
|
2527
|
+
this.element = new Element(this.type, this.resolvedType, false, this.syntax, this.name);
|
|
2501
2528
|
if (this.map)
|
|
2502
|
-
this.keyElement = new Element(this.keyType, undefined, true, this.syntax);
|
|
2529
|
+
this.keyElement = new Element(this.keyType, undefined, true, this.syntax, this.name);
|
|
2503
2530
|
|
|
2504
2531
|
// In proto3, fields do not have field presence, and every field is set to
|
|
2505
2532
|
// its type's default value ("", 0, 0.0, or false).
|
|
@@ -2521,9 +2548,10 @@
|
|
|
2521
2548
|
*/
|
|
2522
2549
|
FieldPrototype.verifyValue = function(value, skipRepeated) {
|
|
2523
2550
|
skipRepeated = skipRepeated || false;
|
|
2524
|
-
var
|
|
2525
|
-
|
|
2526
|
-
|
|
2551
|
+
var self = this;
|
|
2552
|
+
function fail(val, msg) {
|
|
2553
|
+
throw Error("Illegal value for "+self.toString(true)+" of type "+self.type.name+": "+val+" ("+msg+")");
|
|
2554
|
+
}
|
|
2527
2555
|
if (value === null) { // NULL values for optional fields
|
|
2528
2556
|
if (this.required)
|
|
2529
2557
|
fail(typeof value, "required");
|
|
@@ -3137,6 +3165,9 @@
|
|
|
3137
3165
|
callback(err);
|
|
3138
3166
|
return;
|
|
3139
3167
|
}
|
|
3168
|
+
// Coalesce to empty string when service response has empty content
|
|
3169
|
+
if (res === null)
|
|
3170
|
+
res = ''
|
|
3140
3171
|
try { res = method.resolvedResponseType.clazz.decode(res); } catch (notABuffer) {}
|
|
3141
3172
|
if (!res || !(res instanceof method.resolvedResponseType.clazz)) {
|
|
3142
3173
|
callback(Error("Illegal response type received in service method "+ T.name+"#"+method.name));
|
|
@@ -3580,13 +3611,12 @@
|
|
|
3580
3611
|
subObj.push(svc);
|
|
3581
3612
|
});
|
|
3582
3613
|
|
|
3583
|
-
// Set extension
|
|
3614
|
+
// Set extension ranges
|
|
3584
3615
|
if (def["extensions"]) {
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
obj.extensions[1] = ProtoBuf.ID_MAX;
|
|
3616
|
+
if (typeof def["extensions"][0] === 'number') // pre 5.0.1
|
|
3617
|
+
obj.extensions = [ def["extensions"] ];
|
|
3618
|
+
else
|
|
3619
|
+
obj.extensions = def["extensions"];
|
|
3590
3620
|
}
|
|
3591
3621
|
|
|
3592
3622
|
// Create on top of current namespace
|
|
@@ -3625,8 +3655,16 @@
|
|
|
3625
3655
|
def["fields"].forEach(function(fld) {
|
|
3626
3656
|
if (obj.getChild(fld['id']|0) !== null)
|
|
3627
3657
|
throw Error("duplicate extended field id in "+obj.name+": "+fld['id']);
|
|
3628
|
-
if
|
|
3629
|
-
|
|
3658
|
+
// Check if field id is allowed to be extended
|
|
3659
|
+
if (obj.extensions) {
|
|
3660
|
+
var valid = false;
|
|
3661
|
+
obj.extensions.forEach(function(range) {
|
|
3662
|
+
if (fld["id"] >= range[0] && fld["id"] <= range[1])
|
|
3663
|
+
valid = true;
|
|
3664
|
+
});
|
|
3665
|
+
if (!valid)
|
|
3666
|
+
throw Error("illegal extended field id in "+obj.name+": "+fld['id']+" (not within valid ranges)");
|
|
3667
|
+
}
|
|
3630
3668
|
// Convert extension field names to camel case notation if the override is set
|
|
3631
3669
|
var name = fld["name"];
|
|
3632
3670
|
if (this.options['convertFieldsToCamelCase'])
|
|
@@ -3707,7 +3745,11 @@
|
|
|
3707
3745
|
root = require("path")['resolve'](root);
|
|
3708
3746
|
if (root.indexOf("\\") >= 0 || filename.file.indexOf("\\") >= 0)
|
|
3709
3747
|
delim = '\\';
|
|
3710
|
-
var fname
|
|
3748
|
+
var fname;
|
|
3749
|
+
if (ProtoBuf.Util.IS_NODE)
|
|
3750
|
+
fname = require("path")['join'](root, filename.file);
|
|
3751
|
+
else
|
|
3752
|
+
fname = root + delim + filename.file;
|
|
3711
3753
|
if (this.files[fname] === true)
|
|
3712
3754
|
return this.reset();
|
|
3713
3755
|
this.files[fname] = true;
|
|
@@ -3753,7 +3795,10 @@
|
|
|
3753
3795
|
var importFilename = json['imports'][i];
|
|
3754
3796
|
if (importFilename === "google/protobuf/descriptor.proto")
|
|
3755
3797
|
continue; // Not needed and therefore not used
|
|
3756
|
-
|
|
3798
|
+
if (ProtoBuf.Util.IS_NODE)
|
|
3799
|
+
importFilename = require("path")['join'](importRoot, importFilename);
|
|
3800
|
+
else
|
|
3801
|
+
importFilename = importRoot + delim + importFilename;
|
|
3757
3802
|
if (this.files[importFilename] === true)
|
|
3758
3803
|
continue; // Already imported
|
|
3759
3804
|
if (/\.proto$/i.test(importFilename) && !ProtoBuf.DotProto) // If this is a light build
|
|
@@ -3851,6 +3896,16 @@
|
|
|
3851
3896
|
this.ptr.keyType = ProtoBuf.TYPES[this.ptr.keyType];
|
|
3852
3897
|
}
|
|
3853
3898
|
|
|
3899
|
+
// If it's a repeated and packable field then proto3 mandates it should be packed by
|
|
3900
|
+
// default
|
|
3901
|
+
if (
|
|
3902
|
+
this.ptr.syntax === 'proto3' &&
|
|
3903
|
+
this.ptr.repeated && this.ptr.options.packed === undefined &&
|
|
3904
|
+
ProtoBuf.PACKABLE_WIRE_TYPES.indexOf(this.ptr.type.wireType) !== -1
|
|
3905
|
+
) {
|
|
3906
|
+
this.ptr.options.packed = true;
|
|
3907
|
+
}
|
|
3908
|
+
|
|
3854
3909
|
} else if (this.ptr instanceof ProtoBuf.Reflect.Service.Method) {
|
|
3855
3910
|
|
|
3856
3911
|
if (this.ptr instanceof ProtoBuf.Reflect.Service.RPCMethod) {
|