public static final class DynamicMessage.Builder extends AbstractMessage.Builder<DynamicMessage.Builder>
Methods
addRepeatedField(Descriptors.FieldDescriptor field, Object value)
public DynamicMessage.Builder addRepeatedField(Descriptors.FieldDescriptor field, Object value)
build()
public DynamicMessage build()
buildPartial()
public DynamicMessage buildPartial()
clear()
public DynamicMessage.Builder clear()
Resets all fields to their default values.
Overrides
clearField(Descriptors.FieldDescriptor field)
public DynamicMessage.Builder clearField(Descriptors.FieldDescriptor field)
clearOneof(Descriptors.OneofDescriptor oneof)
public DynamicMessage.Builder clearOneof(Descriptors.OneofDescriptor oneof)
TODO(jieluo): Clear it when all subclasses have implemented this method.
Overrides
clone()
public DynamicMessage.Builder clone()
Overrides
getAllFields()
public Map<Descriptors.FieldDescriptor,Object> getAllFields()
getDefaultInstanceForType()
public DynamicMessage getDefaultInstanceForType()
getDescriptorForType()
public Descriptors.Descriptor getDescriptorForType()
getField(Descriptors.FieldDescriptor field)
public Object getField(Descriptors.FieldDescriptor field)
getFieldBuilder(Descriptors.FieldDescriptor field)
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
.
Overrides
getOneofFieldDescriptor(Descriptors.OneofDescriptor oneof)
public Descriptors.FieldDescriptor getOneofFieldDescriptor(Descriptors.OneofDescriptor oneof)
TODO(jieluo): Clear it when all subclasses have implemented this method.
Overrides
getRepeatedField(Descriptors.FieldDescriptor field, int index)
public Object getRepeatedField(Descriptors.FieldDescriptor field, int index)
getRepeatedFieldBuilder(Descriptors.FieldDescriptor field, int index)
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
.
Overrides
getRepeatedFieldCount(Descriptors.FieldDescriptor field)
public int getRepeatedFieldCount(Descriptors.FieldDescriptor field)
Returns |
---|
Type | Description |
int | |
getUnknownFields()
public UnknownFieldSet getUnknownFields()
hasField(Descriptors.FieldDescriptor field)
public boolean hasField(Descriptors.FieldDescriptor field)
hasOneof(Descriptors.OneofDescriptor oneof)
public boolean hasOneof(Descriptors.OneofDescriptor oneof)
TODO(jieluo): Clear it when all subclasses have implemented this method.
Overrides
isInitialized()
public boolean isInitialized()
mergeFrom(Message other)
public DynamicMessage.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++.
Parameter |
---|
Name | Description |
other | Message
|
Overrides
mergeUnknownFields(UnknownFieldSet unknownFields)
public DynamicMessage.Builder mergeUnknownFields(UnknownFieldSet unknownFields)
Overrides
newBuilderForField(Descriptors.FieldDescriptor field)
public DynamicMessage.Builder newBuilderForField(Descriptors.FieldDescriptor field)
setField(Descriptors.FieldDescriptor field, Object value)
public DynamicMessage.Builder setField(Descriptors.FieldDescriptor field, Object value)
setRepeatedField(Descriptors.FieldDescriptor field, int index, Object value)
public DynamicMessage.Builder setRepeatedField(Descriptors.FieldDescriptor field, int index, Object value)
setUnknownFields(UnknownFieldSet unknownFields)
public DynamicMessage.Builder setUnknownFields(UnknownFieldSet unknownFields)