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.
- package/bin/proto2js +16 -4
- package/bower.json +1 -1
- package/dist/ProtoBuf.js +645 -441
- package/dist/ProtoBuf.min.js +96 -96
- package/dist/ProtoBuf.min.js.gz +0 -0
- package/dist/ProtoBuf.min.map +2 -2
- package/dist/ProtoBuf.noparse.js +520 -357
- package/dist/ProtoBuf.noparse.min.js +68 -66
- package/dist/ProtoBuf.noparse.min.js.gz +0 -0
- package/dist/ProtoBuf.noparse.min.map +3 -3
- package/docs/ProtoBuf.Builder.Message.html +673 -135
- package/docs/ProtoBuf.Builder.Service.html +58 -19
- package/docs/ProtoBuf.Builder.html +374 -46
- package/docs/ProtoBuf.DotProto.Parser.html +58 -19
- package/docs/ProtoBuf.DotProto.Tokenizer.html +104 -19
- package/docs/ProtoBuf.DotProto.html +16 -10
- package/docs/ProtoBuf.Reflect.Enum.Value.html +207 -33
- package/docs/ProtoBuf.Reflect.Enum.html +318 -56
- package/docs/ProtoBuf.Reflect.Extension.html +53 -13
- package/docs/ProtoBuf.Reflect.Message.ExtensionField.html +450 -68
- package/docs/ProtoBuf.Reflect.Message.Field.html +454 -51
- package/docs/ProtoBuf.Reflect.Message.OneOf.html +1044 -0
- package/docs/ProtoBuf.Reflect.Message.html +378 -64
- package/docs/ProtoBuf.Reflect.Namespace.html +333 -51
- package/docs/ProtoBuf.Reflect.Service.Method.html +228 -35
- package/docs/ProtoBuf.Reflect.Service.RPCMethod.html +262 -41
- package/docs/ProtoBuf.Reflect.Service.html +318 -56
- package/docs/ProtoBuf.Reflect.T.html +210 -25
- package/docs/ProtoBuf.Reflect.html +17 -11
- package/docs/ProtoBuf.Util.html +59 -13
- package/docs/ProtoBuf.html +235 -67
- package/docs/ProtoBuf.js.html +648 -443
- package/docs/index.html +4 -2
- package/docs/styles/jsdoc-default.css +2 -2
- package/examples/protoify/.npmignore +2 -0
- package/examples/protoify/README.md +28 -0
- package/examples/protoify/index.js +147 -0
- package/examples/protoify/json.js +123 -0
- package/examples/protoify/json.json +123 -0
- package/examples/protoify/json.proto +30 -0
- package/examples/protoify/package.json +15 -0
- package/examples/protoify/test.js +56 -0
- package/examples/websocket/README.md +1 -0
- package/examples/websocket/package.json +1 -1
- package/externs/ProtoBuf.js +922 -922
- package/package.json +3 -3
- package/scripts/build.js +58 -58
- package/src/ProtoBuf/Builder/Message.js +107 -77
- package/src/ProtoBuf/Builder/Service.js +8 -5
- package/src/ProtoBuf/Builder.js +71 -37
- package/src/ProtoBuf/DotProto/Parser.js +108 -72
- package/src/ProtoBuf/DotProto/Tokenizer.js +17 -11
- package/src/ProtoBuf/Lang.js +1 -1
- package/src/ProtoBuf/Reflect/Enum/Value.js +3 -2
- package/src/ProtoBuf/Reflect/Enum.js +9 -5
- package/src/ProtoBuf/Reflect/Extension.js +4 -3
- package/src/ProtoBuf/Reflect/Message/ExtensionField.js +4 -3
- package/src/ProtoBuf/Reflect/Message/Field.js +45 -26
- package/src/ProtoBuf/Reflect/Message/OneOf.js +19 -0
- package/src/ProtoBuf/Reflect/Message.js +36 -19
- package/src/ProtoBuf/Reflect/Namespace.js +19 -15
- package/src/ProtoBuf/Reflect/Service/Method.js +9 -5
- package/src/ProtoBuf/Reflect/Service/RPCMethod.js +3 -2
- package/src/ProtoBuf/Reflect/Service.js +9 -5
- package/src/ProtoBuf/Reflect/T.js +20 -6
- package/src/ProtoBuf/Reflect.js +9 -0
- package/src/ProtoBuf/Util.js +132 -132
- package/src/ProtoBuf.js +15 -17
- package/src/google/protobuf/descriptor.json +33 -13
- package/tests/bench.txt +373 -373
- package/tests/complex.json +8 -4
- package/tests/custom-options.json +169 -169
- package/tests/extend.json +71 -71
- package/tests/nodeunit-browser/nodeunit.css +70 -70
- package/tests/nodeunit-browser/nodeunit.js +2108 -2108
- package/tests/oneof.proto +6 -0
- package/tests/options.json +32 -32
- package/tests/options.proto +2 -0
- package/tests/proto2js/Bar.json +46 -46
- package/tests/suite.js +83 -12
- package/.idea/.name +0 -1
- package/.idea/ProtoBuf.iml +0 -9
- package/.idea/dictionaries/Daniel.xml +0 -7
- package/.idea/encodings.xml +0 -5
- package/.idea/misc.xml +0 -5
- package/.idea/modules.xml +0 -9
- package/.idea/scopes/scope_settings.xml +0 -5
- package/.idea/vcs.xml +0 -7
- package/.idea/workspace.xml +0 -551
- package/NOTICE +0 -2
- 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/issue42/innerextend.proto +0 -18
- package/sandbox/issue42/main.js +0 -8
- package/sandbox/issue42/outerextend.proto +0 -17
- package/v8.log +0 -3828
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*?
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
// --- Scope -----------------
|
|
3
|
+
// Lang : Language expressions
|
|
4
|
+
*/
|
|
5
5
|
/**
|
|
6
6
|
* Constructs a new Tokenizer.
|
|
7
7
|
* @exports ProtoBuf.DotProto.Tokenizer
|
|
8
|
-
* @class
|
|
8
|
+
* @class prototype tokenizer
|
|
9
9
|
* @param {string} proto Proto to tokenize
|
|
10
10
|
* @constructor
|
|
11
11
|
*/
|
|
@@ -54,22 +54,28 @@ var Tokenizer = function(proto) {
|
|
|
54
54
|
this.stringEndsWith = Lang.STRINGCLOSE;
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
+
/**
|
|
58
|
+
* @alias ProtoBuf.DotProto.Tokenizer.prototype
|
|
59
|
+
* @inner
|
|
60
|
+
*/
|
|
61
|
+
var TokenizerPrototype = Tokenizer.prototype;
|
|
62
|
+
|
|
57
63
|
/**
|
|
58
64
|
* Reads a string beginning at the current index.
|
|
59
65
|
* @return {string} The string
|
|
60
66
|
* @throws {Error} If it's not a valid string
|
|
61
67
|
* @private
|
|
62
68
|
*/
|
|
63
|
-
|
|
69
|
+
TokenizerPrototype._readString = function() {
|
|
64
70
|
Lang.STRING.lastIndex = this.index-1; // Include the open quote
|
|
65
71
|
var match;
|
|
66
72
|
if ((match = Lang.STRING.exec(this.source)) !== null) {
|
|
67
|
-
var s = match[1];
|
|
73
|
+
var s = typeof match[1] !== 'undefined' ? match[1] : match[2];
|
|
68
74
|
this.index = Lang.STRING.lastIndex;
|
|
69
75
|
this.stack.push(this.stringEndsWith);
|
|
70
76
|
return s;
|
|
71
77
|
}
|
|
72
|
-
throw Error("
|
|
78
|
+
throw Error("Unterminated string at line "+this.line+", index "+this.index);
|
|
73
79
|
};
|
|
74
80
|
|
|
75
81
|
/**
|
|
@@ -78,7 +84,7 @@ Tokenizer.prototype._readString = function() {
|
|
|
78
84
|
* @throws {Error} If it's not a valid proto file
|
|
79
85
|
* @expose
|
|
80
86
|
*/
|
|
81
|
-
|
|
87
|
+
TokenizerPrototype.next = function() {
|
|
82
88
|
if (this.stack.length > 0)
|
|
83
89
|
return this.stack.shift();
|
|
84
90
|
if (this.index >= this.source.length)
|
|
@@ -121,7 +127,7 @@ Tokenizer.prototype.next = function() {
|
|
|
121
127
|
this.index++;
|
|
122
128
|
repeat = true;
|
|
123
129
|
} else
|
|
124
|
-
throw Error("
|
|
130
|
+
throw Error("Unterminated comment at line "+this.line+": /"+this.source.charAt(this.index));
|
|
125
131
|
}
|
|
126
132
|
} while (repeat);
|
|
127
133
|
if (this.index === this.source.length) return null;
|
|
@@ -152,7 +158,7 @@ Tokenizer.prototype.next = function() {
|
|
|
152
158
|
* @throws {Error} If it's not a valid proto file
|
|
153
159
|
* @expose
|
|
154
160
|
*/
|
|
155
|
-
|
|
161
|
+
TokenizerPrototype.peek = function() {
|
|
156
162
|
if (this.stack.length === 0) {
|
|
157
163
|
var token = this.next();
|
|
158
164
|
if (token === null)
|
|
@@ -167,6 +173,6 @@ Tokenizer.prototype.peek = function() {
|
|
|
167
173
|
* @return {string} String representation as of "Tokenizer(index/length)"
|
|
168
174
|
* @expose
|
|
169
175
|
*/
|
|
170
|
-
|
|
176
|
+
TokenizerPrototype.toString = function() {
|
|
171
177
|
return "Tokenizer("+this.index+"/"+this.source.length+" at line "+this.line+")";
|
|
172
178
|
};
|
package/src/ProtoBuf/Lang.js
CHANGED
|
@@ -33,6 +33,6 @@ ProtoBuf.Lang = {
|
|
|
33
33
|
ID: /^(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/,
|
|
34
34
|
NEGID: /^\-?(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/,
|
|
35
35
|
WHITESPACE: /\s/,
|
|
36
|
-
STRING: /
|
|
36
|
+
STRING: /(?:"([^"\\]*(?:\\.[^"\\]*)*)")|(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g,
|
|
37
37
|
BOOL: /^(?:true|false)$/i
|
|
38
38
|
};
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Constructs a new Enum Value.
|
|
3
3
|
* @exports ProtoBuf.Reflect.Enum.Value
|
|
4
|
+
* @param {!ProtoBuf.Builder} builder Builder reference
|
|
4
5
|
* @param {!ProtoBuf.Reflect.Enum} enm Enum reference
|
|
5
6
|
* @param {string} name Field name
|
|
6
7
|
* @param {number} id Unique field id
|
|
7
8
|
* @constructor
|
|
8
9
|
* @extends ProtoBuf.Reflect.T
|
|
9
10
|
*/
|
|
10
|
-
var Value = function(enm, name, id) {
|
|
11
|
-
T.call(this, enm, name);
|
|
11
|
+
var Value = function(builder, enm, name, id) {
|
|
12
|
+
T.call(this, builder, enm, name);
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* @override
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Constructs a new Enum.
|
|
3
3
|
* @exports ProtoBuf.Reflect.Enum
|
|
4
|
+
* @param {!ProtoBuf.Builder} builder Builder reference
|
|
4
5
|
* @param {!ProtoBuf.Reflect.T} parent Parent Reflect object
|
|
5
6
|
* @param {string} name Enum name
|
|
6
7
|
* @param {Object.<string,*>=} options Enum options
|
|
7
8
|
* @constructor
|
|
8
9
|
* @extends ProtoBuf.Reflect.Namespace
|
|
9
10
|
*/
|
|
10
|
-
var Enum = function(parent, name, options) {
|
|
11
|
-
Namespace.call(this, parent, name, options);
|
|
11
|
+
var Enum = function(builder, parent, name, options) {
|
|
12
|
+
Namespace.call(this, builder, parent, name, options);
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* @override
|
|
@@ -23,15 +24,18 @@ var Enum = function(parent, name, options) {
|
|
|
23
24
|
this.object = null;
|
|
24
25
|
};
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
/**
|
|
28
|
+
* @alias ProtoBuf.Reflect.Enum.prototype
|
|
29
|
+
* @inner
|
|
30
|
+
*/
|
|
31
|
+
var EnumPrototype = Enum.prototype = Object.create(Namespace.prototype);
|
|
28
32
|
|
|
29
33
|
/**
|
|
30
34
|
* Builds this enum and returns the runtime counterpart.
|
|
31
35
|
* @return {Object<string,*>}
|
|
32
36
|
* @expose
|
|
33
37
|
*/
|
|
34
|
-
|
|
38
|
+
EnumPrototype.build = function() {
|
|
35
39
|
var enm = {},
|
|
36
40
|
values = this.getChildren(Enum.Value);
|
|
37
41
|
for (var i=0, k=values.length; i<k; ++i)
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
* An extension (field).
|
|
3
3
|
* @exports ProtoBuf.Reflect.Extension
|
|
4
4
|
* @constructor
|
|
5
|
-
* @param {ProtoBuf.
|
|
5
|
+
* @param {!ProtoBuf.Builder} builder Builder reference
|
|
6
|
+
* @param {!ProtoBuf.Reflect.T} parent Parent object
|
|
6
7
|
* @param {string} name Object name
|
|
7
8
|
* @param {!ProtoBuf.Reflect.Message.Field} field Extension field
|
|
8
9
|
*/
|
|
9
|
-
var Extension = function(parent, name, field) {
|
|
10
|
-
T.call(this, parent, name);
|
|
10
|
+
var Extension = function(builder, parent, name, field) {
|
|
11
|
+
T.call(this, builder, parent, name);
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Extended message field.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Constructs a new Message ExtensionField.
|
|
3
3
|
* @exports ProtoBuf.Reflect.Message.ExtensionField
|
|
4
|
-
* @param {ProtoBuf.
|
|
4
|
+
* @param {!ProtoBuf.Builder} builder Builder reference
|
|
5
|
+
* @param {!ProtoBuf.Reflect.Message} message Message reference
|
|
5
6
|
* @param {string} rule Rule, one of requried, optional, repeated
|
|
6
7
|
* @param {string} type Data type, e.g. int32
|
|
7
8
|
* @param {string} name Field name
|
|
@@ -10,8 +11,8 @@
|
|
|
10
11
|
* @constructor
|
|
11
12
|
* @extends ProtoBuf.Reflect.Message.Field
|
|
12
13
|
*/
|
|
13
|
-
var ExtensionField = function(message, rule, type, name, id, options) {
|
|
14
|
-
Field.call(this, message, rule, type, name, id, options);
|
|
14
|
+
var ExtensionField = function(builder, message, rule, type, name, id, options) {
|
|
15
|
+
Field.call(this, builder, message, rule, type, name, id, options);
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Extension reference.
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Constructs a new Message Field.
|
|
3
3
|
* @exports ProtoBuf.Reflect.Message.Field
|
|
4
|
-
* @param {ProtoBuf.
|
|
4
|
+
* @param {!ProtoBuf.Builder} builder Builder reference
|
|
5
|
+
* @param {!ProtoBuf.Reflect.Message} message Message reference
|
|
5
6
|
* @param {string} rule Rule, one of requried, optional, repeated
|
|
6
7
|
* @param {string} type Data type, e.g. int32
|
|
7
8
|
* @param {string} name Field name
|
|
8
9
|
* @param {number} id Unique field id
|
|
9
10
|
* @param {Object.<string,*>=} options Options
|
|
11
|
+
* @param {!ProtoBuf.Reflect.Message.OneOf=} oneof Enclosing OneOf
|
|
10
12
|
* @constructor
|
|
11
13
|
* @extends ProtoBuf.Reflect.T
|
|
12
14
|
*/
|
|
13
|
-
var Field = function(message, rule, type, name, id, options) {
|
|
14
|
-
T.call(this, message, name);
|
|
15
|
+
var Field = function(builder, message, rule, type, name, id, options, oneof) {
|
|
16
|
+
T.call(this, builder, message, name);
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
* @override
|
|
@@ -68,6 +70,13 @@ var Field = function(message, rule, type, name, id, options) {
|
|
|
68
70
|
*/
|
|
69
71
|
this.defaultValue = null;
|
|
70
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Enclosing OneOf.
|
|
75
|
+
* @type {?ProtoBuf.Reflect.Message.OneOf}
|
|
76
|
+
* @expose
|
|
77
|
+
*/
|
|
78
|
+
this.oneof = oneof || null;
|
|
79
|
+
|
|
71
80
|
/**
|
|
72
81
|
* Original field name.
|
|
73
82
|
* @type {string}
|
|
@@ -76,22 +85,34 @@ var Field = function(message, rule, type, name, id, options) {
|
|
|
76
85
|
this.originalName = this.name; // Used to revert camelcase transformation on naming collisions
|
|
77
86
|
|
|
78
87
|
// Convert field names to camel case notation if the override is set
|
|
79
|
-
if (
|
|
80
|
-
this.name = this.name
|
|
81
|
-
return $1.toUpperCase();
|
|
82
|
-
});
|
|
83
|
-
}
|
|
88
|
+
if (this.builder.options['convertFieldsToCamelCase'] && !(this instanceof Message.ExtensionField))
|
|
89
|
+
this.name = Field._toCamelCase(this.name);
|
|
84
90
|
};
|
|
85
91
|
|
|
86
|
-
|
|
87
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Converts a field name to camel case.
|
|
94
|
+
* @param {string} name Likely underscore notated name
|
|
95
|
+
* @returns {string} Camel case notated name
|
|
96
|
+
* @private
|
|
97
|
+
*/
|
|
98
|
+
Field._toCamelCase = function(name) {
|
|
99
|
+
return name.replace(/_([a-zA-Z])/g, function($0, $1) {
|
|
100
|
+
return $1.toUpperCase();
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @alias ProtoBuf.Reflect.Message.Field.prototype
|
|
106
|
+
* @inner
|
|
107
|
+
*/
|
|
108
|
+
var FieldPrototype = Field.prototype = Object.create(T.prototype);
|
|
88
109
|
|
|
89
110
|
/**
|
|
90
111
|
* Builds the field.
|
|
91
112
|
* @override
|
|
92
113
|
* @expose
|
|
93
114
|
*/
|
|
94
|
-
|
|
115
|
+
FieldPrototype.build = function() {
|
|
95
116
|
this.defaultValue = typeof this.options['default'] !== 'undefined'
|
|
96
117
|
? this.verifyValue(this.options['default']) : null;
|
|
97
118
|
};
|
|
@@ -124,7 +145,7 @@ function mkLong(value, unsigned) {
|
|
|
124
145
|
* @throws {Error} If the value cannot be set for this field
|
|
125
146
|
* @expose
|
|
126
147
|
*/
|
|
127
|
-
|
|
148
|
+
FieldPrototype.verifyValue = function(value, skipRepeated) {
|
|
128
149
|
skipRepeated = skipRepeated || false;
|
|
129
150
|
var fail = function(val, msg) {
|
|
130
151
|
throw Error("Illegal value for "+this.toString(true)+" of type "+this.type.name+": "+val+" ("+msg+")");
|
|
@@ -212,20 +233,18 @@ Field.prototype.verifyValue = function(value, skipRepeated) {
|
|
|
212
233
|
|
|
213
234
|
// Length-delimited bytes
|
|
214
235
|
case ProtoBuf.TYPES["bytes"]:
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
236
|
+
if (ByteBuffer.isByteBuffer(value))
|
|
237
|
+
return value;
|
|
238
|
+
return ByteBuffer.wrap(value, "base64");
|
|
218
239
|
|
|
219
240
|
// Constant enum value
|
|
220
241
|
case ProtoBuf.TYPES["enum"]: {
|
|
221
242
|
var values = this.resolvedType.getChildren(Enum.Value);
|
|
222
|
-
for (i=0; i<values.length; i++)
|
|
223
|
-
if (values[i].name == value)
|
|
243
|
+
for (i=0; i<values.length; i++)
|
|
244
|
+
if (values[i].name == value)
|
|
224
245
|
return values[i].id;
|
|
225
|
-
|
|
246
|
+
else if (values[i].id == value)
|
|
226
247
|
return values[i].id;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
248
|
fail(value, "not a valid enum value");
|
|
230
249
|
}
|
|
231
250
|
// Embedded message
|
|
@@ -260,7 +279,7 @@ Field.prototype.verifyValue = function(value, skipRepeated) {
|
|
|
260
279
|
* @throws {Error} If the field cannot be encoded
|
|
261
280
|
* @expose
|
|
262
281
|
*/
|
|
263
|
-
|
|
282
|
+
FieldPrototype.encode = function(value, buffer) {
|
|
264
283
|
if (this.type === null || typeof this.type !== 'object')
|
|
265
284
|
throw Error("[INTERNAL] Unresolved type in "+this.toString(true)+": "+this.type);
|
|
266
285
|
if (value === null || (this.repeated && value.length == 0))
|
|
@@ -312,7 +331,7 @@ Field.prototype.encode = function(value, buffer) {
|
|
|
312
331
|
* @throws {Error} If the value cannot be encoded
|
|
313
332
|
* @expose
|
|
314
333
|
*/
|
|
315
|
-
|
|
334
|
+
FieldPrototype.encodeValue = function(value, buffer) {
|
|
316
335
|
if (value === null) return buffer; // Nothing to encode
|
|
317
336
|
// Tag has already been written
|
|
318
337
|
|
|
@@ -433,7 +452,7 @@ Field.prototype.encodeValue = function(value, buffer) {
|
|
|
433
452
|
* @returns {number} Byte length
|
|
434
453
|
* @expose
|
|
435
454
|
*/
|
|
436
|
-
|
|
455
|
+
FieldPrototype.calculate = function(value) {
|
|
437
456
|
value = this.verifyValue(value); // May throw
|
|
438
457
|
if (this.type === null || typeof this.type !== 'object')
|
|
439
458
|
throw Error("[INTERNAL] Unresolved type in "+this.toString(true)+": "+this.type);
|
|
@@ -472,7 +491,7 @@ Field.prototype.calculate = function(value) {
|
|
|
472
491
|
* @throws {Error} If the value cannot be calculated
|
|
473
492
|
* @expose
|
|
474
493
|
*/
|
|
475
|
-
|
|
494
|
+
FieldPrototype.calculateValue = function(value) {
|
|
476
495
|
if (value === null) return 0; // Nothing to encode
|
|
477
496
|
// Tag has already been written
|
|
478
497
|
var n;
|
|
@@ -528,7 +547,7 @@ Field.prototype.calculateValue = function(value) {
|
|
|
528
547
|
* @throws {Error} If the field cannot be decoded
|
|
529
548
|
* @expose
|
|
530
549
|
*/
|
|
531
|
-
|
|
550
|
+
FieldPrototype.decode = function(wireType, buffer, skipRepeated) {
|
|
532
551
|
var value, nBytes;
|
|
533
552
|
if (wireType != this.type.wireType && (skipRepeated || (wireType != ProtoBuf.WIRE_TYPES.LDELIM || !this.repeated)))
|
|
534
553
|
throw Error("Illegal wire type for field "+this.toString(true)+": "+wireType+" ("+this.type.wireType+" expected)");
|
|
@@ -628,4 +647,4 @@ Field.prototype.decode = function(wireType, buffer, skipRepeated) {
|
|
|
628
647
|
|
|
629
648
|
// We should never end here
|
|
630
649
|
throw Error("[INTERNAL] Illegal wire type for "+this.toString(true)+": "+wireType);
|
|
631
|
-
}
|
|
650
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constructs a new Message OneOf.
|
|
3
|
+
* @exports ProtoBuf.Reflect.Message.OneOf
|
|
4
|
+
* @param {!ProtoBuf.Builder} builder Builder reference
|
|
5
|
+
* @param {!ProtoBuf.Reflect.Message} message Message reference
|
|
6
|
+
* @param {string} name OneOf name
|
|
7
|
+
* @constructor
|
|
8
|
+
* @extends ProtoBuf.Reflect.T
|
|
9
|
+
*/
|
|
10
|
+
var OneOf = function(builder, message, name) {
|
|
11
|
+
T.call(this, builder, message, name);
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Enclosed fields.
|
|
15
|
+
* @type {!Array.<!ProtoBuf.Reflect.Message.Field>}
|
|
16
|
+
* @expose
|
|
17
|
+
*/
|
|
18
|
+
this.fields = [];
|
|
19
|
+
};
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Constructs a new Message.
|
|
3
3
|
* @exports ProtoBuf.Reflect.Message
|
|
4
|
-
* @param {ProtoBuf.
|
|
4
|
+
* @param {!ProtoBuf.Builder} builder Builder reference
|
|
5
|
+
* @param {!ProtoBuf.Reflect.Namespace} parent Parent message or namespace
|
|
5
6
|
* @param {string} name Message name
|
|
6
|
-
* @param {Object.<string
|
|
7
|
+
* @param {Object.<string,*>=} options Message options
|
|
7
8
|
* @param {boolean=} isGroup `true` if this is a legacy group
|
|
8
9
|
* @constructor
|
|
9
10
|
* @extends ProtoBuf.Reflect.Namespace
|
|
10
11
|
*/
|
|
11
|
-
var Message = function(parent, name, options, isGroup) {
|
|
12
|
-
Namespace.call(this, parent, name, options);
|
|
12
|
+
var Message = function(builder, parent, name, options, isGroup) {
|
|
13
|
+
Namespace.call(this, builder, parent, name, options);
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* @override
|
|
@@ -52,10 +53,20 @@ var Message = function(parent, name, options, isGroup) {
|
|
|
52
53
|
* @private
|
|
53
54
|
*/
|
|
54
55
|
this._fieldsById = null;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Cached fields by name.
|
|
59
|
+
* @type {?Object.<string,!ProtoBuf.Reflect.Message.Field>}
|
|
60
|
+
* @private
|
|
61
|
+
*/
|
|
62
|
+
this._fieldsByName = null;
|
|
55
63
|
};
|
|
56
64
|
|
|
57
|
-
|
|
58
|
-
|
|
65
|
+
/**
|
|
66
|
+
* @alias ProtoBuf.Reflect.Message.prototype
|
|
67
|
+
* @inner
|
|
68
|
+
*/
|
|
69
|
+
var MessagePrototype = Message.prototype = Object.create(Namespace.prototype);
|
|
59
70
|
|
|
60
71
|
/**
|
|
61
72
|
* Builds the message and returns the runtime counterpart, which is a fully functional class.
|
|
@@ -65,7 +76,7 @@ Message.prototype = Object.create(Namespace.prototype);
|
|
|
65
76
|
* @throws {Error} If the message cannot be built
|
|
66
77
|
* @expose
|
|
67
78
|
*/
|
|
68
|
-
|
|
79
|
+
MessagePrototype.build = function(rebuild) {
|
|
69
80
|
if (this.clazz && !rebuild)
|
|
70
81
|
return this.clazz;
|
|
71
82
|
|
|
@@ -80,20 +91,20 @@ Message.prototype.build = function(rebuild) {
|
|
|
80
91
|
|
|
81
92
|
// Static enums and prototyped sub-messages / cached collections
|
|
82
93
|
this._fields = [];
|
|
83
|
-
this._fieldsById =
|
|
94
|
+
this._fieldsById = {};
|
|
95
|
+
this._fieldsByName = {};
|
|
84
96
|
for (var i=0, k=this.children.length, child; i<k; i++) {
|
|
85
97
|
child = this.children[i];
|
|
86
98
|
if (child instanceof Enum)
|
|
87
|
-
clazz[child
|
|
99
|
+
clazz[child.name] = child.build();
|
|
88
100
|
else if (child instanceof Message)
|
|
89
|
-
clazz[child
|
|
101
|
+
clazz[child.name] = child.build();
|
|
90
102
|
else if (child instanceof Message.Field)
|
|
91
103
|
child.build(),
|
|
92
104
|
this._fields.push(child),
|
|
93
|
-
this._fieldsById[child.id] = child
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
} else
|
|
105
|
+
this._fieldsById[child.id] = child,
|
|
106
|
+
this._fieldsByName[child.name] = child;
|
|
107
|
+
else if (!(child instanceof Message.OneOf) && !(child instanceof Extension)) // Not built
|
|
97
108
|
throw Error("Illegal reflect child of "+this.toString(true)+": "+children[i].toString(true));
|
|
98
109
|
}
|
|
99
110
|
|
|
@@ -109,11 +120,11 @@ Message.prototype.build = function(rebuild) {
|
|
|
109
120
|
* @throws {Error} If required fields are missing or the message cannot be encoded for another reason
|
|
110
121
|
* @expose
|
|
111
122
|
*/
|
|
112
|
-
|
|
123
|
+
MessagePrototype.encode = function(message, buffer, noVerify) {
|
|
113
124
|
var fieldMissing = null,
|
|
114
125
|
field;
|
|
115
126
|
for (var i=0, k=this._fields.length, val; i<k; ++i) {
|
|
116
|
-
field = this.
|
|
127
|
+
field = this._fields[i];
|
|
117
128
|
val = message[field.name];
|
|
118
129
|
if (field.required && val === null) {
|
|
119
130
|
if (fieldMissing === null)
|
|
@@ -136,7 +147,7 @@ Message.prototype.encode = function(message, buffer, noVerify) {
|
|
|
136
147
|
* @throws {Error} If required fields are missing or the message cannot be calculated for another reason
|
|
137
148
|
* @expose
|
|
138
149
|
*/
|
|
139
|
-
|
|
150
|
+
MessagePrototype.calculate = function(message) {
|
|
140
151
|
for (var n=0, i=0, k=this._fields.length, field, val; i<k; ++i) {
|
|
141
152
|
field = this._fields[i];
|
|
142
153
|
val = message[field.name];
|
|
@@ -198,7 +209,7 @@ function skipTillGroupEnd(expectedId, buf) {
|
|
|
198
209
|
* @throws {Error} If the message cannot be decoded
|
|
199
210
|
* @expose
|
|
200
211
|
*/
|
|
201
|
-
|
|
212
|
+
MessagePrototype.decode = function(buffer, length, expectedGroupEndId) {
|
|
202
213
|
length = typeof length === 'number' ? length : -1;
|
|
203
214
|
var start = buffer.offset,
|
|
204
215
|
msg = new (this.clazz)(),
|
|
@@ -238,8 +249,14 @@ Message.prototype.decode = function(buffer, length, expectedGroupEndId) {
|
|
|
238
249
|
}
|
|
239
250
|
if (field.repeated && !field.options["packed"])
|
|
240
251
|
msg[field.name].push(field.decode(wireType, buffer));
|
|
241
|
-
else
|
|
252
|
+
else {
|
|
242
253
|
msg[field.name] = field.decode(wireType, buffer);
|
|
254
|
+
if (field.oneof) {
|
|
255
|
+
if (this[field.oneof.name] !== null)
|
|
256
|
+
this[this[field.oneof.name]] = null;
|
|
257
|
+
msg[field.oneof.name] = field.name;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
243
260
|
}
|
|
244
261
|
|
|
245
262
|
// Check if all required fields are present and set default values for optional fields that are not
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Constructs a new Namespace.
|
|
3
3
|
* @exports ProtoBuf.Reflect.Namespace
|
|
4
|
-
* @param {ProtoBuf.
|
|
4
|
+
* @param {!ProtoBuf.Builder} builder Builder reference
|
|
5
|
+
* @param {?ProtoBuf.Reflect.Namespace} parent Namespace parent
|
|
5
6
|
* @param {string} name Namespace name
|
|
6
|
-
* @param {Object.<string
|
|
7
|
+
* @param {Object.<string,*>=} options Namespace options
|
|
7
8
|
* @constructor
|
|
8
9
|
* @extends ProtoBuf.Reflect.T
|
|
9
10
|
*/
|
|
10
|
-
var Namespace = function(parent, name, options) {
|
|
11
|
-
T.call(this, parent, name);
|
|
11
|
+
var Namespace = function(builder, parent, name, options) {
|
|
12
|
+
T.call(this, builder, parent, name);
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* @override
|
|
@@ -17,19 +18,22 @@ var Namespace = function(parent, name, options) {
|
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* Children inside the namespace.
|
|
20
|
-
* @type {Array.<ProtoBuf.Reflect.T>}
|
|
21
|
+
* @type {!Array.<ProtoBuf.Reflect.T>}
|
|
21
22
|
*/
|
|
22
23
|
this.children = [];
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* Options.
|
|
26
|
-
* @type {Object.<string, *>}
|
|
27
|
+
* @type {!Object.<string, *>}
|
|
27
28
|
*/
|
|
28
29
|
this.options = options || {};
|
|
29
30
|
};
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
/**
|
|
33
|
+
* @alias ProtoBuf.Reflect.Namespace.prototype
|
|
34
|
+
* @inner
|
|
35
|
+
*/
|
|
36
|
+
var NamespacePrototype = Namespace.prototype = Object.create(T.prototype);
|
|
33
37
|
|
|
34
38
|
/**
|
|
35
39
|
* Returns an array of the namespace's children.
|
|
@@ -37,7 +41,7 @@ Namespace.prototype = Object.create(T.prototype);
|
|
|
37
41
|
* @return {Array.<ProtoBuf.Reflect.T>}
|
|
38
42
|
* @expose
|
|
39
43
|
*/
|
|
40
|
-
|
|
44
|
+
NamespacePrototype.getChildren = function(type) {
|
|
41
45
|
type = type || null;
|
|
42
46
|
if (type == null)
|
|
43
47
|
return this.children.slice();
|
|
@@ -54,7 +58,7 @@ Namespace.prototype.getChildren = function(type) {
|
|
|
54
58
|
* @throws {Error} If the child cannot be added (duplicate)
|
|
55
59
|
* @expose
|
|
56
60
|
*/
|
|
57
|
-
|
|
61
|
+
NamespacePrototype.addChild = function(child) {
|
|
58
62
|
var other;
|
|
59
63
|
if (other = this.getChild(child.name)) {
|
|
60
64
|
// Try to revert camelcase transformation on collision
|
|
@@ -74,7 +78,7 @@ Namespace.prototype.addChild = function(child) {
|
|
|
74
78
|
* @return {?ProtoBuf.Reflect.T} The child or null if not found
|
|
75
79
|
* @expose
|
|
76
80
|
*/
|
|
77
|
-
|
|
81
|
+
NamespacePrototype.getChild = function(nameOrId) {
|
|
78
82
|
var key = typeof nameOrId === 'number' ? 'id' : 'name';
|
|
79
83
|
for (var i=0, k=this.children.length; i<k; ++i)
|
|
80
84
|
if (this.children[i][key] === nameOrId)
|
|
@@ -89,7 +93,7 @@ Namespace.prototype.getChild = function(nameOrId) {
|
|
|
89
93
|
* @return {?ProtoBuf.Reflect.Namespace} The resolved type or null if not found
|
|
90
94
|
* @expose
|
|
91
95
|
*/
|
|
92
|
-
|
|
96
|
+
NamespacePrototype.resolve = function(qn, excludeFields) {
|
|
93
97
|
var part = qn.split("."),
|
|
94
98
|
ptr = this,
|
|
95
99
|
i = 0;
|
|
@@ -123,7 +127,7 @@ Namespace.prototype.resolve = function(qn, excludeFields) {
|
|
|
123
127
|
* @return {Object.<string,Function|Object>} Runtime namespace
|
|
124
128
|
* @expose
|
|
125
129
|
*/
|
|
126
|
-
|
|
130
|
+
NamespacePrototype.build = function() {
|
|
127
131
|
/** @dict */
|
|
128
132
|
var ns = {};
|
|
129
133
|
var children = this.children;
|
|
@@ -141,7 +145,7 @@ Namespace.prototype.build = function() {
|
|
|
141
145
|
* Builds the namespace's '$options' property.
|
|
142
146
|
* @return {Object.<string,*>}
|
|
143
147
|
*/
|
|
144
|
-
|
|
148
|
+
NamespacePrototype.buildOpt = function() {
|
|
145
149
|
var opt = {},
|
|
146
150
|
keys = Object.keys(this.options);
|
|
147
151
|
for (var i=0, k=keys.length; i<k; ++i) {
|
|
@@ -162,7 +166,7 @@ Namespace.prototype.buildOpt = function() {
|
|
|
162
166
|
* @param {string=} name Returns the option value if specified, otherwise all options are returned.
|
|
163
167
|
* @return {*|Object.<string,*>}null} Option value or NULL if there is no such option
|
|
164
168
|
*/
|
|
165
|
-
|
|
169
|
+
NamespacePrototype.getOption = function(name) {
|
|
166
170
|
if (typeof name === 'undefined')
|
|
167
171
|
return this.options;
|
|
168
172
|
return typeof this.options[name] !== 'undefined' ? this.options[name] : null;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Abstract service method.
|
|
3
3
|
* @exports ProtoBuf.Reflect.Service.Method
|
|
4
|
+
* @param {!ProtoBuf.Builder} builder Builder reference
|
|
4
5
|
* @param {!ProtoBuf.Reflect.Service} svc Service
|
|
5
6
|
* @param {string} name Method name
|
|
6
7
|
* @param {Object.<string,*>=} options Options
|
|
7
8
|
* @constructor
|
|
8
9
|
* @extends ProtoBuf.Reflect.T
|
|
9
10
|
*/
|
|
10
|
-
var Method = function(svc, name, options) {
|
|
11
|
-
T.call(this, svc, name);
|
|
11
|
+
var Method = function(builder, svc, name, options) {
|
|
12
|
+
T.call(this, builder, svc, name);
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* @override
|
|
@@ -23,8 +24,11 @@ var Method = function(svc, name, options) {
|
|
|
23
24
|
this.options = options || {};
|
|
24
25
|
};
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
/**
|
|
28
|
+
* @alias ProtoBuf.Reflect.Service.Method.prototype
|
|
29
|
+
* @inner
|
|
30
|
+
*/
|
|
31
|
+
var MethodPrototype = Method.prototype = Object.create(T.prototype);
|
|
28
32
|
|
|
29
33
|
/**
|
|
30
34
|
* Builds the method's '$options' property.
|
|
@@ -32,4 +36,4 @@ Method.prototype = Object.create(T.prototype);
|
|
|
32
36
|
* @function
|
|
33
37
|
* @return {Object.<string,*>}
|
|
34
38
|
*/
|
|
35
|
-
|
|
39
|
+
MethodPrototype.buildOpt = NamespacePrototype.buildOpt;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* RPC service method.
|
|
3
3
|
* @exports ProtoBuf.Reflect.Service.RPCMethod
|
|
4
|
+
* @param {!ProtoBuf.Builder} builder Builder reference
|
|
4
5
|
* @param {!ProtoBuf.Reflect.Service} svc Service
|
|
5
6
|
* @param {string} name Method name
|
|
6
7
|
* @param {string} request Request message name
|
|
@@ -9,8 +10,8 @@
|
|
|
9
10
|
* @constructor
|
|
10
11
|
* @extends ProtoBuf.Reflect.Service.Method
|
|
11
12
|
*/
|
|
12
|
-
var RPCMethod = function(svc, name, request, response, options) {
|
|
13
|
-
Method.call(this, svc, name, options);
|
|
13
|
+
var RPCMethod = function(builder, svc, name, request, response, options) {
|
|
14
|
+
Method.call(this, builder, svc, name, options);
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* @override
|