com.google.protobuf
Interface Message

All Superinterfaces:
MessageLite
All Known Implementing Classes:
AbstractMessage, DynamicMessage, GeneratedMessage, GeneratedMessage.ExtendableMessage

public interface Message
extends MessageLite

Abstract interface implemented by Protocol Message objects.

See also MessageLite, which defines most of the methods that typical users care about. Message adds to it methods that are not available in the "lite" runtime. The biggest added features are introspection and reflection -- i.e., getting descriptors for the message type and accessing the field values dynamically.

Author:
[email protected] Kenton Varda

Nested Class Summary
static interface Message.Builder
          Abstract interface implemented by Protocol Message builders.
 
Method Summary
 boolean equals(java.lang.Object other)
          Compares the specified object with this message for equality.
 java.util.Map<Descriptors.FieldDescriptor,java.lang.Object> getAllFields()
          Returns a collection of all the fields in this message which are set and their corresponding values.
 Message getDefaultInstanceForType()
          Get an instance of the type with all fields set to their default values.
 Descriptors.Descriptor getDescriptorForType()
          Get the message's type's descriptor.
 java.lang.Object getField(Descriptors.FieldDescriptor field)
          Obtains the value of the given field, or the default value if it is not set.
 java.lang.Object getRepeatedField(Descriptors.FieldDescriptor field, int index)
          Gets an element of a repeated field.
 int getRepeatedFieldCount(Descriptors.FieldDescriptor field)
          Gets the number of elements of a repeated field.
 UnknownFieldSet getUnknownFields()
          Get the UnknownFieldSet for this message.
 boolean hasField(Descriptors.FieldDescriptor field)
          Returns true if the given field is set.
 int hashCode()
          Returns the hash code value for this message.
 Message.Builder newBuilderForType()
          Constructs a new builder for a message of the same type as this message.
 Message.Builder toBuilder()
          Constructs a builder initialized with the current message.
 java.lang.String toString()
          Converts the message to a string in protocol buffer text format.
 
Methods inherited from interface com.google.protobuf.MessageLite
getSerializedSize, isInitialized, toByteArray, toByteString, writeDelimitedTo, writeTo, writeTo
 

Method Detail

getDescriptorForType

Descriptors.Descriptor getDescriptorForType()
Get the message's type's descriptor. This differs from the getDescriptor() method of generated message classes in that this method is an abstract method of the Message interface whereas getDescriptor() is a static method of a specific class. They return the same thing.


getDefaultInstanceForType

Message getDefaultInstanceForType()
Description copied from interface: MessageLite
Get an instance of the type with all fields set to their default values. This may or may not be a singleton. This differs from the getDefaultInstance() method of generated message classes in that this method is an abstract method of the MessageLite interface whereas getDefaultInstance() is a static method of a specific class. They return the same thing.

Specified by:
getDefaultInstanceForType in interface MessageLite

getAllFields

java.util.Map<Descriptors.FieldDescriptor,java.lang.Object> getAllFields()
Returns a collection of all the fields in this message which are set and their corresponding values. A singular ("required" or "optional") field is set iff hasField() returns true for that field. A "repeated" field is set iff getRepeatedFieldSize() is greater than zero. The values are exactly what would be returned by calling getField(Descriptors.FieldDescriptor) for each field. The map is guaranteed to be a sorted map, so iterating over it will return fields in order by field number.


hasField

boolean hasField(Descriptors.FieldDescriptor field)
Returns true if the given field is set. This is exactly equivalent to calling the generated "has" accessor method corresponding to the field.

Throws:
java.lang.IllegalArgumentException - The field is a repeated field, or field.getContainingType() != getDescriptorForType().

getField

java.lang.Object getField(Descriptors.FieldDescriptor field)
Obtains the value of the given field, or the default value if it is not set. For primitive fields, the boxed primitive value is returned. For enum fields, the EnumValueDescriptor for the value is returend. For embedded message fields, the sub-message is returned. For repeated fields, a java.util.List is returned.


getRepeatedFieldCount

int getRepeatedFieldCount(Descriptors.FieldDescriptor field)
Gets the number of elements of a repeated field. This is exactly equivalent to calling the generated "Count" accessor method corresponding to the field.

Throws:
java.lang.IllegalArgumentException - The field is not a repeated field, or field.getContainingType() != getDescriptorForType().

getRepeatedField

java.lang.Object getRepeatedField(Descriptors.FieldDescriptor field,
                                  int index)
Gets an element of a repeated field. For primitive fields, the boxed primitive value is returned. For enum fields, the EnumValueDescriptor for the value is returend. For embedded message fields, the sub-message is returned.

Throws:
java.lang.IllegalArgumentException - The field is not a repeated field, or field.getContainingType() != getDescriptorForType().

getUnknownFields

UnknownFieldSet getUnknownFields()
Get the UnknownFieldSet for this message.


equals

boolean equals(java.lang.Object other)
Compares the specified object with this message for equality. Returns true if the given object is a message of the same type (as defined by getDescriptorForType()) and has identical values for all of its fields.

Overrides:
equals in class java.lang.Object
Parameters:
other - object to be compared for equality with this message
Returns:
true if the specified object is equal to this message

hashCode

int hashCode()
Returns the hash code value for this message. The hash code of a message is defined to be getDescriptor().hashCode() ^ map.hashCode(), where map is a map of field numbers to field values.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code value for this message
See Also:
Map.hashCode()

toString

java.lang.String toString()
Converts the message to a string in protocol buffer text format. This is just a trivial wrapper around TextFormat.printToString(Message).

Overrides:
toString in class java.lang.Object

newBuilderForType

Message.Builder newBuilderForType()
Description copied from interface: MessageLite
Constructs a new builder for a message of the same type as this message.

Specified by:
newBuilderForType in interface MessageLite

toBuilder

Message.Builder toBuilder()
Description copied from interface: MessageLite
Constructs a builder initialized with the current message. Use this to derive a new message from the current one.

Specified by:
toBuilder in interface MessageLite


Copyright © 2008-2010 Google. All Rights Reserved.