The goog.proto2.Message Class

goog.proto2.Message()

Abstract base class for all Protocol Buffer 2 messages. It will be subclassed in the code generated by the Protocol Compiler. Any other subclasses are prohibited.

The goog.proto2.Message.FieldType Enum

An enumeration defining the possible field types. Should be a mirror of that defined in descriptor.h. TODO(user): Remove this alias. The code generator generates code that references this enum, so it needs to exist until the code generator is changed. The enum was moved to from Message to FieldDescriptor to avoid a dependency cycle. Use goog.proto2.FieldDescriptor.FieldType instead. … more

.add(field, value)

Adds the given value to the field specified by the given field descriptor. Note that the field must be repeated.

field {goog.proto2.FieldDescriptor}
The field in which to add the the value.
value {*}
The new value to add to the field.

.arrayOf(field)

Returns the array of values found for the given repeated field.

field {goog.proto2.FieldDescriptor}
The field for which to return the values.
returns {!Array}
The values found.

.clear(field)

Clears the field specified.

field {goog.proto2.FieldDescriptor}
The field to clear.

.clone()

returns {!goog.proto2.Message}
Recursive clone of the message only including the known fields.

.copyFrom(message)

Recursively copies the known fields from the given message to this message. Removes the fields which are not present in the source message.

message {!goog.proto2.Message}
The source message.

.countOf(field)

Returns the number of values stored in the given field.

field {goog.proto2.FieldDescriptor}
The field for which to count the number of values.
returns {number}
The count of the values in the given field.

.equals(other)

Compares this message with another one ignoring the unknown fields.

other {*}
The other message.
returns {boolean}
Whether they are equal. Returns false if the {@code other} argument is a different type of message or not a message.

.forEachUnknown(callback, opt_scope)

Iterates over all the unknown fields in the message.

callback {function(number, *)}
A callback method which gets invoked for each unknown field.
opt_scope {Object=}
The scope under which to execute the callback. If not given, the current message will be used.

.get(field, opt_index)

Returns the value stored at the field specified by the given field descriptor.

field {goog.proto2.FieldDescriptor}
The field for which to get the value.
opt_index {number=}
If the field is repeated, the index to use when looking up the value.
returns {*}
The value found or null if none.

.getDescriptor()

Returns the descriptor which describes the current message.

returns {goog.proto2.Descriptor}
The descriptor.

.getOrDefault(field, opt_index)

Returns the value stored at the field specified by the given field descriptor or the default value if none exists.

field {goog.proto2.FieldDescriptor}
The field for which to get the value.
opt_index {number=}
If the field is repeated, the index to use when looking up the value.
returns {*}
The value found or the default if none.

.has(field)

Returns whether there is a value stored at the field specified by the given field descriptor.

field {goog.proto2.FieldDescriptor}
The field for which to check if there is a value.
returns {boolean}
True if a value was found.

.has$Value(tag)

Returns the whether or not the field indicated by the given tag has a value. GENERATED CODE USE ONLY. Basis of the has{Field} methods.

tag {number}
The tag.
returns {boolean}
Whether the message has a value for the field.

.initDefaults(simpleFieldsToo)

Fills in the protocol buffer with default values. Any fields that are already set will not be overridden.

simpleFieldsToo {boolean}
If true, all fields will be initialized; if false, only the nested messages and groups.

.initializeForLazyDeserializer(deserializer, data)

Initializes the message with a lazy deserializer and its associated data. This method should be called by internal methods ONLY.

deserializer {goog.proto2.LazyDeserializer}
The lazy deserializer to use to decode the data on the fly.
data {*}
The data to decode/deserialize.

.mergeFrom(message)

Merges the given message into this message. Singular fields will be overwritten, except for embedded messages which will be merged. Repeated fields will be concatenated.

message {!goog.proto2.Message}
The source message.

.set(field, value)

Stores the given value to the field specified by the given field descriptor. Note that the field must not be repeated.

field {goog.proto2.FieldDescriptor}
The field for which to set the value.
value {*}
The new value for the field.

.set$Metadata(messageType, metadataObj)

Sets the metadata that represents the definition of this message. GENERATED CODE USE ONLY. Called when constructing message classes.

messageType {Function}
Constructor for the message type to which this metadata applies.
metadataObj {Object}
The object containing the metadata.

.setUnknown(tag, value)

Sets the value of an unknown field, by tag.

tag {number}
The tag of an unknown field (must be >= 1).
value {*}
The value for that unknown field.