public static final class DynamicMessage.Builder extends AbstractMessage.Builder<DynamicMessage.Builder>
DynamicMessage
s.Modifier and Type | Method and Description |
---|---|
DynamicMessage.Builder |
addRepeatedField(Descriptors.FieldDescriptor field,
java.lang.Object value)
Like
setRepeatedField , but appends the value as a new element. |
DynamicMessage |
build()
Constructs the message based on the state of the Builder.
|
DynamicMessage |
buildPartial()
Like
MessageLite.Builder.build() , but does not throw an exception if the message
is missing required fields. |
DynamicMessage.Builder |
clear()
Resets all fields to their default values.
|
DynamicMessage.Builder |
clearField(Descriptors.FieldDescriptor field)
Clears the field.
|
DynamicMessage.Builder |
clone()
Clones the Builder.
|
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.
|
DynamicMessage |
getDefaultInstanceForType()
Get an instance of the type with no fields set.
|
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.
|
Message.Builder |
getFieldBuilder(Descriptors.FieldDescriptor field)
Get a nested builder instance for the given field.
|
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.
|
boolean |
isInitialized()
Returns true if all required fields in the message and all embedded
messages are set, false otherwise.
|
DynamicMessage.Builder |
mergeFrom(Message other)
Merge
other into the message being built. |
DynamicMessage.Builder |
mergeUnknownFields(UnknownFieldSet unknownFields)
Merge some unknown fields into the
UnknownFieldSet for this
message. |
DynamicMessage.Builder |
newBuilderForField(Descriptors.FieldDescriptor field)
Create a Builder for messages of the appropriate type for the given
field.
|
DynamicMessage.Builder |
setField(Descriptors.FieldDescriptor field,
java.lang.Object value)
Sets a field to the given value.
|
DynamicMessage.Builder |
setRepeatedField(Descriptors.FieldDescriptor field,
int index,
java.lang.Object value)
Sets an element of a repeated field to the given value.
|
DynamicMessage.Builder |
setUnknownFields(UnknownFieldSet unknownFields)
Set the
UnknownFieldSet for this message. |
findInitializationErrors, getInitializationErrorString, mergeDelimitedFrom, mergeDelimitedFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom
public DynamicMessage.Builder clear()
MessageLite.Builder
clear
in interface Message.Builder
clear
in interface MessageLite.Builder
clear
in class AbstractMessage.Builder<DynamicMessage.Builder>
public DynamicMessage.Builder mergeFrom(Message other)
Message.Builder
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:other
,
then other
's value overwrites the value in this message.other
,
it is merged into the corresponding sub-message of this message
using the same merging rules.other
are concatenated
with the elements in this message.
This is equivalent to the Message::MergeFrom
method in C++.mergeFrom
in interface Message.Builder
mergeFrom
in class AbstractMessage.Builder<DynamicMessage.Builder>
public DynamicMessage build()
MessageLite.Builder
public DynamicMessage buildPartial()
MessageLite.Builder
MessageLite.Builder.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.public DynamicMessage.Builder clone()
MessageLite.Builder
clone
in interface Message.Builder
clone
in interface MessageLite.Builder
clone
in class AbstractMessage.Builder<DynamicMessage.Builder>
Object.clone()
public boolean isInitialized()
MessageLiteOrBuilder
public Descriptors.Descriptor getDescriptorForType()
Message.Builder
MessageOrBuilder.getDescriptorForType()
.public DynamicMessage getDefaultInstanceForType()
MessageLiteOrBuilder
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.public java.util.Map<Descriptors.FieldDescriptor,java.lang.Object> getAllFields()
MessageOrBuilder
MessageOrBuilder.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.
public DynamicMessage.Builder newBuilderForField(Descriptors.FieldDescriptor field)
Message.Builder
public boolean hasField(Descriptors.FieldDescriptor field)
MessageOrBuilder
public java.lang.Object getField(Descriptors.FieldDescriptor field)
MessageOrBuilder
public DynamicMessage.Builder setField(Descriptors.FieldDescriptor field, java.lang.Object value)
Message.Builder
MessageOrBuilder.getField(Descriptors.FieldDescriptor)
would return.public DynamicMessage.Builder clearField(Descriptors.FieldDescriptor field)
Message.Builder
public int getRepeatedFieldCount(Descriptors.FieldDescriptor field)
MessageOrBuilder
public java.lang.Object getRepeatedField(Descriptors.FieldDescriptor field, int index)
MessageOrBuilder
public DynamicMessage.Builder setRepeatedField(Descriptors.FieldDescriptor field, int index, java.lang.Object value)
Message.Builder
MessageOrBuilder.getRepeatedField(Descriptors.FieldDescriptor,int)
would
return.public DynamicMessage.Builder addRepeatedField(Descriptors.FieldDescriptor field, java.lang.Object value)
Message.Builder
setRepeatedField
, but appends the value as a new element.public UnknownFieldSet getUnknownFields()
MessageOrBuilder
UnknownFieldSet
for this message.public DynamicMessage.Builder setUnknownFields(UnknownFieldSet unknownFields)
Message.Builder
UnknownFieldSet
for this message.public DynamicMessage.Builder mergeUnknownFields(UnknownFieldSet unknownFields)
Message.Builder
UnknownFieldSet
for this
message.mergeUnknownFields
in interface Message.Builder
mergeUnknownFields
in class AbstractMessage.Builder<DynamicMessage.Builder>
public Message.Builder getFieldBuilder(Descriptors.FieldDescriptor field)
Message.Builder
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
UnsupportedException
.
getFieldBuilder
in interface Message.Builder
getFieldBuilder
in class AbstractMessage.Builder<DynamicMessage.Builder>