Top Description Inners Methods
com.google.protobuf

public Interface Message

extends MessageLite, MessageOrBuilder
Known Direct Implementers
com.google.protobuf.AbstractMessage
Imports
java.io.IOException, .InputStream, java.util.Map

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 and Inner Type Summary

Modifier and TypeClass and Description
public static interface
Message.Builder

Abstract interface implemented by Protocol Message builders.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the specified object is equal to this message
equals
(Object
object to be compared for equality with this message
other
)

Compares the specified object with this message for equality.

public Parser<? extends Message>
getParserForType()

Redeclares com.google.protobuf.MessageLite.getParserForType.

Gets the parser for a message of the same type as this message.
public int

Returns:

the hash code value for this message
hashCode
()

Returns the hash code value for this message.

public Message.Builder
newBuilderForType()

Redeclares com.google.protobuf.MessageLite.newBuilderForType.

Constructs a new builder for a message of the same type as this message.
public Message.Builder
toBuilder()

Redeclares com.google.protobuf.MessageLite.toBuilder.

Constructs a builder initialized with the current message.
public String
toString()

Converts the message to a string in protocol buffer text format.

Inherited from com.google.protobuf.MessageLite:
getSerializedSizetoByteArraytoByteStringwriteDelimitedTowriteTowriteTo
Inherited from com.google.protobuf.MessageOrBuilder:
findInitializationErrorsgetAllFieldsgetDefaultInstanceForTypegetDescriptorForTypegetFieldgetInitializationErrorStringgetOneofFieldDescriptorgetRepeatedFieldgetRepeatedFieldCountgetUnknownFieldshasFieldhasOneof

Method Detail

equalsback to summary
public boolean equals(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. Subclasses must implement this; inheriting Object.equals() is incorrect.

Parameters
other:Object

object to be compared for equality with this message

Returns:boolean

true if the specified object is equal to this message

Annotations
@Override
getParserForTypeback to summary
public Parser<? extends Message> getParserForType()

Redeclares com.google.protobuf.MessageLite.getParserForType.

Doc from com.google.protobuf.MessageLite.getParserForType.

Gets the parser for a message of the same type as this message.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Returns the hash code value for this message. The hash code of a message should mix the message's type (object identity of the descriptor) with its contents (known and unknown field values). Subclasses must implement this; inheriting Object.hashCode() is incorrect.

Returns:int

the hash code value for this message

Annotations
@Override
See Also
Map#hashCode()
newBuilderForTypeback to summary
public Message.Builder newBuilderForType()

Redeclares com.google.protobuf.MessageLite.newBuilderForType.

Doc from com.google.protobuf.MessageLite.newBuilderForType.

Constructs a new builder for a message of the same type as this message.

Annotations
@Override
toBuilderback to summary
public Message.Builder toBuilder()

Redeclares com.google.protobuf.MessageLite.toBuilder.

Doc from com.google.protobuf.MessageLite.toBuilder.

Constructs a builder initialized with the current message. Use this to derive a new message from the current one.

Annotations
@Override
toStringback to summary
public String toString()

Converts the message to a string in protocol buffer text format. This is just a trivial wrapper around TextFormat#printToString(MessageOrBuilder).

Annotations
@Override
com.google.protobuf back to summary

public Interface Message.Builder

extends Builder, MessageOrBuilder
Known Direct Implementers
com.google.protobuf.AbstractMessage.Builder

Abstract interface implemented by Protocol Message builders.

Method Summary

Modifier and TypeMethod and Description
public Message.Builder
addRepeatedField(Descriptors.FieldDescriptor field, Object value)

Like setRepeatedField, but appends the value as a new element.

public Message
build()

Redeclares com.google.protobuf.MessageLite.Builder.build.

Constructs the message based on the state of the Builder.
public Message
buildPartial()

Redeclares com.google.protobuf.MessageLite.Builder.buildPartial.

Like build(), but does not throw an exception if the message is missing required fields.
public Message.Builder
clear()

Redeclares com.google.protobuf.MessageLite.Builder.clear.

Resets all fields to their default values.
public Message.Builder
clearField(Descriptors.FieldDescriptor field)

Clears the field.

public Message.Builder
clearOneof(Descriptors.OneofDescriptor oneof)

Clears the oneof.

public Message.Builder
clone()

Redeclares com.google.protobuf.MessageLite.Builder.clone.

Clones the Builder.
public Descriptors.Descriptor
getDescriptorForType()

Redeclares com.google.protobuf.MessageOrBuilder.getDescriptorForType.

Get the message's type's descriptor.
public Message.Builder
getFieldBuilder(Descriptors.FieldDescriptor field)

Get a nested builder instance for the given field.

public Message.Builder
getRepeatedFieldBuilder(Descriptors.FieldDescriptor field, int index)

Get a nested builder instance for the given repeated field instance.

public boolean
public boolean
public Message.Builder
mergeFrom(Message other)

Merge other into the message being built.

public Message.Builder
mergeFrom(CodedInputStream input)

Redeclares com.google.protobuf.MessageLite.Builder.mergeFrom.

Parses a message of this type from the input and merges it with this message.
public Message.Builder
public Message.Builder
mergeFrom(ByteString data)

Redeclares com.google.protobuf.MessageLite.Builder.mergeFrom.

Parse data as a message of this type and merge it with the message being built.
public Message.Builder
mergeFrom(ByteString data, ExtensionRegistryLite extensionRegistry)

Redeclares com.google.protobuf.MessageLite.Builder.mergeFrom.

Parse data as a message of this type and merge it with the message being built.
public Message.Builder
mergeFrom(byte[] data)

Redeclares com.google.protobuf.MessageLite.Builder.mergeFrom.

Parse data as a message of this type and merge it with the message being built.
public Message.Builder
mergeFrom(byte[] data, int off, int len)

Redeclares com.google.protobuf.MessageLite.Builder.mergeFrom.

Parse data as a message of this type and merge it with the message being built.
public Message.Builder
mergeFrom(byte[] data, ExtensionRegistryLite extensionRegistry)

Redeclares com.google.protobuf.MessageLite.Builder.mergeFrom.

Parse data as a message of this type and merge it with the message being built.
public Message.Builder
mergeFrom(byte[] data, int off, int len, ExtensionRegistryLite extensionRegistry)

Redeclares com.google.protobuf.MessageLite.Builder.mergeFrom.

Parse data as a message of this type and merge it with the message being built.
public Message.Builder
mergeFrom(InputStream input)

Redeclares com.google.protobuf.MessageLite.Builder.mergeFrom.

Parse a message of this type from input and merge it with the message being built.
public Message.Builder
mergeFrom(InputStream input, ExtensionRegistryLite extensionRegistry)

Redeclares com.google.protobuf.MessageLite.Builder.mergeFrom.

Parse a message of this type from input and merge it with the message being built.
public Message.Builder
mergeUnknownFields(UnknownFieldSet unknownFields)

Merge some unknown fields into the UnknownFieldSet for this message.

public Message.Builder
newBuilderForField(Descriptors.FieldDescriptor field)

Create a builder for messages of the appropriate type for the given field.

public Message.Builder
setField(Descriptors.FieldDescriptor field, Object value)

Sets a field to the given value.

public Message.Builder
setRepeatedField(Descriptors.FieldDescriptor field, int index, Object value)

Sets an element of a repeated field to the given value.

public Message.Builder
setUnknownFields(UnknownFieldSet unknownFields)

Set the UnknownFieldSet for this message.

Inherited from com.google.protobuf.MessageLite.Builder:
mergeFrom
Inherited from com.google.protobuf.MessageOrBuilder:
findInitializationErrorsgetAllFieldsgetDefaultInstanceForTypegetFieldgetInitializationErrorStringgetOneofFieldDescriptorgetRepeatedFieldgetRepeatedFieldCountgetUnknownFieldshasFieldhasOneof

Method Detail

addRepeatedFieldback to summary
public Message.Builder addRepeatedField(Descriptors.FieldDescriptor field, Object value)

Like setRepeatedField, but appends the value as a new element.

Exceptions
IllegalArgumentException:
The field is not a repeated field, or field.getContainingType() != getDescriptorForType().
buildback to summary
public Message build()

Redeclares com.google.protobuf.MessageLite.Builder.build.

Doc from com.google.protobuf.MessageLite.Builder.build.

Constructs the message based on the state of the Builder. Subsequent changes to the Builder will not affect the returned message.

Annotations
@Override
buildPartialback to summary
public Message buildPartial()

Redeclares com.google.protobuf.MessageLite.Builder.buildPartial.

Doc from com.google.protobuf.MessageLite.Builder.buildPartial.

Like build(), but does not throw an exception if the message is missing required fields. Instead, a partial message is returned. Subsequent changes to the Builder will not affect the returned message.

Annotations
@Override
clearback to summary
public Message.Builder clear()

Redeclares com.google.protobuf.MessageLite.Builder.clear.

Doc from com.google.protobuf.MessageLite.Builder.clear.

Resets all fields to their default values.

Annotations
@Override
clearFieldback to summary
public Message.Builder clearField(Descriptors.FieldDescriptor field)

Clears the field. This is exactly equivalent to calling the generated "clear" accessor method corresponding to the field.

clearOneofback to summary
public Message.Builder clearOneof(Descriptors.OneofDescriptor oneof)

Clears the oneof. This is exactly equivalent to calling the generated "clear" accessor method corresponding to the oneof.

cloneback to summary
public Message.Builder clone()

Redeclares com.google.protobuf.MessageLite.Builder.clone.

Doc from com.google.protobuf.MessageLite.Builder.clone.

Clones the Builder.

Annotations
@Override
getDescriptorForTypeback to summary
public Descriptors.Descriptor getDescriptorForType()

Redeclares com.google.protobuf.MessageOrBuilder.getDescriptorForType.

Get the message's type's descriptor. See Message#getDescriptorForType().

Annotations
@Override
getFieldBuilderback to summary
public Message.Builder getFieldBuilder(Descriptors.FieldDescriptor field)

Get a nested builder instance for the given field.

Normally, we hold a reference to the immutable message object for the message type field. Some implementations(the generated message builders), however, can also hold a reference to the builder object (a nested builder) for the field.

If the field is already backed up by a nested builder, the nested builder will be returned. Otherwise, a new field builder will be created and returned. The original message field (if exist) will be merged into the field builder, which will then be nested into its parent builder.

Note

implementations that do not support nested builders will throw UnsupportedOperationException.

getRepeatedFieldBuilderback to summary
public Message.Builder getRepeatedFieldBuilder(Descriptors.FieldDescriptor field, int index)

Get a nested builder instance for the given repeated field instance.

Normally, we hold a reference to the immutable message object for the message type field. Some implementations(the generated message builders), however, can also hold a reference to the builder object (a nested builder) for the field.

If the field is already backed up by a nested builder, the nested builder will be returned. Otherwise, a new field builder will be created and returned. The original message field (if exist) will be merged into the field builder, which will then be nested into its parent builder.

Note

implementations that do not support nested builders will throw UnsupportedOperationException.

mergeDelimitedFromback to summary
public boolean mergeDelimitedFrom(InputStream input) throws IOException

Redeclares com.google.protobuf.MessageLite.Builder.mergeDelimitedFrom.

Doc from com.google.protobuf.MessageLite.Builder.mergeDelimitedFrom.

Like mergeFrom(InputStream), but does not read until EOF. Instead, the size of the message (encoded as a varint) is read first, then the message data. Use MessageLite#writeDelimitedTo(OutputStream) to write messages in this format.

Returns:boolean

True if successful, or false if the stream is at EOF when the method starts. Any other error (including reaching EOF during parsing) will cause an exception to be thrown.

Annotations
@Override
mergeDelimitedFromback to summary
public boolean mergeDelimitedFrom(InputStream input, ExtensionRegistryLite extensionRegistry) throws IOException

Redeclares com.google.protobuf.MessageLite.Builder.mergeDelimitedFrom.

Doc from com.google.protobuf.MessageLite.Builder.mergeDelimitedFrom.

Like mergeDelimitedFrom(InputStream) but supporting extensions.

Annotations
@Override
mergeFromback to summary
public Message.Builder mergeFrom(Message other)

Merge other into the message being built. other must have the exact same type as this (i.e. getDescriptorForType() == other.getDescriptorForType()).

Merging occurs as follows. For each field:
* For singular primitive fields, if the field is set in other, then other's value overwrites the value in this message.
* For singular message fields, if the field is set in other, it is merged into the corresponding sub-message of this message using the same merging rules.
* For repeated fields, the elements in other are concatenated with the elements in this message.
* For oneof groups, if the other message has one of the fields set, the group of this message is cleared and replaced by the field of the other message, so that the oneof constraint is preserved.

This is equivalent to the Message::MergeFrom method in C++.

mergeFromback to summary
public Message.Builder mergeFrom(CodedInputStream input) throws IOException

Redeclares com.google.protobuf.MessageLite.Builder.mergeFrom.

Doc from com.google.protobuf.MessageLite.Builder.mergeFrom.

Parses a message of this type from the input and merges it with this message.

Warning: This does not verify that all required fields are present in the input message. If you call build() without setting all required fields, it will throw an UninitializedMessageException, which is a RuntimeException and thus might not be caught. There are a few good ways to deal with this:

  • Call isInitialized() to verify that all required fields are set before building.
  • Use buildPartial() to build, which ignores missing required fields.

Note

The caller should call CodedInputStream#checkLastTagWas(int) after calling this to verify that the last tag seen was the appropriate end-group tag, or zero for EOF.

Annotations
@Override
mergeFromback to summary
public Message.Builder mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws IOException

Redeclares com.google.protobuf.MessageLite.Builder.mergeFrom.

Doc from com.google.protobuf.MessageLite.Builder.mergeFrom.

Like Builder#mergeFrom(CodedInputStream), but also parses extensions. The extensions that you want to be able to parse must be registered in extensionRegistry. Extensions not in the registry will be treated as unknown fields.

Annotations
@Override
mergeFromback to summary
public Message.Builder mergeFrom(ByteString data) throws InvalidProtocolBufferException

Redeclares com.google.protobuf.MessageLite.Builder.mergeFrom.

Doc from com.google.protobuf.MessageLite.Builder.mergeFrom.

Parse data as a message of this type and merge it with the message being built. This is just a small wrapper around mergeFrom(CodedInputStream).

Returns:Message.Builder

this

Annotations
@Override
mergeFromback to summary
public Message.Builder mergeFrom(ByteString data, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException

Redeclares com.google.protobuf.MessageLite.Builder.mergeFrom.

Doc from com.google.protobuf.MessageLite.Builder.mergeFrom.

Parse data as a message of this type and merge it with the message being built. This is just a small wrapper around mergeFrom(CodedInputStream, ExtensionRegistryLite).

Returns:Message.Builder

this

Annotations
@Override
mergeFromback to summary
public Message.Builder mergeFrom(byte[] data) throws InvalidProtocolBufferException

Redeclares com.google.protobuf.MessageLite.Builder.mergeFrom.

Doc from com.google.protobuf.MessageLite.Builder.mergeFrom.

Parse data as a message of this type and merge it with the message being built. This is just a small wrapper around mergeFrom(CodedInputStream).

Returns:Message.Builder

this

Annotations
@Override
mergeFromback to summary
public Message.Builder mergeFrom(byte[] data, int off, int len) throws InvalidProtocolBufferException

Redeclares com.google.protobuf.MessageLite.Builder.mergeFrom.

Doc from com.google.protobuf.MessageLite.Builder.mergeFrom.

Parse data as a message of this type and merge it with the message being built. This is just a small wrapper around mergeFrom(CodedInputStream).

Returns:Message.Builder

this

Annotations
@Override
mergeFromback to summary
public Message.Builder mergeFrom(byte[] data, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException

Redeclares com.google.protobuf.MessageLite.Builder.mergeFrom.

Doc from com.google.protobuf.MessageLite.Builder.mergeFrom.

Parse data as a message of this type and merge it with the message being built. This is just a small wrapper around mergeFrom(CodedInputStream, ExtensionRegistryLite).

Returns:Message.Builder

this

Annotations
@Override
mergeFromback to summary
public Message.Builder mergeFrom(byte[] data, int off, int len, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException

Redeclares com.google.protobuf.MessageLite.Builder.mergeFrom.

Doc from com.google.protobuf.MessageLite.Builder.mergeFrom.

Parse data as a message of this type and merge it with the message being built. This is just a small wrapper around mergeFrom(CodedInputStream, ExtensionRegistryLite).

Returns:Message.Builder

this

Annotations
@Override
mergeFromback to summary
public Message.Builder mergeFrom(InputStream input) throws IOException

Redeclares com.google.protobuf.MessageLite.Builder.mergeFrom.

Doc from com.google.protobuf.MessageLite.Builder.mergeFrom.

Parse a message of this type from input and merge it with the message being built. This is just a small wrapper around mergeFrom(CodedInputStream). Note that this method always reads the entire input (unless it throws an exception). If you want it to stop earlier, you will need to wrap your input in some wrapper stream that limits reading. Or, use MessageLite#writeDelimitedTo(OutputStream) to write your message and mergeDelimitedFrom(InputStream) to read it.

Despite usually reading the entire input, this does not close the stream.

Returns:Message.Builder

this

Annotations
@Override
mergeFromback to summary
public Message.Builder mergeFrom(InputStream input, ExtensionRegistryLite extensionRegistry) throws IOException

Redeclares com.google.protobuf.MessageLite.Builder.mergeFrom.

Doc from com.google.protobuf.MessageLite.Builder.mergeFrom.

Parse a message of this type from input and merge it with the message being built. This is just a small wrapper around mergeFrom(CodedInputStream, ExtensionRegistryLite).

Returns:Message.Builder

this

Annotations
@Override
mergeUnknownFieldsback to summary
public Message.Builder mergeUnknownFields(UnknownFieldSet unknownFields)

Merge some unknown fields into the UnknownFieldSet for this message.

newBuilderForFieldback to summary
public Message.Builder newBuilderForField(Descriptors.FieldDescriptor field)

Create a builder for messages of the appropriate type for the given field. The builder is NOT nested in the current builder. However, messages built with the builder can then be passed to the setField(Descriptors.FieldDescriptor, Object), setRepeatedField(Descriptors.FieldDescriptor, int, Object), or addRepeatedField(Descriptors.FieldDescriptor, Object) method of the current builder.

To obtain a builder nested in the current builder, use getFieldBuilder(Descriptors.FieldDescriptor) instead.

setFieldback to summary
public Message.Builder setField(Descriptors.FieldDescriptor field, Object value)

Sets a field to the given value. The value must be of the correct type for this field, i.e. the same type that Message#getField(Descriptors.FieldDescriptor) would return.

setRepeatedFieldback to summary
public Message.Builder setRepeatedField(Descriptors.FieldDescriptor field, int index, Object value)

Sets an element of a repeated field to the given value. The value must be of the correct type for this field, i.e. the same type that Message#getRepeatedField(Descriptors.FieldDescriptor, int) would return.

Exceptions
IllegalArgumentException:
The field is not a repeated field, or field.getContainingType() != getDescriptorForType().
setUnknownFieldsback to summary
public Message.Builder setUnknownFields(UnknownFieldSet unknownFields)

Set the UnknownFieldSet for this message.