Home | History | Annotate | Download | only in js

Lines Matching defs:Message

32  * @fileoverview Definition of jspb.Message.
38 goog.provide('jspb.Message');
75 * binary{Reader,Writer}Fn and (if message type) binaryMessageSerializeFn are
78 * this extension, and binaryMessageSerializeFn is a reference to the message
83 * @param {?function(new: jspb.Message, Array=)} ctor
84 * @param {?function((boolean|undefined),!jspb.Message):!Object} toObjectFn
123 * @return {boolean} Does this field represent a sub Message?
135 jspb.Message = function() {
147 goog.define('jspb.Message.GENERATE_TO_OBJECT', true);
162 goog.define('jspb.Message.GENERATE_FROM_OBJECT', !goog.DISALLOW_TEST_ONLY_CODE);
172 goog.define('jspb.Message.MINIMIZE_MEMORY_ALLOCATIONS', COMPILED);
181 jspb.Message.SUPPORTS_UINT8ARRAY_ = (typeof Uint8Array == 'function');
189 jspb.Message.prototype.array;
193 * Wrappers are the constructed instances of message-type fields. They are built
194 * on demand from the raw array data. Includes message fields, repeated message
195 * fields and extension message fields. Indexed by field number.
199 jspb.Message.prototype.wrappers_;
208 jspb.Message.prototype.extensionObject_;
217 jspb.Message.prototype.pivot_;
222 * @type {string|undefined} the message id or undefined if this message
226 jspb.Message.prototype.messageId_;
234 jspb.Message.prototype.convertedFloatingPointFields_;
241 * Available if {@link jspb.generate_xid} is added as a Message option to
243 * @const {!xid.String|undefined} The xid or undefined if message is
246 jspb.Message.prototype.messageXid;
252 * @return {string|undefined} the message id or undefined if this message
255 jspb.Message.prototype.getJsPbMessageId = function() {
267 jspb.Message.prototype.arrayIndexOffset_;
273 * @param {!jspb.Message} msg Message for which we're calculating an index.
278 jspb.Message.getIndex_ = function(msg, fieldNumber) {
284 * Initializes a JsPb Message.
285 * @param {!jspb.Message} msg The JsPb proto to modify.
287 * @param {string|number} messageId For response messages, the message id or ''
288 * if no message id is specified. For non-response messages, 0.
292 * required for this message type.
293 * @param {Array<number>} repeatedFields The message's repeated fields.
295 * each of the message's oneof unions.
298 jspb.Message.initialize = function(
300 msg.wrappers_ = jspb.Message.MINIMIZE_MEMORY_ALLOCATIONS ? null : {};
305 // If the messageId is 0, this message is not a response message, so we shift
310 jspb.Message.materializeExtensionObject_(msg, suggestedPivot);
317 var index = jspb.Message.getIndex_(msg, fieldNumber);
319 (jspb.Message.MINIMIZE_MEMORY_ALLOCATIONS ?
320 jspb.Message.EMPTY_LIST_SENTINEL_ :
325 (jspb.Message.MINIMIZE_MEMORY_ALLOCATIONS ?
326 jspb.Message.EMPTY_LIST_SENTINEL_ :
336 opt_oneofFields, goog.partial(jspb.Message.computeOneofCase, msg));
349 jspb.Message.EMPTY_LIST_SENTINEL_ = goog.DEBUG && Object.freeze ?
361 * @param {!jspb.Message} msg The JsPb proto to modify.
365 jspb.Message.materializeExtensionObject_ = function(msg, suggestedPivot) {
391 var pivotIndex = jspb.Message.getIndex_(msg, suggestedPivot);
392 if (!jspb.Message.MINIMIZE_MEMORY_ALLOCATIONS) {
407 * @param {!jspb.Message} msg The JsPb proto to modify.
410 jspb.Message.maybeInitEmptyExtensionObject_ = function(msg) {
411 var pivotIndex = jspb.Message.getIndex_(msg, msg.pivot_);
419 * Converts a JsPb repeated message field into an object list.
420 * @param {!Array<T>} field The repeated message field to be
428 * @return {!Array<Object>} An array of converted message objects.
431 jspb.Message.toObjectList = function(field, toObjectFn, opt_includeInstance) {
437 /** @type {!jspb.Message} */ (field[i]));
445 * @param {!jspb.Message} proto The proto whose extensions to convert.
454 jspb.Message.toObjectExtension = function(proto, obj, extensions,
469 obj[name] = jspb.Message.toObjectList(
470 /** @type {!Array<jspb.Message>} */ (value),
483 * @param {!jspb.Message} proto The proto whose extensions to convert.
489 jspb.Message.serializeBinaryExtensions = function(proto, writer, extensions,
497 throw new Error('Message extension present that was generated ' +
503 // If the message type of the extension was generated without binary
504 // support, there may not be a binary message serializer function, and
505 // we can't know when we codegen the extending message that the extended
506 // message may require binary support, so we can *only* catch this error
513 throw new Error('Message extension present holding submessage ' +
514 'without binary support enabled, and message is ' +
528 * @param {!jspb.Message} msg A jspb proto.
534 jspb.Message.readBinaryExtension = function(msg, reader, extensions,
571 * @param {!jspb.Message} msg A jspb proto.
577 jspb.Message.getField = function(msg, fieldNumber) {
579 var index = jspb.Message.getIndex_(msg, fieldNumber);
581 if (val === jspb.Message.EMPTY_LIST_SENTINEL_) {
587 if (val === jspb.Message.EMPTY_LIST_SENTINEL_) {
597 * @param {!jspb.Message} msg A jspb proto.
602 jspb.Message.getOptionalFloatingPointField = function(msg, fieldNumber) {
603 var value = jspb.Message.getField(msg, fieldNumber);
611 * @param {!jspb.Message} msg A jspb proto.
616 jspb.Message.getRepeatedFloatingPointField = function(msg, fieldNumber) {
617 var values = jspb.Message.getField(msg, fieldNumber);
638 jspb.Message.bytesAsB64 = function(value) {
642 if (jspb.Message.SUPPORTS_UINT8ARRAY_ && value instanceof Uint8Array) {
657 jspb.Message.bytesAsU8 = function(value) {
675 jspb.Message.bytesListAsB64 = function(value) {
676 jspb.Message.assertConsistentTypes_(value);
680 return goog.array.map(value, jspb.Message.bytesAsB64);
692 jspb.Message.bytesListAsU8 = function(value) {
693 jspb.Message.assertConsistentTypes_(value);
697 return goog.array.map(value, jspb.Message.bytesAsU8);
706 jspb.Message.assertConsistentTypes_ = function(array) {
724 * @param {!jspb.Message} msg A jspb proto.
730 jspb.Message.getFieldProto3 = function(msg, fieldNumber, defaultValue) {
731 var value = jspb.Message.getField(msg, fieldNumber);
742 * @param {!jspb.Message} msg A jspb proto.
747 jspb.Message.setField = function(msg, fieldNumber, value) {
749 msg.array[jspb.Message.getIndex_(msg, fieldNumber)] = value;
759 * @param {!jspb.Message} msg A jspb proto.
765 jspb.Message.setOneofField = function(msg, fieldNumber, oneof, value) {
766 var currentCase = jspb.Message.computeOneofCase(msg, oneof);
771 jspb.Message.setField(msg, currentCase, undefined);
773 jspb.Message.setField(msg, fieldNumber, value);
778 * Computes the selection in a oneof group for the given message, ensuring
784 * last member seen is used in the parsed message." Since JSPB serializes
789 * @param {!jspb.Message} msg A jspb proto.
794 jspb.Message.computeOneofCase = function(msg, oneof) {
799 var value = jspb.Message.getField(msg, fieldNumber);
803 jspb.Message.setField(msg, fieldNumber, undefined);
808 // NB: We know the value is unique, so we can call jspb.Message.setField
809 // directly instead of jpsb.Message.setOneofField. Also, setOneofField
811 jspb.Message.setField(msg, oneofField, oneofValue);
821 * @param {!jspb.Message} msg A jspb proto.
822 * @param {function(new:jspb.Message, Array)} ctor Constructor for the field.
825 * @return {jspb.Message} The field as a jspb proto.
828 jspb.Message.getWrapperField = function(msg, ctor, fieldNumber, opt_required) {
834 var data = /** @type {Array} */ (jspb.Message.getField(msg, fieldNumber));
840 return /** @type {jspb.Message} */ (msg.wrappers_[fieldNumber]);
846 * @param {!jspb.Message} msg A jspb proto.
847 * @param {function(new:jspb.Message, Array)} ctor Constructor for the field.
849 * @return {Array<!jspb.Message>} The repeated field as an array of protos.
852 jspb.Message.getRepeatedWrapperField = function(msg, ctor, fieldNumber) {
857 var data = jspb.Message.getField(msg, fieldNumber);
864 if (val == jspb.Message.EMPTY_LIST_SENTINEL_) {
867 return /** @type {Array<!jspb.Message>} */ (val);
873 * @param {!jspb.Message} msg A jspb proto.
875 * @param {jspb.Message|undefined} value A new value for this proto field.
878 jspb.Message.setWrapperField = function(msg, fieldNumber, value) {
884 jspb.Message.setField(msg, fieldNumber, data);
890 * @param {!jspb.Message} msg A jspb proto.
893 * @param {jspb.Message|undefined} value A new value for this proto field.
896 jspb.Message.setOneofWrapperField = function(msg, fieldNumber, oneof, value) {
902 jspb.Message.setOneofField(msg, fieldNumber, oneof, data);
908 * @param {!jspb.Message} msg A jspb proto.
910 * @param {Array<!jspb.Message>|undefined} value An array of protos.
913 jspb.Message.setRepeatedWrapperField = function(msg, fieldNumber, value) {
922 jspb.Message.setField(msg, fieldNumber, data);
927 * Converts a JsPb repeated message field into a map. The map will contain
930 * @param {!Array<T>} field The repeated message field to be
943 jspb.Message.toMap = function(
949 /** @type {!jspb.Message} */ (field[i])) : field[i];
961 jspb.Message.prototype.toArray = function() {
974 jspb.Message.prototype.toString = function() {
985 jspb.Message.prototype.getExtension = function(fieldInfo) {
1024 * @param {jspb.Message|string|Uint8Array|number|boolean|Array?} value The value
1027 jspb.Message.prototype.setExtension = function(fieldInfo, value) {
1031 jspb.Message.maybeInitEmptyExtensionObject_(this);
1038 /** @type {Array<jspb.Message>} */ (value), function(msg) {
1067 * @param {!jspb.Message} m1 The first message object.
1068 * @param {!jspb.Message} m2 The second message object.
1069 * @return {!jspb.Message} The difference returned as a proto message.
1070 * Note that the returned message may be missing required fields. This is
1076 jspb.Message.difference = function(m1, m2) {
1090 if (!jspb.Message.compareFields(arr1[i], arr2[i])) {
1100 * @param {jspb.Message|undefined} m1 The first message object.
1101 * @param {jspb.Message|undefined} m2 The second message object.
1105 jspb.Message.equals = function(m1, m2) {
1107 jspb.Message.compareFields(m1.toArray(), m2.toArray()));
1112 * Compares two message extension fields recursively.
1118 jspb.Message.compareExtensions = function(extension1, extension2) {
1130 if (!jspb.Message.compareFields(extension1[name], extension2[name])) {
1139 * Compares two message fields recursively.
1144 jspb.Message.compareFields = function(field1, field2) {
1160 if (jspb.Message.SUPPORTS_UINT8ARRAY_ && field1.constructor === Uint8Array) {
1195 if (!jspb.Message.compareFields(val1, val2)) {
1203 return jspb.Message.compareExtensions(extension1, extension2);
1212 return jspb.Message.compareExtensions(field1, field2);
1222 * @param {!jspb.Message} msg A message to clone.
1223 * @return {!jspb.Message} A deep clone of the given message.
1225 jspb.Message.clone = function(msg) {
1227 return jspb.Message.cloneMessage(msg);
1232 * @param {!jspb.Message} msg A message to clone.
1233 * @return {!jspb.Message} A deep clone of the given message.
1236 jspb.Message.cloneMessage = function(msg) {
1238 return new msg.constructor(jspb.Message.clone_(msg.toArray()));
1244 * message into the second. After this the 2 messages will equals in terms of
1245 * value semantics but share no state. All data in the destination message will
1248 * @param {MESSAGE} fromMessage Message that will be copied into toMessage.
1249 * @param {MESSAGE} toMessage Message which will receive a copy of fromMessage
1251 * @template MESSAGE
1253 jspb.Message.copyInto = function(fromMessage, toMessage) {
1254 goog.asserts.assertInstanceof(fromMessage, jspb.Message);
1255 goog.asserts.assertInstanceof(toMessage, jspb.Message);
1257 'Copy source and target message should have the same type.');
1258 var copyOfFrom = jspb.Message.clone(fromMessage);
1265 // and then copy everything from the new to the existing message.
1283 jspb.Message.clone_ = function(obj) {
1291 clonedArray[i] = typeof o == 'object' ? jspb.Message.clone_(o) : o;
1299 clone[key] = typeof o == 'object' ? jspb.Message.clone_(o) : o;
1307 * Registers a JsPb message type id with its constructor.
1308 * @param {string} id The id for this type of message.
1309 * @param {Function} constructor The message constructor.
1311 jspb.Message.registerMessageType = function(id, constructor) {
1312 jspb.Message.registry_[id] = constructor;
1320 * The registry of message ids to message constructors.
1323 jspb.Message.registry_ = {};
1337 jspb.Message.messageSetExtensions = {};