protobufjs 3.6.0 → 3.8.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.
Files changed (99) hide show
  1. package/bin/proto2js +16 -4
  2. package/bower.json +1 -1
  3. package/dist/ProtoBuf.js +645 -441
  4. package/dist/ProtoBuf.min.js +96 -96
  5. package/dist/ProtoBuf.min.js.gz +0 -0
  6. package/dist/ProtoBuf.min.map +2 -2
  7. package/dist/ProtoBuf.noparse.js +520 -357
  8. package/dist/ProtoBuf.noparse.min.js +68 -66
  9. package/dist/ProtoBuf.noparse.min.js.gz +0 -0
  10. package/dist/ProtoBuf.noparse.min.map +3 -3
  11. package/docs/ProtoBuf.Builder.Message.html +673 -135
  12. package/docs/ProtoBuf.Builder.Service.html +58 -19
  13. package/docs/ProtoBuf.Builder.html +374 -46
  14. package/docs/ProtoBuf.DotProto.Parser.html +58 -19
  15. package/docs/ProtoBuf.DotProto.Tokenizer.html +104 -19
  16. package/docs/ProtoBuf.DotProto.html +16 -10
  17. package/docs/ProtoBuf.Reflect.Enum.Value.html +207 -33
  18. package/docs/ProtoBuf.Reflect.Enum.html +318 -56
  19. package/docs/ProtoBuf.Reflect.Extension.html +53 -13
  20. package/docs/ProtoBuf.Reflect.Message.ExtensionField.html +450 -68
  21. package/docs/ProtoBuf.Reflect.Message.Field.html +454 -51
  22. package/docs/ProtoBuf.Reflect.Message.OneOf.html +1044 -0
  23. package/docs/ProtoBuf.Reflect.Message.html +378 -64
  24. package/docs/ProtoBuf.Reflect.Namespace.html +333 -51
  25. package/docs/ProtoBuf.Reflect.Service.Method.html +228 -35
  26. package/docs/ProtoBuf.Reflect.Service.RPCMethod.html +262 -41
  27. package/docs/ProtoBuf.Reflect.Service.html +318 -56
  28. package/docs/ProtoBuf.Reflect.T.html +210 -25
  29. package/docs/ProtoBuf.Reflect.html +17 -11
  30. package/docs/ProtoBuf.Util.html +59 -13
  31. package/docs/ProtoBuf.html +235 -67
  32. package/docs/ProtoBuf.js.html +648 -443
  33. package/docs/index.html +4 -2
  34. package/docs/styles/jsdoc-default.css +2 -2
  35. package/examples/protoify/.npmignore +2 -0
  36. package/examples/protoify/README.md +28 -0
  37. package/examples/protoify/index.js +147 -0
  38. package/examples/protoify/json.js +123 -0
  39. package/examples/protoify/json.json +123 -0
  40. package/examples/protoify/json.proto +30 -0
  41. package/examples/protoify/package.json +15 -0
  42. package/examples/protoify/test.js +56 -0
  43. package/examples/websocket/README.md +1 -0
  44. package/examples/websocket/package.json +1 -1
  45. package/externs/ProtoBuf.js +922 -922
  46. package/package.json +3 -3
  47. package/scripts/build.js +58 -58
  48. package/src/ProtoBuf/Builder/Message.js +107 -77
  49. package/src/ProtoBuf/Builder/Service.js +8 -5
  50. package/src/ProtoBuf/Builder.js +71 -37
  51. package/src/ProtoBuf/DotProto/Parser.js +108 -72
  52. package/src/ProtoBuf/DotProto/Tokenizer.js +17 -11
  53. package/src/ProtoBuf/Lang.js +1 -1
  54. package/src/ProtoBuf/Reflect/Enum/Value.js +3 -2
  55. package/src/ProtoBuf/Reflect/Enum.js +9 -5
  56. package/src/ProtoBuf/Reflect/Extension.js +4 -3
  57. package/src/ProtoBuf/Reflect/Message/ExtensionField.js +4 -3
  58. package/src/ProtoBuf/Reflect/Message/Field.js +45 -26
  59. package/src/ProtoBuf/Reflect/Message/OneOf.js +19 -0
  60. package/src/ProtoBuf/Reflect/Message.js +36 -19
  61. package/src/ProtoBuf/Reflect/Namespace.js +19 -15
  62. package/src/ProtoBuf/Reflect/Service/Method.js +9 -5
  63. package/src/ProtoBuf/Reflect/Service/RPCMethod.js +3 -2
  64. package/src/ProtoBuf/Reflect/Service.js +9 -5
  65. package/src/ProtoBuf/Reflect/T.js +20 -6
  66. package/src/ProtoBuf/Reflect.js +9 -0
  67. package/src/ProtoBuf/Util.js +132 -132
  68. package/src/ProtoBuf.js +15 -17
  69. package/src/google/protobuf/descriptor.json +33 -13
  70. package/tests/bench.txt +373 -373
  71. package/tests/complex.json +8 -4
  72. package/tests/custom-options.json +169 -169
  73. package/tests/extend.json +71 -71
  74. package/tests/nodeunit-browser/nodeunit.css +70 -70
  75. package/tests/nodeunit-browser/nodeunit.js +2108 -2108
  76. package/tests/oneof.proto +6 -0
  77. package/tests/options.json +32 -32
  78. package/tests/options.proto +2 -0
  79. package/tests/proto2js/Bar.json +46 -46
  80. package/tests/suite.js +83 -12
  81. package/.idea/.name +0 -1
  82. package/.idea/ProtoBuf.iml +0 -9
  83. package/.idea/dictionaries/Daniel.xml +0 -7
  84. package/.idea/encodings.xml +0 -5
  85. package/.idea/misc.xml +0 -5
  86. package/.idea/modules.xml +0 -9
  87. package/.idea/scopes/scope_settings.xml +0 -5
  88. package/.idea/vcs.xml +0 -7
  89. package/.idea/workspace.xml +0 -551
  90. package/NOTICE +0 -2
  91. package/sandbox/issue146/MyOptions.proto +0 -28
  92. package/sandbox/issue146/Sample.proto +0 -21
  93. package/sandbox/issue146/main.js +0 -3
  94. package/sandbox/issue147/enum.proto +0 -8
  95. package/sandbox/issue147/main.js +0 -3
  96. package/sandbox/issue42/innerextend.proto +0 -18
  97. package/sandbox/issue42/main.js +0 -8
  98. package/sandbox/issue42/outerextend.proto +0 -17
  99. package/v8.log +0 -3828
package/docs/index.html CHANGED
@@ -22,6 +22,7 @@
22
22
 
23
23
 
24
24
 
25
+
25
26
 
26
27
 
27
28
 
@@ -35,6 +36,7 @@
35
36
 
36
37
 
37
38
 
39
+
38
40
 
39
41
 
40
42
 
@@ -48,13 +50,13 @@
48
50
  </div>
49
51
 
50
52
  <nav>
51
- <h2><a href="index.html">Index</a></h2><h3>Classes</h3><ul><li><a href="ProtoBuf.Builder.html">Builder</a></li><li><a href="ProtoBuf.Builder.Message.html">Message</a></li><li><a href="ProtoBuf.Builder.Service.html">Service</a></li><li><a href="ProtoBuf.DotProto.Parser.html">Parser</a></li><li><a href="ProtoBuf.DotProto.Tokenizer.html">Tokenizer</a></li><li><a href="ProtoBuf.Reflect.Enum.html">Enum</a></li><li><a href="ProtoBuf.Reflect.Enum.Value.html">Value</a></li><li><a href="ProtoBuf.Reflect.Extension.html">Extension</a></li><li><a href="ProtoBuf.Reflect.Message.html">Message</a></li><li><a href="ProtoBuf.Reflect.Message.ExtensionField.html">ExtensionField</a></li><li><a href="ProtoBuf.Reflect.Message.Field.html">Field</a></li><li><a href="ProtoBuf.Reflect.Namespace.html">Namespace</a></li><li><a href="ProtoBuf.Reflect.Service.html">Service</a></li><li><a href="ProtoBuf.Reflect.Service.Method.html">Method</a></li><li><a href="ProtoBuf.Reflect.Service.RPCMethod.html">RPCMethod</a></li><li><a href="ProtoBuf.Reflect.T.html">T</a></li></ul><h3>Namespaces</h3><ul><li><a href="ProtoBuf.html">ProtoBuf</a></li><li><a href="ProtoBuf.DotProto.html">DotProto</a></li><li><a href="ProtoBuf.Reflect.html">Reflect</a></li><li><a href="ProtoBuf.Util.html">Util</a></li></ul>
53
+ <h2><a href="index.html">Index</a></h2><h3>Classes</h3><ul><li><a href="ProtoBuf.Builder.html">Builder</a></li><li><a href="ProtoBuf.Builder.Message.html">Message</a></li><li><a href="ProtoBuf.Builder.Service.html">Service</a></li><li><a href="ProtoBuf.DotProto.Parser.html">Parser</a></li><li><a href="ProtoBuf.DotProto.Tokenizer.html">Tokenizer</a></li><li><a href="ProtoBuf.Reflect.Enum.html">Enum</a></li><li><a href="ProtoBuf.Reflect.Enum.Value.html">Value</a></li><li><a href="ProtoBuf.Reflect.Extension.html">Extension</a></li><li><a href="ProtoBuf.Reflect.Message.html">Message</a></li><li><a href="ProtoBuf.Reflect.Message.ExtensionField.html">ExtensionField</a></li><li><a href="ProtoBuf.Reflect.Message.Field.html">Field</a></li><li><a href="ProtoBuf.Reflect.Message.OneOf.html">OneOf</a></li><li><a href="ProtoBuf.Reflect.Namespace.html">Namespace</a></li><li><a href="ProtoBuf.Reflect.Service.html">Service</a></li><li><a href="ProtoBuf.Reflect.Service.Method.html">Method</a></li><li><a href="ProtoBuf.Reflect.Service.RPCMethod.html">RPCMethod</a></li><li><a href="ProtoBuf.Reflect.T.html">T</a></li></ul><h3>Namespaces</h3><ul><li><a href="ProtoBuf.html">ProtoBuf</a></li><li><a href="ProtoBuf.DotProto.html">DotProto</a></li><li><a href="ProtoBuf.Reflect.html">Reflect</a></li><li><a href="ProtoBuf.Util.html">Util</a></li></ul>
52
54
  </nav>
53
55
 
54
56
  <br clear="both">
55
57
 
56
58
  <footer>
57
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Tue Aug 26 2014 22:15:41 GMT+0200 (Mitteleuropäische Sommerzeit)
59
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha10</a> on Mon Nov 24 2014 18:08:27 GMT+0100 (Mitteleuropäische Zeit)
58
60
  </footer>
59
61
 
60
62
  <script> prettyPrint(); </script>
@@ -195,8 +195,8 @@ h6
195
195
  }
196
196
 
197
197
  .details { margin-top: 14px; border-left: 2px solid #DDD; }
198
- .details dt { width:100px; float:left; padding-left: 10px; padding-top: 6px; }
199
- .details dd { margin-left: 50px; }
198
+ .details dt { width:120px; float:left; padding-left: 10px; padding-top: 6px; }
199
+ .details dd { margin-left: 70px; }
200
200
  .details ul { margin: 0; }
201
201
  .details ul { list-style-type: none; }
202
202
  .details li { margin-left: 30px; padding-top: 6px; }
@@ -0,0 +1,2 @@
1
+ node_modules/
2
+ npm-debug.log
@@ -0,0 +1,28 @@
1
+ ProtoBuf.js protoify example
2
+ ============================
3
+ This example shows the general usage of ProtoBuf.js by converting JSON structures to protocol buffers and vice versa
4
+ using a definition describing JSON itself. While this works as an example, it does not provide any real world benefits
5
+ (well, this is if you are not building a protobuf-backed database for JSON data, using inter-field substitution to
6
+ minimize redundancy - nevermind, forget that).
7
+
8
+ Instructions
9
+ ------------
10
+ 1. Set up dependencies: `npm install`
11
+ 2. Run: `npm test`
12
+
13
+ Now you know no more and no less than that it works and you might want to inspect the following files to get the 'how':
14
+
15
+ * **[index.js](https://github.com/dcodeIO/ProtoBuf.js/blob/master/examples/protoify/index.js)**
16
+ contains the sample's source code
17
+
18
+ * **[json.proto](https://github.com/dcodeIO/ProtoBuf.js/blob/master/examples/protoify/json.proto)**
19
+ contains the protobuf definition used
20
+
21
+ * **[json.json](https://github.com/dcodeIO/ProtoBuf.js/blob/master/examples/protoify/json.json)**
22
+ contains the protobuf definition converted through `proto2js json.proto > json.json`
23
+
24
+ * **[json.js](https://github.com/dcodeIO/ProtoBuf.js/blob/master/examples/protoify/json.js)**
25
+ contains the protobuf definition converted through `proto2js json.proto -commonjs=js > json.js`
26
+
27
+ * **[test.js](https://github.com/dcodeIO/ProtoBuf.js/blob/master/examples/protoify/test.js)**
28
+ contains our simple test suite
@@ -0,0 +1,147 @@
1
+ var ProtoBuf = require("protobufjs"),
2
+ ByteBuffer = ProtoBuf.ByteBuffer, // ProtoBuf.js uses and also exposes ByteBuffer.js
3
+ Long = ProtoBuf.Long; // as well as Long.js (not used in this example)
4
+
5
+ // Option 1: Loading the .proto file directly
6
+ var builder = ProtoBuf.loadProtoFile("./json.proto"), // Creates the Builder
7
+ JS = builder.build("js"); // Returns just the 'js' namespace if that's all we need
8
+
9
+ // Option 2: Loading the .json file generated through 'proto2js json.proto > json.json'
10
+ var root = ProtoBuf.loadJsonFile("./json.json").build(), // Here we make the Builder return the root namespace
11
+ JS = root.js; // then we reference 'js' inside. Both is possible.
12
+
13
+ // Option 3: Loading the module generated through 'proto2js json.proto -commonjs=js > json.js'
14
+ var JS = require("./json.js"); // Returns what is specified with -commonjs[=XX] (omitted=root)
15
+
16
+ // `JS` now contains the js namespace from json.proto: Value, Array and Object
17
+
18
+ // This is how we use these classes:
19
+
20
+ /**
21
+ * Converts a JSON-like structure to JS-Namespace values.
22
+ * @param {*} val JSON
23
+ * @returns {!JS.Value} JS-Namespace value
24
+ * @inner
25
+ */
26
+ function _protoify(val) {
27
+ switch (typeof val) {
28
+ case 'number':
29
+ if (val%1 === 0 && val >= (0x80000000|0) && val <= (0x7fffffff|0))
30
+ return new JS.Value(val); // sets the first field declared in .js.Value
31
+ else
32
+ return new JS.Value(null, val); // sets the second field
33
+ case 'string':
34
+ return new JS.Value({ 'string': val }); // uses object notation instead
35
+ case 'boolean':
36
+ return new JS.Value({ 'boolean': val });
37
+ case 'object':
38
+ if (val === null)
39
+ return new JS.Value({ 'null': true });
40
+ if (Object.prototype.toString.call(val) === "[object Array]") {
41
+ var arr = new JS.Array();
42
+ for (var i=0; i<val.length; ++i)
43
+ arr['values'][i] = _protoify(val[i]);
44
+ return new JS.Value({ 'array': arr });
45
+ }
46
+ var obj = new JS.Object();
47
+ for (var key in val)
48
+ if (val.hasOwnProperty(key))
49
+ obj['keys'].push(_protoify(key)),
50
+ obj['values'].push(_protoify(val[key]));
51
+ return new JS.Value({ 'object': obj });
52
+ case 'undefined':
53
+ return new JS.Value(); // undefined
54
+ default:
55
+ throw Error("Unsupported type: "+(typeof val)); // symbol, function
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Converts JS-Namespace values to JSON.
61
+ * @param {!JS.Value} value JS value
62
+ * @returns {*} JSON
63
+ * @inner
64
+ */
65
+ function _jsonify(value) {
66
+ if (value.type === null)
67
+ return undefined;
68
+ switch (value.type) {
69
+ case 'null':
70
+ return null;
71
+ case 'array':
72
+ return (function() {
73
+ var values = value['array']['values'],
74
+ i = 0,
75
+ k = values.length,
76
+ arr = new Array(k);
77
+ for (; i<k; ++i)
78
+ arr[i] = _jsonify(values[i]);
79
+ return arr;
80
+ })();
81
+ case 'object':
82
+ return (function() {
83
+ var keys = value['object']['keys'],
84
+ values = value['object']['values'],
85
+ i = 0,
86
+ k = keys.length,
87
+ obj = {};
88
+ for (; i<k; ++i)
89
+ obj[keys[i]['string'] /* is a JS.Value, here always a string */] = _jsonify(values[i]);
90
+ return obj;
91
+ })();
92
+ default:
93
+ return value[value.type];
94
+ }
95
+ }
96
+
97
+ // And this is how we actually encode and decode them:
98
+
99
+ /**
100
+ * A temporary Buffer to speed up encoding.
101
+ * @type {!ByteBuffer}
102
+ * @inner
103
+ */
104
+ var tempBuffer = ByteBuffer.allocate(1024);
105
+
106
+ /**
107
+ * Converts a JSON structure to a Buffer.
108
+ * @param {*} json JSON
109
+ * @returns {!Buffer|!ArrayBuffer}
110
+ * @expose
111
+ */
112
+ module.exports = function(json) {
113
+ return _protoify(json) // Returns the root JS.Value
114
+ .encode(tempBuffer).flip() // Encodes it to a ByteBuffer, here: reusing tempBuffer forever
115
+ // The non-tempBuffer alternative is just doing .encode()
116
+ .toBuffer(); // Converts it to a Buffer. In the browser, this returns an ArrayBuffer. To return an
117
+ // ArrayBuffer explicitly both under node.js and in the browser, use .toArrayBuffer().
118
+ // Performance note: This just returns a slice on the ByteBuffer's backing .buffer
119
+ };
120
+
121
+ /**
122
+ * Converts a Buffer to a JSON structure.
123
+ * @param {!Buffer|!ArrayBuffer} proto Buffer
124
+ * @returns {*} JSON
125
+ * @expose
126
+ */
127
+ module.exports.parse = function(proto) {
128
+ return _jsonify( // Processes JS-namespace objects
129
+ JS.Value.decode(proto) // Decodes the JS.Value from a ByteBuffer, a Buffer, an ArrayBuffer, an Uint8Array, ...
130
+ );
131
+ };
132
+
133
+ /**
134
+ * Performs maintenance.
135
+ * @expose
136
+ */
137
+ module.exports.performMaintenance = function() {
138
+ if (tempBuffer.capacity() > 2048)
139
+ tempBuffer = ByteBuffer.allocate(1024);
140
+ // In case this module is running inside of a daemon, we'd just call this
141
+ // method every now and then to discard the tempBuffer if it becomes too
142
+ // large. This is just an example on how to reuse ByteBuffers effectively.
143
+ // You may consider something like this for the performance benefit, which
144
+ // is decreasing the memory allocation footprint of your app.
145
+ };
146
+
147
+ // Have a nice day!
@@ -0,0 +1,123 @@
1
+ module.exports = require("protobufjs").newBuilder({})["import"]({
2
+ "package": "js",
3
+ "messages": [
4
+ {
5
+ "name": "Value",
6
+ "fields": [
7
+ {
8
+ "rule": "optional",
9
+ "options": {},
10
+ "type": "sint32",
11
+ "name": "integer",
12
+ "id": 1,
13
+ "oneof": "type"
14
+ },
15
+ {
16
+ "rule": "optional",
17
+ "options": {},
18
+ "type": "double",
19
+ "name": "double",
20
+ "id": 2,
21
+ "oneof": "type"
22
+ },
23
+ {
24
+ "rule": "optional",
25
+ "options": {},
26
+ "type": "string",
27
+ "name": "string",
28
+ "id": 3,
29
+ "oneof": "type"
30
+ },
31
+ {
32
+ "rule": "optional",
33
+ "options": {},
34
+ "type": "bool",
35
+ "name": "boolean",
36
+ "id": 4,
37
+ "oneof": "type"
38
+ },
39
+ {
40
+ "rule": "optional",
41
+ "options": {},
42
+ "type": "bool",
43
+ "name": "null",
44
+ "id": 5,
45
+ "oneof": "type"
46
+ },
47
+ {
48
+ "rule": "optional",
49
+ "options": {},
50
+ "type": "Array",
51
+ "name": "array",
52
+ "id": 6,
53
+ "oneof": "type"
54
+ },
55
+ {
56
+ "rule": "optional",
57
+ "options": {},
58
+ "type": "Object",
59
+ "name": "object",
60
+ "id": 7,
61
+ "oneof": "type"
62
+ }
63
+ ],
64
+ "enums": [],
65
+ "messages": [],
66
+ "options": {},
67
+ "oneofs": {
68
+ "type": [
69
+ 1,
70
+ 2,
71
+ 3,
72
+ 4,
73
+ 5,
74
+ 6,
75
+ 7
76
+ ]
77
+ }
78
+ },
79
+ {
80
+ "name": "Array",
81
+ "fields": [
82
+ {
83
+ "rule": "repeated",
84
+ "options": {},
85
+ "type": "Value",
86
+ "name": "values",
87
+ "id": 1
88
+ }
89
+ ],
90
+ "enums": [],
91
+ "messages": [],
92
+ "options": {},
93
+ "oneofs": {}
94
+ },
95
+ {
96
+ "name": "Object",
97
+ "fields": [
98
+ {
99
+ "rule": "repeated",
100
+ "options": {},
101
+ "type": "Value",
102
+ "name": "keys",
103
+ "id": 1
104
+ },
105
+ {
106
+ "rule": "repeated",
107
+ "options": {},
108
+ "type": "Value",
109
+ "name": "values",
110
+ "id": 2
111
+ }
112
+ ],
113
+ "enums": [],
114
+ "messages": [],
115
+ "options": {},
116
+ "oneofs": {}
117
+ }
118
+ ],
119
+ "enums": [],
120
+ "imports": [],
121
+ "options": {},
122
+ "services": []
123
+ }).build("js");
@@ -0,0 +1,123 @@
1
+ {
2
+ "package": "js",
3
+ "messages": [
4
+ {
5
+ "name": "Value",
6
+ "fields": [
7
+ {
8
+ "rule": "optional",
9
+ "options": {},
10
+ "type": "sint32",
11
+ "name": "integer",
12
+ "id": 1,
13
+ "oneof": "type"
14
+ },
15
+ {
16
+ "rule": "optional",
17
+ "options": {},
18
+ "type": "double",
19
+ "name": "double",
20
+ "id": 2,
21
+ "oneof": "type"
22
+ },
23
+ {
24
+ "rule": "optional",
25
+ "options": {},
26
+ "type": "string",
27
+ "name": "string",
28
+ "id": 3,
29
+ "oneof": "type"
30
+ },
31
+ {
32
+ "rule": "optional",
33
+ "options": {},
34
+ "type": "bool",
35
+ "name": "boolean",
36
+ "id": 4,
37
+ "oneof": "type"
38
+ },
39
+ {
40
+ "rule": "optional",
41
+ "options": {},
42
+ "type": "bool",
43
+ "name": "null",
44
+ "id": 5,
45
+ "oneof": "type"
46
+ },
47
+ {
48
+ "rule": "optional",
49
+ "options": {},
50
+ "type": "Array",
51
+ "name": "array",
52
+ "id": 6,
53
+ "oneof": "type"
54
+ },
55
+ {
56
+ "rule": "optional",
57
+ "options": {},
58
+ "type": "Object",
59
+ "name": "object",
60
+ "id": 7,
61
+ "oneof": "type"
62
+ }
63
+ ],
64
+ "enums": [],
65
+ "messages": [],
66
+ "options": {},
67
+ "oneofs": {
68
+ "type": [
69
+ 1,
70
+ 2,
71
+ 3,
72
+ 4,
73
+ 5,
74
+ 6,
75
+ 7
76
+ ]
77
+ }
78
+ },
79
+ {
80
+ "name": "Array",
81
+ "fields": [
82
+ {
83
+ "rule": "repeated",
84
+ "options": {},
85
+ "type": "Value",
86
+ "name": "values",
87
+ "id": 1
88
+ }
89
+ ],
90
+ "enums": [],
91
+ "messages": [],
92
+ "options": {},
93
+ "oneofs": {}
94
+ },
95
+ {
96
+ "name": "Object",
97
+ "fields": [
98
+ {
99
+ "rule": "repeated",
100
+ "options": {},
101
+ "type": "Value",
102
+ "name": "keys",
103
+ "id": 1
104
+ },
105
+ {
106
+ "rule": "repeated",
107
+ "options": {},
108
+ "type": "Value",
109
+ "name": "values",
110
+ "id": 2
111
+ }
112
+ ],
113
+ "enums": [],
114
+ "messages": [],
115
+ "options": {},
116
+ "oneofs": {}
117
+ }
118
+ ],
119
+ "enums": [],
120
+ "imports": [],
121
+ "options": {},
122
+ "services": []
123
+ }
@@ -0,0 +1,30 @@
1
+ // Everything below is located in the js-namespace
2
+ package js;
3
+
4
+ // Represents a JavaScript value.
5
+ // Contains exactly one or zero fields.
6
+ message Value {
7
+ oneof type {
8
+ sint32 integer = 1;
9
+ double double = 2;
10
+ string string = 3;
11
+ bool boolean = 4;
12
+ bool null = 5;
13
+ Array array = 6;
14
+ Object object = 7;
15
+ // if none is set: undefined
16
+ }
17
+ }
18
+
19
+ // Represents a JavaScript array.
20
+ // Contains zero to N values.
21
+ message Array {
22
+ repeated Value values = 1;
23
+ }
24
+
25
+ // Represents a JavaScript object.
26
+ // Contains zero to N keys with associated values.
27
+ message Object {
28
+ repeated Value keys = 1;
29
+ repeated Value values = 2;
30
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "protobufjs-protoify-example",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "dependencies": {
6
+ "protobufjs": "~3.7"
7
+ },
8
+ "engines": {
9
+ "node": ">=0.8"
10
+ },
11
+ "scripts": {
12
+ "test": "node test.js"
13
+ },
14
+ "private": true
15
+ }
@@ -0,0 +1,56 @@
1
+ var protoify = require("./index.js"),
2
+ ByteBuffer = require("protobufjs").ByteBuffer,
3
+ assert = require("assert");
4
+
5
+ // Array of samples to test
6
+ var samples = [
7
+ 1, -1, 0x80000000|0, 0x7fffffff|0, // Integers
8
+ 0.1, 0.2, 1.234, // Doubles
9
+ "John", // String
10
+ true, false, // Booleans
11
+ null, // null
12
+ [], // Array
13
+ {}, // Object
14
+ undefined, // undefined
15
+ [ // Array holding each data type
16
+ 1,
17
+ 0.1,
18
+ "John",
19
+ true,
20
+ false,
21
+ null,
22
+ [],
23
+ {},
24
+ undefined
25
+ ],
26
+ { // Object holding each data type
27
+ 1: 1,
28
+ 0.1: 0.1,
29
+ "John": "John",
30
+ true: true,
31
+ false: false,
32
+ null: null,
33
+ array: [],
34
+ object: {},
35
+ undefined: undefined
36
+ }
37
+ ];
38
+
39
+ samples.forEach(function(sample) {
40
+ // Encode each sample to a Buffer
41
+ var buf = protoify(sample);
42
+
43
+ // Print some nice debugging information
44
+ console.log(JSON.stringify(sample));
45
+ console.log("-------------------------------------------------------------------");
46
+ console.log(ByteBuffer.wrap(buf).toDebug(true));
47
+
48
+ // Decode the Buffer back to JSON
49
+ var decodedSample = protoify.parse(buf);
50
+
51
+ // And assert that it's actually equal
52
+ assert.deepEqual(decodedSample, sample);
53
+ });
54
+
55
+ // If no assertion errors are thrown, print
56
+ console.log("OK");
@@ -1,5 +1,6 @@
1
1
  ProtoBuf.js WebSocket example
2
2
  =============================
3
+ This example shows how to use binary websockets to transfer protocol buffers.
3
4
 
4
5
  Instructions
5
6
  ------------
@@ -7,7 +7,7 @@
7
7
  "open": "0.0.3"
8
8
  },
9
9
  "engines": {
10
- "node": ">=0.6"
10
+ "node": ">=0.8"
11
11
  },
12
12
  "scripts": {
13
13
  "run": "node server.js"