protobufjs 4.1.1 → 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.
Files changed (72) hide show
  1. package/.travis.yml +2 -1
  2. package/README.md +17 -17
  3. package/bower.json +2 -2
  4. package/cli/pbjs/targets/json.js +3 -2
  5. package/cli/pbjs/targets/proto.js +48 -24
  6. package/cli/pbjs.js +8 -1
  7. package/dist/README.md +10 -10
  8. package/dist/{ProtoBuf-light.js → protobuf-light.js} +49 -43
  9. package/dist/protobuf-light.min.js +87 -0
  10. package/dist/protobuf-light.min.js.gz +0 -0
  11. package/dist/protobuf-light.min.map +8 -0
  12. package/dist/{ProtoBuf.js → protobuf.js} +103 -66
  13. package/dist/protobuf.min.js +108 -0
  14. package/dist/protobuf.min.js.gz +0 -0
  15. package/dist/protobuf.min.map +8 -0
  16. package/docs/ProtoBuf.Builder.Message.html +106 -37
  17. package/docs/ProtoBuf.Builder.Service.html +9 -9
  18. package/docs/ProtoBuf.Builder.html +22 -22
  19. package/docs/ProtoBuf.DotProto.Parser.html +7 -7
  20. package/docs/ProtoBuf.DotProto.Tokenizer.html +11 -11
  21. package/docs/ProtoBuf.DotProto.html +2 -2
  22. package/docs/ProtoBuf.Map.html +6 -6
  23. package/docs/ProtoBuf.Reflect.Element.html +7 -7
  24. package/docs/ProtoBuf.Reflect.Enum.Value.html +10 -10
  25. package/docs/ProtoBuf.Reflect.Enum.html +21 -21
  26. package/docs/ProtoBuf.Reflect.Extension.html +3 -3
  27. package/docs/ProtoBuf.Reflect.Message.ExtensionField.html +29 -29
  28. package/docs/ProtoBuf.Reflect.Message.Field.html +28 -28
  29. package/docs/ProtoBuf.Reflect.Message.OneOf.html +10 -10
  30. package/docs/ProtoBuf.Reflect.Message.html +31 -28
  31. package/docs/ProtoBuf.Reflect.Namespace.html +19 -19
  32. package/docs/ProtoBuf.Reflect.Service.Method.html +11 -11
  33. package/docs/ProtoBuf.Reflect.Service.RPCMethod.html +17 -17
  34. package/docs/ProtoBuf.Reflect.Service.html +20 -20
  35. package/docs/ProtoBuf.Reflect.T.html +9 -9
  36. package/docs/ProtoBuf.Reflect.html +2 -2
  37. package/docs/ProtoBuf.Util.html +2 -151
  38. package/docs/ProtoBuf.html +9 -9
  39. package/docs/ProtoBuf.js.html +104 -67
  40. package/docs/index.html +1 -1
  41. package/donate.png +0 -0
  42. package/externs/{ProtoBuf.js → protobuf.js} +933 -922
  43. package/index.js +1 -18
  44. package/package.json +12 -11
  45. package/protobuf.png +0 -0
  46. package/sandbox/issue347/index.js +27 -0
  47. package/sandbox/issue355/main.proto +15 -0
  48. package/scripts/build.js +4 -9
  49. package/src/ProtoBuf/Builder/Message.js +9 -4
  50. package/src/ProtoBuf/Builder/Service.js +3 -0
  51. package/src/ProtoBuf/Builder.js +17 -10
  52. package/src/ProtoBuf/DotProto/Parser.js +54 -23
  53. package/src/ProtoBuf/Reflect/Element.js +4 -3
  54. package/src/ProtoBuf/Reflect/Message/Field.js +4 -3
  55. package/src/ProtoBuf/Reflect/Message.js +3 -3
  56. package/src/ProtoBuf/Util.js +3 -14
  57. package/src/bower.json +1 -1
  58. package/src/google/protobuf/descriptor.json +28 -14
  59. package/src/{ProtoBuf.js → protobuf.js} +0 -0
  60. package/src/wrap.js +6 -6
  61. package/tests/imports-weak.proto +7 -0
  62. package/tests/suite.js +64 -81
  63. package/ProtoBuf.png +0 -0
  64. package/dist/ProtoBuf-light.min.js +0 -88
  65. package/dist/ProtoBuf-light.min.js.gz +0 -0
  66. package/dist/ProtoBuf-light.min.map +0 -8
  67. package/dist/ProtoBuf.min.js +0 -108
  68. package/dist/ProtoBuf.min.js.gz +0 -0
  69. package/dist/ProtoBuf.min.map +0 -8
  70. package/externs/ByteBuffer.js +0 -767
  71. package/externs/Long.js +0 -328
  72. package/tests/gtfs-realtime.proto +0 -552
package/index.js CHANGED
@@ -1,18 +1 @@
1
- /*
2
- Copyright 2013 Daniel Wirtz <dcode@dcode.io>
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
- var ProtoBuf = require("./dist/ProtoBuf.js");
17
-
18
- module.exports = ProtoBuf;
1
+ module.exports = require("./dist/protobuf.js");
package/package.json CHANGED
@@ -1,23 +1,23 @@
1
1
  {
2
2
  "name": "protobufjs",
3
- "version": "4.1.1",
3
+ "version": "5.0.1",
4
4
  "description": "Protocol Buffers for JavaScript. Finally.",
5
5
  "author": "Daniel Wirtz <dcode@dcode.io>",
6
6
  "contributors": [
7
7
  "Frank Xu <yyfrankyy@gmail.com>"
8
8
  ],
9
- "main": "dist/ProtoBuf.js",
9
+ "main": "./dist/protobuf.js",
10
10
  "bin": {
11
11
  "pbjs": "./bin/pbjs"
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
15
- "url": "https://github.com/dcodeIO/ProtoBuf.js.git"
15
+ "url": "https://github.com/dcodeIO/protobuf.js.git"
16
16
  },
17
17
  "bugs": {
18
- "url": "https://github.com/dcodeIO/ProtoBuf.js/issues"
18
+ "url": "https://github.com/dcodeIO/protobuf.js/issues"
19
19
  },
20
- "homepage": "https://github.com/dcodeIO/ProtoBuf.js",
20
+ "homepage": "https://github.com/dcodeIO/protobuf.js",
21
21
  "keywords": [
22
22
  "net",
23
23
  "buffer",
@@ -29,7 +29,7 @@
29
29
  ],
30
30
  "dependencies": {
31
31
  "ascli": "~1",
32
- "bytebuffer": "~4 >=4.1",
32
+ "bytebuffer": "~5",
33
33
  "glob": "^5.0.10",
34
34
  "yargs": "^3.10.0"
35
35
  },
@@ -45,7 +45,8 @@
45
45
  "node": ">=0.8"
46
46
  },
47
47
  "browser": {
48
- "fs": false
48
+ "fs": false,
49
+ "path": false
49
50
  },
50
51
  "scripts": {
51
52
  "prepublish": "npm test",
@@ -54,11 +55,11 @@
54
55
  "build": "node scripts/build.js",
55
56
  "descriptor2json": "node bin/pbjs src/google/protobuf/descriptor.proto --target=json > src/google/protobuf/descriptor.json",
56
57
  "compile": "npm run-script compile-full && npm run-script compile-light",
57
- "compile-full": "ccjs dist/ProtoBuf.js --create_source_map=dist/ProtoBuf.min.map --compilation_level=SIMPLE_OPTIMIZATIONS > dist/ProtoBuf.min.js",
58
- "compile-light": "ccjs dist/ProtoBuf-light.js --create_source_map=dist/ProtoBuf-light.min.map --compilation_level=SIMPLE_OPTIMIZATIONS > dist/ProtoBuf-light.min.js",
58
+ "compile-full": "ccjs dist/protobuf.js --create_source_map=dist/protobuf.min.map --compilation_level=SIMPLE_OPTIMIZATIONS > dist/protobuf.min.js",
59
+ "compile-light": "ccjs dist/protobuf-light.js --create_source_map=dist/protobuf-light.min.map --compilation_level=SIMPLE_OPTIMIZATIONS > dist/protobuf-light.min.js",
59
60
  "compress": "npm run-script compress-full && npm run-script compress-light",
60
- "compress-full": "gzip -c -9 dist/ProtoBuf.min.js > dist/ProtoBuf.min.js.gz",
61
- "compress-light": "gzip -c -9 dist/ProtoBuf-light.min.js > dist/ProtoBuf-light.min.js.gz",
61
+ "compress-full": "gzip -c -9 dist/protobuf.min.js > dist/protobuf.min.js.gz",
62
+ "compress-light": "gzip -c -9 dist/protobuf-light.min.js > dist/protobuf-light.min.js.gz",
62
63
  "jsdoc": "node node_modules/jsdoc/jsdoc.js -c jsdoc.json"
63
64
  }
64
65
  }
package/protobuf.png ADDED
Binary file
@@ -0,0 +1,27 @@
1
+ var ProtoBuf = require('../../'),
2
+ ByteBuffer = ProtoBuf.ByteBuffer;
3
+ var prototext = String(function() {
4
+ /*
5
+ package str;
6
+
7
+ message Value {
8
+ oneof type {
9
+ string string = 1;
10
+ bytes bytes = 2;
11
+ }
12
+ }
13
+ */
14
+ }).match(/\/\*([^]*)\*\//)[1];
15
+
16
+ var builder = ProtoBuf.loadProto(prototext);
17
+ var messageValue = builder.build('str.Value');
18
+ var bb = ByteBuffer.wrap([10, 1, 97, 10, 2, 98, 98, 10, 3, 99, 99, 99]);
19
+ bb.printDebug();
20
+ var value1 = messageValue.decode(bb);
21
+ bb.printDebug();
22
+ bb = ByteBuffer.wrap([10, 3, 99, 99, 99]);
23
+ bb.printDebug();
24
+ var value2 = messageValue.decode(bb);
25
+ bb.printDebug();
26
+ console.log('value1: %j', value1);
27
+ console.log('value2: %j', value2);
@@ -0,0 +1,15 @@
1
+ message A {
2
+ repeated group EntryResponse = 1 {
3
+ required ResponseType response_type = 2;
4
+ optional string id_string = 3;
5
+ optional string parent_id_string = 4;
6
+ optional int64 position_in_parent = 5;
7
+ optional int64 version = 6;
8
+ optional string name = 7;
9
+ optional string non_unique_name = 8;
10
+ optional string error_message = 9;
11
+ optional int64 mtime = 10;
12
+ }
13
+
14
+ message ResponseType {}
15
+ }
package/scripts/build.js CHANGED
@@ -14,11 +14,6 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- /**
18
- * @overview ProtoBuf.js Build Script (c) 2014 Daniel Wirtz <dcode@dcode.io>
19
- * Released under the Apache License, Version 2.0
20
- * see: https://github.com/dcodeIO/ProtoBuf.js for details
21
- */
22
17
  var MetaScript = require("metascript"),
23
18
  path = require("path"),
24
19
  fs = require("fs");
@@ -35,17 +30,17 @@ var scope = {
35
30
  };
36
31
 
37
32
  // Make full build
38
- console.log("Building ProtoBuf.js with scope", JSON.stringify(scope, null, 2));
33
+ console.log("Building protobuf.js with scope", JSON.stringify(scope, null, 2));
39
34
  fs.writeFileSync(
40
- path.join(distDir, "ProtoBuf.js"),
35
+ path.join(distDir, "protobuf.js"),
41
36
  MetaScript.transform(fs.readFileSync(filename = path.join(srcDir, "wrap.js")), filename, scope, srcDir)
42
37
  );
43
38
 
44
39
  // Make light build
45
40
  scope.DOTPROTO = false;
46
- console.log("Building ProtoBuf-light.js with scope", JSON.stringify(scope, null, 2));
41
+ console.log("Building protobuf-light.js with scope", JSON.stringify(scope, null, 2));
47
42
  fs.writeFileSync(
48
- path.join(distDir, "ProtoBuf-light.js"),
43
+ path.join(distDir, "protobuf-light.js"),
49
44
  MetaScript.transform(fs.readFileSync(filename = path.join(srcDir, "wrap.js")), filename, scope, srcDir)
50
45
  );
51
46
 
@@ -340,18 +340,19 @@ MessagePrototype.calculate = function() {
340
340
  * @name ProtoBuf.Builder.Message#encodeDelimited
341
341
  * @function
342
342
  * @param {(!ByteBuffer|boolean)=} buffer ByteBuffer to encode to. Will create a new one and flip it if omitted.
343
+ * @param {boolean=} noVerify Whether to not verify field values, defaults to `false`
343
344
  * @return {!ByteBuffer} Encoded message as a ByteBuffer
344
345
  * @throws {Error} If the message cannot be encoded or if required fields are missing. The later still
345
346
  * returns the encoded ByteBuffer in the `encoded` property on the error.
346
347
  * @expose
347
348
  */
348
- MessagePrototype.encodeDelimited = function(buffer) {
349
+ MessagePrototype.encodeDelimited = function(buffer, noVerify) {
349
350
  var isNew = false;
350
351
  if (!buffer)
351
352
  buffer = new ByteBuffer(),
352
353
  isNew = true;
353
354
  var enc = new ByteBuffer().LE();
354
- T.encode(this, enc).flip();
355
+ T.encode(this, enc, noVerify).flip();
355
356
  buffer.writeVarint32(enc.remaining());
356
357
  buffer.append(enc);
357
358
  return isNew ? buffer.flip() : buffer;
@@ -498,7 +499,7 @@ function cloneRaw(obj, binaryAsBase64, longsAsStrings, resolvedType) {
498
499
  return binaryAsBase64 ? obj.toBase64() : obj.toBuffer();
499
500
  // Convert Longs to proper objects or strings
500
501
  if (ProtoBuf.Long.isLong(obj))
501
- return longsAsStrings ? obj.toString() : new ProtoBuf.Long(obj);
502
+ return longsAsStrings ? obj.toString() : ProtoBuf.Long.fromValue(obj);
502
503
  var clone;
503
504
  // Clone arrays
504
505
  if (Array.isArray(obj)) {
@@ -560,6 +561,7 @@ MessagePrototype.encodeJSON = function() {
560
561
  * @name ProtoBuf.Builder.Message.decode
561
562
  * @function
562
563
  * @param {!ByteBuffer|!ArrayBuffer|!Buffer|string} buffer Buffer to decode from
564
+ * @param {(number|string)=} length Message length. Defaults to decode all the remainig data.
563
565
  * @param {string=} enc Encoding if buffer is a string: hex, utf8 (not recommended), defaults to base64
564
566
  * @return {!ProtoBuf.Builder.Message} Decoded message
565
567
  * @throws {Error} If the message cannot be decoded or if required fields are missing. The later still
@@ -568,7 +570,10 @@ MessagePrototype.encodeJSON = function() {
568
570
  * @see ProtoBuf.Builder.Message.decode64
569
571
  * @see ProtoBuf.Builder.Message.decodeHex
570
572
  */
571
- Message.decode = function(buffer, enc) {
573
+ Message.decode = function(buffer, length, enc) {
574
+ if (typeof length === 'string')
575
+ enc = length,
576
+ length = -1;
572
577
  if (typeof buffer === 'string')
573
578
  buffer = ByteBuffer.wrap(buffer, enc ? enc : "base64");
574
579
  buffer = ByteBuffer.isByteBuffer(buffer) ? buffer : ByteBuffer.wrap(buffer); // May throw
@@ -77,6 +77,9 @@ for (var i=0; i<rpc.length; i++) {
77
77
  callback(err);
78
78
  return;
79
79
  }
80
+ // Coalesce to empty string when service response has empty content
81
+ if (res === null)
82
+ res = ''
80
83
  try { res = method.resolvedResponseType.clazz.decode(res); } catch (notABuffer) {}
81
84
  if (!res || !(res instanceof method.resolvedResponseType.clazz)) {
82
85
  callback(Error("Illegal response type received in service method "+ T.name+"#"+method.name));
@@ -243,13 +243,12 @@ ProtoBuf.Builder = (function(ProtoBuf, Lang, Reflect) {
243
243
  subObj.push(svc);
244
244
  });
245
245
 
246
- // Set extension range
246
+ // Set extension ranges
247
247
  if (def["extensions"]) {
248
- obj.extensions = def["extensions"];
249
- if (obj.extensions[0] < ProtoBuf.ID_MIN)
250
- obj.extensions[0] = ProtoBuf.ID_MIN;
251
- if (obj.extensions[1] > ProtoBuf.ID_MAX)
252
- obj.extensions[1] = ProtoBuf.ID_MAX;
248
+ if (typeof def["extensions"][0] === 'number') // pre 5.0.1
249
+ obj.extensions = [ def["extensions"] ];
250
+ else
251
+ obj.extensions = def["extensions"];
253
252
  }
254
253
 
255
254
  // Create on top of current namespace
@@ -288,8 +287,16 @@ ProtoBuf.Builder = (function(ProtoBuf, Lang, Reflect) {
288
287
  def["fields"].forEach(function(fld) {
289
288
  if (obj.getChild(fld['id']|0) !== null)
290
289
  throw Error("duplicate extended field id in "+obj.name+": "+fld['id']);
291
- if (fld['id'] < obj.extensions[0] || fld['id'] > obj.extensions[1])
292
- throw Error("illegal extended field id in "+obj.name+": "+fld['id']+" ("+obj.extensions.join(' to ')+" expected)");
290
+ // Check if field id is allowed to be extended
291
+ if (obj.extensions) {
292
+ var valid = false;
293
+ obj.extensions.forEach(function(range) {
294
+ if (fld["id"] >= range[0] && fld["id"] <= range[1])
295
+ valid = true;
296
+ });
297
+ if (!valid)
298
+ throw Error("illegal extended field id in "+obj.name+": "+fld['id']+" (not within valid ranges)");
299
+ }
293
300
  // Convert extension field names to camel case notation if the override is set
294
301
  var name = fld["name"];
295
302
  if (this.options['convertFieldsToCamelCase'])
@@ -358,7 +365,7 @@ ProtoBuf.Builder = (function(ProtoBuf, Lang, Reflect) {
358
365
  if (typeof filename === 'string') {
359
366
 
360
367
  if (ProtoBuf.Util.IS_NODE)
361
- filename = ProtoBuf.Util.require("path")['resolve'](filename);
368
+ filename = require("path")['resolve'](filename);
362
369
  if (this.files[filename] === true)
363
370
  return this.reset();
364
371
  this.files[filename] = true;
@@ -367,7 +374,7 @@ ProtoBuf.Builder = (function(ProtoBuf, Lang, Reflect) {
367
374
 
368
375
  var root = filename.root;
369
376
  if (ProtoBuf.Util.IS_NODE)
370
- root = ProtoBuf.Util.require("path")['resolve'](root);
377
+ root = require("path")['resolve'](root);
371
378
  if (root.indexOf("\\") >= 0 || filename.file.indexOf("\\") >= 0)
372
379
  delim = '\\';
373
380
  var fname = root + delim + filename.file;
@@ -50,7 +50,8 @@ ParserPrototype.parse = function() {
50
50
  // "syntax": undefined
51
51
  };
52
52
  var token,
53
- head = true;
53
+ head = true,
54
+ weak;
54
55
  try {
55
56
  while (token = this.tn.next()) {
56
57
  switch (token) {
@@ -67,11 +68,12 @@ ParserPrototype.parse = function() {
67
68
  if (!head)
68
69
  throw Error("unexpected 'import'");
69
70
  token = this.tn.peek();
70
- if (token === "public") // ignored
71
+ if (token === "public" || (weak = token === "weak")) // token ignored
71
72
  this.tn.next();
72
73
  token = this._readString();
73
74
  this.tn.skip(";");
74
- topLevel["imports"].push(token);
75
+ if (!weak) // import ignored
76
+ topLevel["imports"].push(token);
75
77
  break;
76
78
  case 'syntax':
77
79
  if (!head)
@@ -396,6 +398,7 @@ ParserPrototype._parseMessage = function(parent, fld) {
396
398
  "enums": [],
397
399
  "messages": [],
398
400
  "options": {},
401
+ "services": [],
399
402
  "oneofs": {}
400
403
  // "extensions": undefined
401
404
  };
@@ -422,8 +425,12 @@ ParserPrototype._parseMessage = function(parent, fld) {
422
425
  this._parseMessage(msg);
423
426
  else if (token === "option")
424
427
  this._parseOption(msg);
428
+ else if (token === "service")
429
+ this._parseService(msg);
425
430
  else if (token === "extensions")
426
- this._parseExtensions(msg);
431
+ msg["extensions"] = this._parseExtensionRanges();
432
+ else if (token === "reserved")
433
+ this._parseIgnored(); // TODO
427
434
  else if (token === "extend")
428
435
  this._parseExtend(msg);
429
436
  else if (Lang.TYPEREF.test(token)) {
@@ -438,6 +445,16 @@ ParserPrototype._parseMessage = function(parent, fld) {
438
445
  return msg;
439
446
  };
440
447
 
448
+ /**
449
+ * Parses an ignored statement.
450
+ * @private
451
+ */
452
+ ParserPrototype._parseIgnored = function() {
453
+ while (this.tn.peek() !== ';')
454
+ this.tn.next();
455
+ this.tn.skip(";");
456
+ };
457
+
441
458
  /**
442
459
  * Parses a message field.
443
460
  * @param {!Object} msg Message definition
@@ -600,29 +617,43 @@ ParserPrototype._parseEnum = function(msg) {
600
617
  };
601
618
 
602
619
  /**
603
- * Parses an extensions statement.
604
- * @param {!Object} msg Message object
620
+ * Parses extension / reserved ranges.
621
+ * @returns {!Array.<!Array.<number>>}
605
622
  * @private
606
623
  */
607
- ParserPrototype._parseExtensions = function(msg) {
608
- var token = this.tn.next(),
624
+ ParserPrototype._parseExtensionRanges = function() {
625
+ var ranges = [];
626
+ var token,
627
+ range,
628
+ value;
629
+ do {
609
630
  range = [];
610
- if (token === "min")
611
- range.push(ProtoBuf.ID_MIN);
612
- else if (token === "max")
613
- range.push(ProtoBuf.ID_MAX);
614
- else
615
- range.push(mkNumber(token));
616
- this.tn.skip("to");
617
- token = this.tn.next();
618
- if (token === "min")
619
- range.push(ProtoBuf.ID_MIN);
620
- else if (token === "max")
621
- range.push(ProtoBuf.ID_MAX);
622
- else
623
- range.push(mkNumber(token));
631
+ while (true) {
632
+ token = this.tn.next();
633
+ switch (token) {
634
+ case "min":
635
+ value = ProtoBuf.ID_MIN;
636
+ break;
637
+ case "max":
638
+ value = ProtoBuf.ID_MAX;
639
+ break;
640
+ default:
641
+ value = mkNumber(token);
642
+ break;
643
+ }
644
+ range.push(value);
645
+ if (range.length === 2)
646
+ break;
647
+ if (this.tn.peek() !== "to") {
648
+ range.push(value);
649
+ break;
650
+ }
651
+ this.tn.next();
652
+ }
653
+ ranges.push(range);
654
+ } while (this.tn.omit(","));
624
655
  this.tn.skip(";");
625
- msg["extensions"] = range;
656
+ return ranges;
626
657
  };
627
658
 
628
659
  /**
@@ -102,9 +102,10 @@ function mkLong(value, unsigned) {
102
102
  * @expose
103
103
  */
104
104
  ElementPrototype.verifyValue = function(value) {
105
- var fail = function(val, msg) {
106
- throw Error("Illegal value for "+this.toString(true)+" of type "+this.type.name+": "+val+" ("+msg+")");
107
- }.bind(this);
105
+ var self = this;
106
+ function fail(val, msg) {
107
+ throw Error("Illegal value for "+self.toString(true)+" of type "+self.type.name+": "+val+" ("+msg+")");
108
+ }
108
109
  switch (this.type) {
109
110
  // Signed 32bit
110
111
  case ProtoBuf.TYPES["int32"]:
@@ -165,9 +165,10 @@ FieldPrototype.build = function() {
165
165
  */
166
166
  FieldPrototype.verifyValue = function(value, skipRepeated) {
167
167
  skipRepeated = skipRepeated || false;
168
- var fail = function(val, msg) {
169
- throw Error("Illegal value for "+this.toString(true)+" of type "+this.type.name+": "+val+" ("+msg+")");
170
- }.bind(this);
168
+ var self = this;
169
+ function fail(val, msg) {
170
+ throw Error("Illegal value for "+self.toString(true)+" of type "+self.type.name+": "+val+" ("+msg+")");
171
+ }
171
172
  if (value === null) { // NULL values for optional fields
172
173
  if (this.required)
173
174
  fail(typeof value, "required");
@@ -20,10 +20,10 @@ var Message = function(builder, parent, name, options, isGroup, syntax) {
20
20
 
21
21
  /**
22
22
  * Extensions range.
23
- * @type {!Array.<number>}
23
+ * @type {!Array.<number>|undefined}
24
24
  * @expose
25
25
  */
26
- this.extensions = [ProtoBuf.ID_MIN, ProtoBuf.ID_MAX];
26
+ this.extensions = undefined;
27
27
 
28
28
  /**
29
29
  * Runtime message class.
@@ -204,7 +204,7 @@ function skipTillGroupEnd(expectedId, buf) {
204
204
  /**
205
205
  * Decodes an encoded message and returns the decoded message.
206
206
  * @param {ByteBuffer} buffer ByteBuffer to decode from
207
- * @param {number=} length Message length. Defaults to decode all the available data.
207
+ * @param {number=} length Message length. Defaults to decode all remaining data.
208
208
  * @param {number=} expectedGroupEndId Expected GROUPEND id if this is a legacy group
209
209
  * @return {ProtoBuf.Builder.Message} Decoded message
210
210
  * @throws {Error} If the message cannot be decoded
@@ -60,8 +60,9 @@ ProtoBuf.Util = (function() {
60
60
  if (callback && typeof callback != 'function')
61
61
  callback = null;
62
62
  if (Util.IS_NODE) {
63
+ var fs = require("fs");
63
64
  if (callback) {
64
- Util.require("fs").readFile(path, function(err, data) {
65
+ fs.readFile(path, function(err, data) {
65
66
  if (err)
66
67
  callback(null);
67
68
  else
@@ -69,7 +70,7 @@ ProtoBuf.Util = (function() {
69
70
  });
70
71
  } else
71
72
  try {
72
- return Util.require("fs").readFileSync(path);
73
+ return fs.readFileSync(path);
73
74
  } catch (e) {
74
75
  return null;
75
76
  }
@@ -99,18 +100,6 @@ ProtoBuf.Util = (function() {
99
100
  }
100
101
  };
101
102
 
102
- /**
103
- * Requires a node module.
104
- * @function
105
- * @param {string} path
106
- * @returns {*}
107
- * @throws Error If node require is not supported
108
- * @expose
109
- */
110
- Util.require = Util.IS_NODE
111
- ? function(path) { return nodeRequire(path); }
112
- : function(path) { throw Error("node require is not supported by this platform")};
113
-
114
103
  /**
115
104
  * Converts a string to camel case.
116
105
  * @param {string} str
package/src/bower.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "protobuf",
3
3
  "description": "Protocol Buffers for JavaScript. Finally.",
4
4
  "version": /*?== VERSION */,
5
- "main": "dist/ProtoBuf.js",
5
+ "main": "dist/protobuf.js",
6
6
  "license": "Apache-2.0",
7
7
  "homepage": "http://dcode.io/",
8
8
  "dependencies": {
@@ -484,8 +484,10 @@
484
484
  }
485
485
  ],
486
486
  "extensions": [
487
- 1000,
488
- 536870911
487
+ [
488
+ 1000,
489
+ 536870911
490
+ ]
489
491
  ],
490
492
  "enums": [
491
493
  {
@@ -536,8 +538,10 @@
536
538
  }
537
539
  ],
538
540
  "extensions": [
539
- 1000,
540
- 536870911
541
+ [
542
+ 1000,
543
+ 536870911
544
+ ]
541
545
  ]
542
546
  },
543
547
  {
@@ -599,8 +603,10 @@
599
603
  }
600
604
  ],
601
605
  "extensions": [
602
- 1000,
603
- 536870911
606
+ [
607
+ 1000,
608
+ 536870911
609
+ ]
604
610
  ],
605
611
  "enums": [
606
612
  {
@@ -642,8 +648,10 @@
642
648
  }
643
649
  ],
644
650
  "extensions": [
645
- 1000,
646
- 536870911
651
+ [
652
+ 1000,
653
+ 536870911
654
+ ]
647
655
  ]
648
656
  },
649
657
  {
@@ -657,8 +665,10 @@
657
665
  }
658
666
  ],
659
667
  "extensions": [
660
- 1000,
661
- 536870911
668
+ [
669
+ 1000,
670
+ 536870911
671
+ ]
662
672
  ]
663
673
  },
664
674
  {
@@ -672,8 +682,10 @@
672
682
  }
673
683
  ],
674
684
  "extensions": [
675
- 1000,
676
- 536870911
685
+ [
686
+ 1000,
687
+ 536870911
688
+ ]
677
689
  ]
678
690
  },
679
691
  {
@@ -687,8 +699,10 @@
687
699
  }
688
700
  ],
689
701
  "extensions": [
690
- 1000,
691
- 536870911
702
+ [
703
+ 1000,
704
+ 536870911
705
+ ]
692
706
  ]
693
707
  },
694
708
  {
File without changes
package/src/wrap.js CHANGED
@@ -15,23 +15,23 @@
15
15
  */
16
16
 
17
17
  /**
18
- * @license ProtoBuf.js (c) 2013 Daniel Wirtz <dcode@dcode.io>
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/ProtoBuf.js for details
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(["ByteBuffer"], factory);
25
+ define(["bytebuffer"], factory);
26
26
  /* CommonJS */ else if (typeof require === "function" && typeof module === "object" && module && module["exports"])
27
- module["exports"] = factory(require("bytebuffer"), require);
27
+ module["exports"] = factory(require("bytebuffer"), true);
28
28
  /* Global */ else
29
29
  (global["dcodeIO"] = global["dcodeIO"] || {})["ProtoBuf"] = factory(global["dcodeIO"]["ByteBuffer"]);
30
30
 
31
- })(this, function(ByteBuffer, nodeRequire) {
31
+ })(this, function(ByteBuffer, isCommonJS) {
32
32
  "use strict";
33
33
 
34
- //? include("ProtoBuf.js");
34
+ //? include("protobuf.js");
35
35
 
36
36
  return ProtoBuf;
37
37
  });
@@ -0,0 +1,7 @@
1
+ package My;
2
+
3
+ import weak "example1.proto";
4
+
5
+ message Test2 {
6
+ required Test1 test1 = 1;
7
+ }