yellow-brick-road 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rst +9 -1
- data/Rakefile +0 -3
- data/lib/generators/templates/yellow_brick_road.rb.erb +12 -0
- data/lib/tasks/ybr.rake +12 -0
- data/lib/yellow-brick-road.rb +5 -0
- data/lib/yellow-brick-road/config.rb +45 -6
- data/lib/yellow-brick-road/directive_processor.rb +89 -10
- data/lib/yellow-brick-road/engine.rb +10 -0
- data/lib/yellow-brick-road/protobuf_js.rb +32 -0
- data/lib/yellow-brick-road/soy_processor.rb +13 -4
- data/lib/yellow-brick-road/utils.rb +7 -1
- data/lib/yellow-brick-road/version.rb +1 -1
- data/test/dummy/app/assets/javascripts/application.js +1 -0
- data/test/dummy/app/assets/javascripts/closure-deps.js +2 -1
- data/test/dummy/app/assets/javascripts/protos/person.pb.js +207 -0
- data/test/dummy/app/protos/person.proto +5 -0
- data/test/dummy/log/development.log +1544 -0
- data/test/dummy/tmp/cache/assets/C5B/240/sprockets%2Fc561864da49634b1e8464990f63f4123 +314 -0
- data/test/dummy/tmp/cache/assets/C7E/9F0/sprockets%2F89862076204c62c4593ac20de32da909 +6 -5
- data/test/dummy/tmp/cache/assets/CBD/850/sprockets%2F9191c7b83dca8e9342628ac59e452229 +297 -0
- data/test/dummy/tmp/cache/assets/CCC/BB0/sprockets%2F649c7cc1e706997576646e6dd790d7a0 +0 -0
- data/test/dummy/tmp/cache/assets/CE0/AB0/sprockets%2Fb8f01070d8f72dd30306684ef61858ac +204 -0
- data/test/dummy/tmp/cache/assets/CF7/BC0/sprockets%2Fe47129798756fd8f35bd4350bff5e461 +213 -0
- data/test/dummy/tmp/cache/assets/D15/F60/sprockets%2Fa28394e3f80365b5bc86794dd46daa22 +0 -0
- data/test/dummy/tmp/cache/assets/D50/F20/sprockets%2Fd858e852254b667a8efffa4f12d96d11 +0 -0
- data/test/dummy/tmp/cache/assets/D6B/0C0/sprockets%2F8c3bdd9c000f7f5a26e91f294a71c3c4 +0 -0
- data/test/dummy/tmp/cache/assets/D6F/6D0/sprockets%2Ff9f65ec20235e6595b5eb2ab91f15bb4 +1441 -0
- data/test/dummy/tmp/cache/assets/D84/210/sprockets%2Fabd0103ccec2b428ac62c94e4c40b384 +7 -5
- data/test/dummy/tmp/cache/assets/D97/E60/sprockets%2F18762119fe3a03903efaac2bfceec628 +763 -0
- data/test/dummy/tmp/cache/assets/DA1/670/sprockets%2Fccb4ba5dcd2f7696c636666ca5ab6057 +60 -0
- data/test/dummy/tmp/cache/assets/DED/040/sprockets%2Fd3aa2ab8d25cde3b6fb324dbb8c42933 +746 -0
- data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- metadata +38 -11
- data/lib/tasks/yellow-brick-road_tasks.rake +0 -4
@@ -0,0 +1,60 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry :@compressedF:@expires_in0:@created_atf1326427868.131518:@value{ I"length:EFiuI"digest;
|
2
|
+
F"%bc60fb6f6b6a839326b6fbadc60fb1c5I"source;
|
3
|
+
FI"u// Copyright 2009 The Closure Library Authors. All Rights Reserved.
|
4
|
+
//
|
5
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
// you may not use this file except in compliance with the License.
|
7
|
+
// You may obtain a copy of the License at
|
8
|
+
//
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
//
|
11
|
+
// Unless required by applicable law or agreed to in writing, software
|
12
|
+
// distributed under the License is distributed on an "AS-IS" BASIS,
|
13
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
// See the License for the specific language governing permissions and
|
15
|
+
// limitations under the License.
|
16
|
+
|
17
|
+
/**
|
18
|
+
* @fileoverview Utility methods for Protocol Buffer 2 implementation.
|
19
|
+
*/
|
20
|
+
|
21
|
+
|
22
|
+
goog.provide('goog.proto2.Util');
|
23
|
+
|
24
|
+
goog.require('goog.asserts');
|
25
|
+
|
26
|
+
|
27
|
+
/**
|
28
|
+
* @define {boolean} Defines a PBCHECK constant that can be turned off by
|
29
|
+
* clients of PB2. This for is clients that do not want assertion/checking
|
30
|
+
* running even in non-COMPILED builds.
|
31
|
+
*/
|
32
|
+
goog.proto2.Util.PBCHECK = !COMPILED;
|
33
|
+
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Asserts that the given condition is true, if and only if the PBCHECK
|
37
|
+
* flag is on.
|
38
|
+
*
|
39
|
+
* @param {*} condition The condition to check.
|
40
|
+
* @param {string=} opt_message Error message in case of failure.
|
41
|
+
* @throws {Error} Assertion failed, the condition evaluates to false.
|
42
|
+
*/
|
43
|
+
goog.proto2.Util.assert = function(condition, opt_message) {
|
44
|
+
if (goog.proto2.Util.PBCHECK) {
|
45
|
+
goog.asserts.assert(condition, opt_message);
|
46
|
+
}
|
47
|
+
};
|
48
|
+
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Returns true if debug assertions (checks) are on.
|
52
|
+
*
|
53
|
+
* @return {boolean} The value of the PBCHECK constant.
|
54
|
+
*/
|
55
|
+
goog.proto2.Util.conductChecks = function() {
|
56
|
+
return goog.proto2.Util.PBCHECK;
|
57
|
+
};
|
58
|
+
;
|
59
|
+
FI"
|
60
|
+
F"%b63f36a1d47a4323f54f178ad295815d
|
@@ -0,0 +1,746 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry :@compressedF:@expires_in0:@created_atf1326427868.348992:@value{ I"length:EFi�QI"digest;
|
2
|
+
F"%72b334f2449f38dc197440fe1204d22eI"source;
|
3
|
+
FI"�Q// Copyright 2008 The Closure Library Authors. All Rights Reserved.
|
4
|
+
//
|
5
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
// you may not use this file except in compliance with the License.
|
7
|
+
// You may obtain a copy of the License at
|
8
|
+
//
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
//
|
11
|
+
// Unless required by applicable law or agreed to in writing, software
|
12
|
+
// distributed under the License is distributed on an "AS-IS" BASIS,
|
13
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
// See the License for the specific language governing permissions and
|
15
|
+
// limitations under the License.
|
16
|
+
|
17
|
+
/**
|
18
|
+
* @fileoverview Protocol Buffer Message base class.
|
19
|
+
*/
|
20
|
+
|
21
|
+
|
22
|
+
goog.provide('goog.proto2.Message');
|
23
|
+
|
24
|
+
goog.require('goog.proto2.Descriptor');
|
25
|
+
goog.require('goog.proto2.FieldDescriptor');
|
26
|
+
goog.require('goog.proto2.Util');
|
27
|
+
goog.require('goog.string');
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
/**
|
32
|
+
* Abstract base class for all Protocol Buffer 2 messages. It will be
|
33
|
+
* subclassed in the code generated by the Protocol Compiler. Any other
|
34
|
+
* subclasses are prohibited.
|
35
|
+
* @constructor
|
36
|
+
*/
|
37
|
+
goog.proto2.Message = function() {
|
38
|
+
/**
|
39
|
+
* Stores the field values in this message.
|
40
|
+
* @type {*}
|
41
|
+
* @private
|
42
|
+
*/
|
43
|
+
this.values_ = {};
|
44
|
+
|
45
|
+
// The descriptor_ is static to the message function that is being created.
|
46
|
+
// Therefore, we retrieve it via the constructor.
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Stores the information (i.e. metadata) about this message.
|
50
|
+
* @type {!goog.proto2.Descriptor}
|
51
|
+
* @private
|
52
|
+
*/
|
53
|
+
this.descriptor_ = this.constructor.descriptor_;
|
54
|
+
|
55
|
+
/**
|
56
|
+
* Stores the field information (i.e. metadata) about this message.
|
57
|
+
* @type {Object.<number, !goog.proto2.FieldDescriptor>}
|
58
|
+
* @private
|
59
|
+
*/
|
60
|
+
this.fields_ = this.descriptor_.getFieldsMap();
|
61
|
+
|
62
|
+
/**
|
63
|
+
* The lazy deserializer for this message instance, if any.
|
64
|
+
* @type {goog.proto2.LazyDeserializer}
|
65
|
+
* @private
|
66
|
+
*/
|
67
|
+
this.lazyDeserializer_ = null;
|
68
|
+
|
69
|
+
/**
|
70
|
+
* A map of those fields deserialized.
|
71
|
+
* @type {Object}
|
72
|
+
* @private
|
73
|
+
*/
|
74
|
+
this.deserializedFields_ = null;
|
75
|
+
};
|
76
|
+
|
77
|
+
|
78
|
+
/**
|
79
|
+
* An enumeration defining the possible field types.
|
80
|
+
* Should be a mirror of that defined in descriptor.h.
|
81
|
+
*
|
82
|
+
* TODO(user): Remove this alias. The code generator generates code that
|
83
|
+
* references this enum, so it needs to exist until the code generator is
|
84
|
+
* changed. The enum was moved to from Message to FieldDescriptor to avoid a
|
85
|
+
* dependency cycle.
|
86
|
+
*
|
87
|
+
* Use goog.proto2.FieldDescriptor.FieldType instead.
|
88
|
+
*
|
89
|
+
* @enum {number}
|
90
|
+
*/
|
91
|
+
goog.proto2.Message.FieldType = {
|
92
|
+
DOUBLE: 1,
|
93
|
+
FLOAT: 2,
|
94
|
+
INT64: 3,
|
95
|
+
UINT64: 4,
|
96
|
+
INT32: 5,
|
97
|
+
FIXED64: 6,
|
98
|
+
FIXED32: 7,
|
99
|
+
BOOL: 8,
|
100
|
+
STRING: 9,
|
101
|
+
GROUP: 10,
|
102
|
+
MESSAGE: 11,
|
103
|
+
BYTES: 12,
|
104
|
+
UINT32: 13,
|
105
|
+
ENUM: 14,
|
106
|
+
SFIXED32: 15,
|
107
|
+
SFIXED64: 16,
|
108
|
+
SINT32: 17,
|
109
|
+
SINT64: 18
|
110
|
+
};
|
111
|
+
|
112
|
+
|
113
|
+
/**
|
114
|
+
* Initializes the message with a lazy deserializer and its associated data.
|
115
|
+
* This method should be called by internal methods ONLY.
|
116
|
+
*
|
117
|
+
* @param {goog.proto2.LazyDeserializer} deserializer The lazy deserializer to
|
118
|
+
* use to decode the data on the fly.
|
119
|
+
*
|
120
|
+
* @param {*} data The data to decode/deserialize.
|
121
|
+
*/
|
122
|
+
goog.proto2.Message.prototype.initializeForLazyDeserializer = function(
|
123
|
+
deserializer, data) {
|
124
|
+
|
125
|
+
this.lazyDeserializer_ = deserializer;
|
126
|
+
this.values_ = data;
|
127
|
+
this.deserializedFields_ = {};
|
128
|
+
};
|
129
|
+
|
130
|
+
|
131
|
+
/**
|
132
|
+
* Sets the value of an unknown field, by tag.
|
133
|
+
*
|
134
|
+
* @param {number} tag The tag of an unknown field (must be >= 1).
|
135
|
+
* @param {*} value The value for that unknown field.
|
136
|
+
*/
|
137
|
+
goog.proto2.Message.prototype.setUnknown = function(tag, value) {
|
138
|
+
goog.proto2.Util.assert(!this.fields_[tag],
|
139
|
+
'Field is not unknown in this message');
|
140
|
+
|
141
|
+
goog.proto2.Util.assert(tag >= 1, 'Tag is not valid');
|
142
|
+
goog.proto2.Util.assert(value !== null, 'Value cannot be null');
|
143
|
+
|
144
|
+
this.values_[tag] = value;
|
145
|
+
};
|
146
|
+
|
147
|
+
|
148
|
+
/**
|
149
|
+
* Iterates over all the unknown fields in the message.
|
150
|
+
*
|
151
|
+
* @param {function(number, *)} callback A callback method
|
152
|
+
* which gets invoked for each unknown field.
|
153
|
+
* @param {Object=} opt_scope The scope under which to execute the callback.
|
154
|
+
* If not given, the current message will be used.
|
155
|
+
*/
|
156
|
+
goog.proto2.Message.prototype.forEachUnknown = function(callback, opt_scope) {
|
157
|
+
var scope = opt_scope || this;
|
158
|
+
for (var key in this.values_) {
|
159
|
+
if (!this.fields_[/** @type {number} */ (key)]) {
|
160
|
+
callback.call(scope, Number(key), this.values_[key]);
|
161
|
+
}
|
162
|
+
}
|
163
|
+
};
|
164
|
+
|
165
|
+
|
166
|
+
/**
|
167
|
+
* Returns the descriptor which describes the current message.
|
168
|
+
*
|
169
|
+
* @return {goog.proto2.Descriptor} The descriptor.
|
170
|
+
*/
|
171
|
+
goog.proto2.Message.prototype.getDescriptor = function() {
|
172
|
+
return this.descriptor_;
|
173
|
+
};
|
174
|
+
|
175
|
+
|
176
|
+
/**
|
177
|
+
* Returns whether there is a value stored at the field specified by the
|
178
|
+
* given field descriptor.
|
179
|
+
*
|
180
|
+
* @param {goog.proto2.FieldDescriptor} field The field for which to check
|
181
|
+
* if there is a value.
|
182
|
+
*
|
183
|
+
* @return {boolean} True if a value was found.
|
184
|
+
*/
|
185
|
+
goog.proto2.Message.prototype.has = function(field) {
|
186
|
+
goog.proto2.Util.assert(
|
187
|
+
field.getContainingType() == this.descriptor_,
|
188
|
+
'The current message does not contain the given field');
|
189
|
+
|
190
|
+
return this.has$Value(field.getTag());
|
191
|
+
};
|
192
|
+
|
193
|
+
|
194
|
+
/**
|
195
|
+
* Returns the array of values found for the given repeated field.
|
196
|
+
*
|
197
|
+
* @param {goog.proto2.FieldDescriptor} field The field for which to
|
198
|
+
* return the values.
|
199
|
+
*
|
200
|
+
* @return {!Array} The values found.
|
201
|
+
*/
|
202
|
+
goog.proto2.Message.prototype.arrayOf = function(field) {
|
203
|
+
goog.proto2.Util.assert(
|
204
|
+
field.getContainingType() == this.descriptor_,
|
205
|
+
'The current message does not contain the given field');
|
206
|
+
|
207
|
+
return this.array$Values(field.getTag());
|
208
|
+
};
|
209
|
+
|
210
|
+
|
211
|
+
/**
|
212
|
+
* Returns the number of values stored in the given field.
|
213
|
+
*
|
214
|
+
* @param {goog.proto2.FieldDescriptor} field The field for which to count
|
215
|
+
* the number of values.
|
216
|
+
*
|
217
|
+
* @return {number} The count of the values in the given field.
|
218
|
+
*/
|
219
|
+
goog.proto2.Message.prototype.countOf = function(field) {
|
220
|
+
goog.proto2.Util.assert(
|
221
|
+
field.getContainingType() == this.descriptor_,
|
222
|
+
'The current message does not contain the given field');
|
223
|
+
|
224
|
+
return this.count$Values(field.getTag());
|
225
|
+
};
|
226
|
+
|
227
|
+
|
228
|
+
/**
|
229
|
+
* Returns the value stored at the field specified by the
|
230
|
+
* given field descriptor.
|
231
|
+
*
|
232
|
+
* @param {goog.proto2.FieldDescriptor} field The field for which to get the
|
233
|
+
* value.
|
234
|
+
* @param {number=} opt_index If the field is repeated, the index to use when
|
235
|
+
* looking up the value.
|
236
|
+
*
|
237
|
+
* @return {*} The value found or null if none.
|
238
|
+
*/
|
239
|
+
goog.proto2.Message.prototype.get = function(field, opt_index) {
|
240
|
+
goog.proto2.Util.assert(
|
241
|
+
field.getContainingType() == this.descriptor_,
|
242
|
+
'The current message does not contain the given field');
|
243
|
+
|
244
|
+
return this.get$Value(field.getTag(), opt_index);
|
245
|
+
};
|
246
|
+
|
247
|
+
|
248
|
+
/**
|
249
|
+
* Returns the value stored at the field specified by the
|
250
|
+
* given field descriptor or the default value if none exists.
|
251
|
+
*
|
252
|
+
* @param {goog.proto2.FieldDescriptor} field The field for which to get the
|
253
|
+
* value.
|
254
|
+
* @param {number=} opt_index If the field is repeated, the index to use when
|
255
|
+
* looking up the value.
|
256
|
+
*
|
257
|
+
* @return {*} The value found or the default if none.
|
258
|
+
*/
|
259
|
+
goog.proto2.Message.prototype.getOrDefault = function(field, opt_index) {
|
260
|
+
goog.proto2.Util.assert(
|
261
|
+
field.getContainingType() == this.descriptor_,
|
262
|
+
'The current message does not contain the given field');
|
263
|
+
|
264
|
+
return this.get$ValueOrDefault(field.getTag(), opt_index);
|
265
|
+
};
|
266
|
+
|
267
|
+
|
268
|
+
/**
|
269
|
+
* Stores the given value to the field specified by the
|
270
|
+
* given field descriptor. Note that the field must not be repeated.
|
271
|
+
*
|
272
|
+
* @param {goog.proto2.FieldDescriptor} field The field for which to set
|
273
|
+
* the value.
|
274
|
+
* @param {*} value The new value for the field.
|
275
|
+
*/
|
276
|
+
goog.proto2.Message.prototype.set = function(field, value) {
|
277
|
+
goog.proto2.Util.assert(
|
278
|
+
field.getContainingType() == this.descriptor_,
|
279
|
+
'The current message does not contain the given field');
|
280
|
+
|
281
|
+
this.set$Value(field.getTag(), value);
|
282
|
+
};
|
283
|
+
|
284
|
+
|
285
|
+
/**
|
286
|
+
* Adds the given value to the field specified by the
|
287
|
+
* given field descriptor. Note that the field must be repeated.
|
288
|
+
*
|
289
|
+
* @param {goog.proto2.FieldDescriptor} field The field in which to add the
|
290
|
+
* the value.
|
291
|
+
* @param {*} value The new value to add to the field.
|
292
|
+
*/
|
293
|
+
goog.proto2.Message.prototype.add = function(field, value) {
|
294
|
+
goog.proto2.Util.assert(
|
295
|
+
field.getContainingType() == this.descriptor_,
|
296
|
+
'The current message does not contain the given field');
|
297
|
+
|
298
|
+
this.add$Value(field.getTag(), value);
|
299
|
+
};
|
300
|
+
|
301
|
+
|
302
|
+
/**
|
303
|
+
* Clears the field specified.
|
304
|
+
*
|
305
|
+
* @param {goog.proto2.FieldDescriptor} field The field to clear.
|
306
|
+
*/
|
307
|
+
goog.proto2.Message.prototype.clear = function(field) {
|
308
|
+
goog.proto2.Util.assert(
|
309
|
+
field.getContainingType() == this.descriptor_,
|
310
|
+
'The current message does not contain the given field');
|
311
|
+
|
312
|
+
this.clear$Field(field.getTag());
|
313
|
+
};
|
314
|
+
|
315
|
+
|
316
|
+
/**
|
317
|
+
* Compares this message with another one ignoring the unknown fields.
|
318
|
+
* @param {*} other The other message.
|
319
|
+
* @return {boolean} Whether they are equal. Returns false if the {@code other}
|
320
|
+
* argument is a different type of message or not a message.
|
321
|
+
*/
|
322
|
+
goog.proto2.Message.prototype.equals = function(other) {
|
323
|
+
if (!other || this.constructor != other.constructor) {
|
324
|
+
return false;
|
325
|
+
}
|
326
|
+
|
327
|
+
var fields = this.getDescriptor().getFields();
|
328
|
+
for (var i = 0; i < fields.length; i++) {
|
329
|
+
var field = fields[i];
|
330
|
+
if (this.has(field) != other.has(field)) {
|
331
|
+
return false;
|
332
|
+
}
|
333
|
+
|
334
|
+
if (this.has(field)) {
|
335
|
+
var isComposite = field.isCompositeType();
|
336
|
+
|
337
|
+
function fieldsEqual(value1, value2) {
|
338
|
+
return isComposite ? value1.equals(value2) : value1 == value2;
|
339
|
+
}
|
340
|
+
|
341
|
+
var tag = field.getTag();
|
342
|
+
var thisValue = this.values_[tag];
|
343
|
+
var otherValue = other.values_[tag];
|
344
|
+
|
345
|
+
if (field.isRepeated()) {
|
346
|
+
// In this case thisValue and otherValue are arrays.
|
347
|
+
if (thisValue.length != otherValue.length) {
|
348
|
+
return false;
|
349
|
+
}
|
350
|
+
for (var j = 0; j < thisValue.length; j++) {
|
351
|
+
if (!fieldsEqual(thisValue[j], otherValue[j])) {
|
352
|
+
return false;
|
353
|
+
}
|
354
|
+
}
|
355
|
+
} else if (!fieldsEqual(thisValue, otherValue)) {
|
356
|
+
return false;
|
357
|
+
}
|
358
|
+
}
|
359
|
+
}
|
360
|
+
|
361
|
+
return true;
|
362
|
+
};
|
363
|
+
|
364
|
+
|
365
|
+
/**
|
366
|
+
* Recursively copies the known fields from the given message to this message.
|
367
|
+
* Removes the fields which are not present in the source message.
|
368
|
+
* @param {!goog.proto2.Message} message The source message.
|
369
|
+
*/
|
370
|
+
goog.proto2.Message.prototype.copyFrom = function(message) {
|
371
|
+
goog.proto2.Util.assert(this.constructor == message.constructor,
|
372
|
+
'The source message must have the same type.');
|
373
|
+
var fields = this.getDescriptor().getFields();
|
374
|
+
|
375
|
+
for (var i = 0; i < fields.length; i++) {
|
376
|
+
var field = fields[i];
|
377
|
+
delete this.values_[field.getTag()];
|
378
|
+
|
379
|
+
if (message.has(field)) {
|
380
|
+
var isComposite = field.isCompositeType();
|
381
|
+
if (field.isRepeated()) {
|
382
|
+
var values = message.arrayOf(field);
|
383
|
+
for (var j = 0; j < values.length; j++) {
|
384
|
+
this.add(field, isComposite ? values[j].clone() : values[j]);
|
385
|
+
}
|
386
|
+
} else {
|
387
|
+
var value = message.get(field);
|
388
|
+
this.set(field, isComposite ? value.clone() : value);
|
389
|
+
}
|
390
|
+
}
|
391
|
+
}
|
392
|
+
};
|
393
|
+
|
394
|
+
|
395
|
+
/**
|
396
|
+
* @return {!goog.proto2.Message} Recursive clone of the message only including
|
397
|
+
* the known fields.
|
398
|
+
*/
|
399
|
+
goog.proto2.Message.prototype.clone = function() {
|
400
|
+
var clone = new this.constructor;
|
401
|
+
clone.copyFrom(this);
|
402
|
+
return clone;
|
403
|
+
};
|
404
|
+
|
405
|
+
|
406
|
+
/**
|
407
|
+
* Fills in the protocol buffer with default values. Any fields that are
|
408
|
+
* already set will not be overridden.
|
409
|
+
* @param {boolean} simpleFieldsToo If true, all fields will be initialized;
|
410
|
+
* if false, only the nested messages and groups.
|
411
|
+
*/
|
412
|
+
goog.proto2.Message.prototype.initDefaults = function(simpleFieldsToo) {
|
413
|
+
var fields = this.getDescriptor().getFields();
|
414
|
+
for (var i = 0; i < fields.length; i++) {
|
415
|
+
var field = fields[i];
|
416
|
+
var tag = field.getTag();
|
417
|
+
var isComposite = field.isCompositeType();
|
418
|
+
|
419
|
+
// Initialize missing fields.
|
420
|
+
if (!this.has(field) && !field.isRepeated()) {
|
421
|
+
if (isComposite) {
|
422
|
+
this.values_[tag] = new /** @type {Function} */ (field.getNativeType());
|
423
|
+
} else if (simpleFieldsToo) {
|
424
|
+
this.values_[tag] = field.getDefaultValue();
|
425
|
+
}
|
426
|
+
}
|
427
|
+
|
428
|
+
// Fill in the existing composite fields recursively.
|
429
|
+
if (isComposite) {
|
430
|
+
if (field.isRepeated()) {
|
431
|
+
var values = this.array$Values(tag);
|
432
|
+
for (var j = 0; j < values.length; j++) {
|
433
|
+
values[j].initDefaults(simpleFieldsToo);
|
434
|
+
}
|
435
|
+
} else {
|
436
|
+
this.get$Value(tag).initDefaults(simpleFieldsToo);
|
437
|
+
}
|
438
|
+
}
|
439
|
+
}
|
440
|
+
};
|
441
|
+
|
442
|
+
|
443
|
+
/**
|
444
|
+
* Returns the field in this message by the given tag number. If no
|
445
|
+
* such field exists, throws an exception.
|
446
|
+
*
|
447
|
+
* @param {number} tag The field's tag index.
|
448
|
+
* @return {!goog.proto2.FieldDescriptor} The descriptor for the field.
|
449
|
+
* @private
|
450
|
+
*/
|
451
|
+
goog.proto2.Message.prototype.getFieldByTag_ = function(tag) {
|
452
|
+
goog.proto2.Util.assert(this.fields_[tag],
|
453
|
+
'No field found for the given tag');
|
454
|
+
|
455
|
+
return this.fields_[tag];
|
456
|
+
};
|
457
|
+
|
458
|
+
|
459
|
+
/**
|
460
|
+
* Returns the whether or not the field indicated by the given tag
|
461
|
+
* has a value.
|
462
|
+
*
|
463
|
+
* GENERATED CODE USE ONLY. Basis of the has{Field} methods.
|
464
|
+
*
|
465
|
+
* @param {number} tag The tag.
|
466
|
+
*
|
467
|
+
* @return {boolean} Whether the message has a value for the field.
|
468
|
+
*/
|
469
|
+
goog.proto2.Message.prototype.has$Value = function(tag) {
|
470
|
+
goog.proto2.Util.assert(this.fields_[tag],
|
471
|
+
'No field found for the given tag');
|
472
|
+
|
473
|
+
return tag in this.values_ && goog.isDef(this.values_[tag]) &&
|
474
|
+
this.values_[tag] !== null;
|
475
|
+
};
|
476
|
+
|
477
|
+
|
478
|
+
/**
|
479
|
+
* If a lazy deserializer is instantiated, lazily deserializes the
|
480
|
+
* field if required.
|
481
|
+
*
|
482
|
+
* @param {goog.proto2.FieldDescriptor} field The field.
|
483
|
+
* @private
|
484
|
+
*/
|
485
|
+
goog.proto2.Message.prototype.lazyDeserialize_ = function(field) {
|
486
|
+
// If we have a lazy deserializer, then ensure that the field is
|
487
|
+
// properly deserialized.
|
488
|
+
if (this.lazyDeserializer_) {
|
489
|
+
var tag = field.getTag();
|
490
|
+
|
491
|
+
if (!(tag in this.deserializedFields_)) {
|
492
|
+
this.values_[tag] = this.lazyDeserializer_.deserializeField(
|
493
|
+
this, field, this.values_[tag]);
|
494
|
+
|
495
|
+
this.deserializedFields_[tag] = true;
|
496
|
+
}
|
497
|
+
}
|
498
|
+
};
|
499
|
+
|
500
|
+
|
501
|
+
/**
|
502
|
+
* Gets the value at the field indicated by the given tag.
|
503
|
+
*
|
504
|
+
* GENERATED CODE USE ONLY. Basis of the get{Field} methods.
|
505
|
+
*
|
506
|
+
* @param {number} tag The field's tag index.
|
507
|
+
* @param {number=} opt_index If the field is a repeated field, the index
|
508
|
+
* at which to get the value.
|
509
|
+
*
|
510
|
+
* @return {*} The value found or null for none.
|
511
|
+
* @protected
|
512
|
+
*/
|
513
|
+
goog.proto2.Message.prototype.get$Value = function(tag, opt_index) {
|
514
|
+
var field = this.getFieldByTag_(tag);
|
515
|
+
|
516
|
+
// Ensure that the field is deserialized.
|
517
|
+
this.lazyDeserialize_(field);
|
518
|
+
|
519
|
+
if (field.isRepeated()) {
|
520
|
+
var index = opt_index || 0;
|
521
|
+
goog.proto2.Util.assert(index >= 0 && index < this.count$Values(tag),
|
522
|
+
'Given index is out of bounds');
|
523
|
+
|
524
|
+
return this.values_[tag][index];
|
525
|
+
} else {
|
526
|
+
goog.proto2.Util.assert(!goog.isArray(this.values_[tag]));
|
527
|
+
return tag in this.values_ ? this.values_[tag] : null;
|
528
|
+
}
|
529
|
+
};
|
530
|
+
|
531
|
+
|
532
|
+
/**
|
533
|
+
* Gets the value at the field indicated by the given tag or the default value
|
534
|
+
* if none.
|
535
|
+
*
|
536
|
+
* GENERATED CODE USE ONLY. Basis of the get{Field} methods.
|
537
|
+
*
|
538
|
+
* @param {number} tag The field's tag index.
|
539
|
+
* @param {number=} opt_index If the field is a repeated field, the index
|
540
|
+
* at which to get the value.
|
541
|
+
*
|
542
|
+
* @return {*} The value found or the default value if none set.
|
543
|
+
* @protected
|
544
|
+
*/
|
545
|
+
goog.proto2.Message.prototype.get$ValueOrDefault = function(tag, opt_index) {
|
546
|
+
|
547
|
+
if (!this.has$Value(tag)) {
|
548
|
+
// Return the default value.
|
549
|
+
var field = this.getFieldByTag_(tag);
|
550
|
+
return field.getDefaultValue();
|
551
|
+
}
|
552
|
+
|
553
|
+
return this.get$Value(tag, opt_index);
|
554
|
+
};
|
555
|
+
|
556
|
+
|
557
|
+
/**
|
558
|
+
* Gets the values at the field indicated by the given tag.
|
559
|
+
*
|
560
|
+
* GENERATED CODE USE ONLY. Basis of the {field}Array methods.
|
561
|
+
*
|
562
|
+
* @param {number} tag The field's tag index.
|
563
|
+
*
|
564
|
+
* @return {!Array} The values found. If none, returns an empty array.
|
565
|
+
* @protected
|
566
|
+
*/
|
567
|
+
goog.proto2.Message.prototype.array$Values = function(tag) {
|
568
|
+
goog.proto2.Util.assert(this.getFieldByTag_(tag).isRepeated(),
|
569
|
+
'Cannot call fieldArray on a non-repeated field');
|
570
|
+
|
571
|
+
var field = this.getFieldByTag_(tag);
|
572
|
+
|
573
|
+
// Ensure that the field is deserialized.
|
574
|
+
this.lazyDeserialize_(field);
|
575
|
+
|
576
|
+
return this.values_[tag] || [];
|
577
|
+
};
|
578
|
+
|
579
|
+
|
580
|
+
/**
|
581
|
+
* Returns the number of values stored in the field by the given tag.
|
582
|
+
*
|
583
|
+
* GENERATED CODE USE ONLY. Basis of the {field}Count methods.
|
584
|
+
*
|
585
|
+
* @param {number} tag The tag.
|
586
|
+
*
|
587
|
+
* @return {number} The number of values.
|
588
|
+
* @protected
|
589
|
+
*/
|
590
|
+
goog.proto2.Message.prototype.count$Values = function(tag) {
|
591
|
+
var field = this.getFieldByTag_(tag);
|
592
|
+
|
593
|
+
if (field.isRepeated()) {
|
594
|
+
if (this.has$Value(tag)) {
|
595
|
+
goog.proto2.Util.assert(goog.isArray(this.values_[tag]));
|
596
|
+
}
|
597
|
+
|
598
|
+
return this.has$Value(tag) ? this.values_[tag].length : 0;
|
599
|
+
} else {
|
600
|
+
return this.has$Value(tag) ? 1 : 0;
|
601
|
+
}
|
602
|
+
};
|
603
|
+
|
604
|
+
|
605
|
+
/**
|
606
|
+
* Sets the value of the *non-repeating* field indicated by the given tag.
|
607
|
+
*
|
608
|
+
* GENERATED CODE USE ONLY. Basis of the set{Field} methods.
|
609
|
+
*
|
610
|
+
* @param {number} tag The field's tag index.
|
611
|
+
* @param {*} value The field's value.
|
612
|
+
* @protected
|
613
|
+
*/
|
614
|
+
goog.proto2.Message.prototype.set$Value = function(tag, value) {
|
615
|
+
if (goog.proto2.Util.conductChecks()) {
|
616
|
+
var field = this.getFieldByTag_(tag);
|
617
|
+
|
618
|
+
goog.proto2.Util.assert(!field.isRepeated(),
|
619
|
+
'Cannot call set on a repeated field');
|
620
|
+
|
621
|
+
this.checkFieldType_(field, value);
|
622
|
+
}
|
623
|
+
|
624
|
+
this.values_[tag] = value;
|
625
|
+
if (this.deserializedFields_) {
|
626
|
+
this.deserializedFields_[tag] = true;
|
627
|
+
}
|
628
|
+
};
|
629
|
+
|
630
|
+
|
631
|
+
/**
|
632
|
+
* Adds the value to the *repeating* field indicated by the given tag.
|
633
|
+
*
|
634
|
+
* GENERATED CODE USE ONLY. Basis of the add{Field} methods.
|
635
|
+
*
|
636
|
+
* @param {number} tag The field's tag index.
|
637
|
+
* @param {*} value The value to add.
|
638
|
+
* @protected
|
639
|
+
*/
|
640
|
+
goog.proto2.Message.prototype.add$Value = function(tag, value) {
|
641
|
+
if (goog.proto2.Util.conductChecks()) {
|
642
|
+
var field = this.getFieldByTag_(tag);
|
643
|
+
|
644
|
+
goog.proto2.Util.assert(field.isRepeated(),
|
645
|
+
'Cannot call add on a non-repeated field');
|
646
|
+
|
647
|
+
this.checkFieldType_(field, value);
|
648
|
+
}
|
649
|
+
|
650
|
+
if (!this.values_[tag]) {
|
651
|
+
this.values_[tag] = [];
|
652
|
+
}
|
653
|
+
|
654
|
+
this.values_[tag].push(value);
|
655
|
+
};
|
656
|
+
|
657
|
+
|
658
|
+
/**
|
659
|
+
* Ensures that the value being assigned to the given field
|
660
|
+
* is valid.
|
661
|
+
*
|
662
|
+
* @param {!goog.proto2.FieldDescriptor} field The field being assigned.
|
663
|
+
* @param {*} value The value being assigned.
|
664
|
+
* @private
|
665
|
+
*/
|
666
|
+
goog.proto2.Message.prototype.checkFieldType_ = function(field, value) {
|
667
|
+
goog.proto2.Util.assert(value !== null);
|
668
|
+
|
669
|
+
var nativeType = field.getNativeType();
|
670
|
+
if (nativeType === String) {
|
671
|
+
goog.proto2.Util.assert(typeof value === 'string',
|
672
|
+
'Expected value of type string');
|
673
|
+
} else if (nativeType === Boolean) {
|
674
|
+
goog.proto2.Util.assert(typeof value === 'boolean',
|
675
|
+
'Expected value of type boolean');
|
676
|
+
} else if (nativeType === Number) {
|
677
|
+
goog.proto2.Util.assert(typeof value === 'number',
|
678
|
+
'Expected value of type number');
|
679
|
+
} else if (field.getFieldType() ==
|
680
|
+
goog.proto2.FieldDescriptor.FieldType.ENUM) {
|
681
|
+
goog.proto2.Util.assert(typeof value === 'number',
|
682
|
+
'Expected an enum value, which is a number');
|
683
|
+
} else {
|
684
|
+
goog.proto2.Util.assert(value instanceof nativeType,
|
685
|
+
'Expected a matching message type');
|
686
|
+
}
|
687
|
+
};
|
688
|
+
|
689
|
+
|
690
|
+
/**
|
691
|
+
* Clears the field specified by tag.
|
692
|
+
*
|
693
|
+
* GENERATED CODE USE ONLY. Basis of the clear{Field} methods.
|
694
|
+
*
|
695
|
+
* @param {number} tag The tag of the field to clear.
|
696
|
+
* @protected
|
697
|
+
*/
|
698
|
+
goog.proto2.Message.prototype.clear$Field = function(tag) {
|
699
|
+
goog.proto2.Util.assert(this.getFieldByTag_(tag), 'Unknown field');
|
700
|
+
delete this.values_[tag];
|
701
|
+
};
|
702
|
+
|
703
|
+
|
704
|
+
/**
|
705
|
+
* Sets the metadata that represents the definition of this message.
|
706
|
+
*
|
707
|
+
* GENERATED CODE USE ONLY. Called when constructing message classes.
|
708
|
+
*
|
709
|
+
* @param {Function} messageType Constructor for the message type to
|
710
|
+
* which this metadata applies.
|
711
|
+
* @param {Object} metadataObj The object containing the metadata.
|
712
|
+
*/
|
713
|
+
goog.proto2.Message.set$Metadata = function(messageType, metadataObj) {
|
714
|
+
var fields = [];
|
715
|
+
var descriptorInfo;
|
716
|
+
|
717
|
+
for (var key in metadataObj) {
|
718
|
+
if (!metadataObj.hasOwnProperty(key)) {
|
719
|
+
continue;
|
720
|
+
}
|
721
|
+
|
722
|
+
goog.proto2.Util.assert(goog.string.isNumeric(key), 'Keys must be numeric');
|
723
|
+
|
724
|
+
if (key == 0) {
|
725
|
+
descriptorInfo = metadataObj[0];
|
726
|
+
continue;
|
727
|
+
}
|
728
|
+
|
729
|
+
// Create the field descriptor.
|
730
|
+
fields.push(
|
731
|
+
new goog.proto2.FieldDescriptor(messageType, key, metadataObj[key]));
|
732
|
+
}
|
733
|
+
|
734
|
+
goog.proto2.Util.assert(descriptorInfo);
|
735
|
+
|
736
|
+
// Create the descriptor.
|
737
|
+
messageType.descriptor_ =
|
738
|
+
new goog.proto2.Descriptor(messageType, descriptorInfo, fields);
|
739
|
+
|
740
|
+
messageType.getDescriptor = function() {
|
741
|
+
return messageType.descriptor_;
|
742
|
+
};
|
743
|
+
};
|
744
|
+
;
|
745
|
+
FI"
|
746
|
+
F"%dc32e8cbd1c3a4a04d28db2bd5d26767
|