Class DynamicMessage.Builder (3.19.4)

public static final class DynamicMessage.Builder extends AbstractMessage.Builder<DynamicMessage.Builder>

Builder for DynamicMessages.

Methods

addRepeatedField(Descriptors.FieldDescriptor field, Object value)

public DynamicMessage.Builder addRepeatedField(Descriptors.FieldDescriptor field, Object value)
Parameters
NameDescription
fieldDescriptors.FieldDescriptor
valueObject
Returns
TypeDescription
DynamicMessage.Builder

build()

public DynamicMessage build()
Returns
TypeDescription
DynamicMessage

buildPartial()

public DynamicMessage buildPartial()
Returns
TypeDescription
DynamicMessage

clear()

public DynamicMessage.Builder clear()

Resets all fields to their default values.

Returns
TypeDescription
DynamicMessage.Builder
Overrides

clearField(Descriptors.FieldDescriptor field)

public DynamicMessage.Builder clearField(Descriptors.FieldDescriptor field)
Parameter
NameDescription
fieldDescriptors.FieldDescriptor
Returns
TypeDescription
DynamicMessage.Builder

clearOneof(Descriptors.OneofDescriptor oneof)

public DynamicMessage.Builder clearOneof(Descriptors.OneofDescriptor oneof)

TODO(jieluo): Clear it when all subclasses have implemented this method.

Parameter
NameDescription
oneofDescriptors.OneofDescriptor
Returns
TypeDescription
DynamicMessage.Builder
Overrides

clone()

public DynamicMessage.Builder clone()

Clones the Builder.

Returns
TypeDescription
DynamicMessage.Builder
Overrides

getAllFields()

public Map<Descriptors.FieldDescriptor,Object> getAllFields()
Returns
TypeDescription
Map<FieldDescriptor,Object>

getDefaultInstanceForType()

public DynamicMessage getDefaultInstanceForType()
Returns
TypeDescription
DynamicMessage

getDescriptorForType()

public Descriptors.Descriptor getDescriptorForType()
Returns
TypeDescription
Descriptors.Descriptor

getField(Descriptors.FieldDescriptor field)

public Object getField(Descriptors.FieldDescriptor field)
Parameter
NameDescription
fieldDescriptors.FieldDescriptor
Returns
TypeDescription
Object

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.

Parameter
NameDescription
fieldDescriptors.FieldDescriptor
Returns
TypeDescription
Message.Builder
Overrides

getOneofFieldDescriptor(Descriptors.OneofDescriptor oneof)

public Descriptors.FieldDescriptor getOneofFieldDescriptor(Descriptors.OneofDescriptor oneof)

TODO(jieluo): Clear it when all subclasses have implemented this method.

Parameter
NameDescription
oneofDescriptors.OneofDescriptor
Returns
TypeDescription
Descriptors.FieldDescriptor
Overrides

getRepeatedField(Descriptors.FieldDescriptor field, int index)

public Object getRepeatedField(Descriptors.FieldDescriptor field, int index)
Parameters
NameDescription
fieldDescriptors.FieldDescriptor
indexint
Returns
TypeDescription
Object

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.

Parameters
NameDescription
fieldDescriptors.FieldDescriptor
indexint
Returns
TypeDescription
Message.Builder
Overrides

getRepeatedFieldCount(Descriptors.FieldDescriptor field)

public int getRepeatedFieldCount(Descriptors.FieldDescriptor field)
Parameter
NameDescription
fieldDescriptors.FieldDescriptor
Returns
TypeDescription
int

getUnknownFields()

public UnknownFieldSet getUnknownFields()
Returns
TypeDescription
UnknownFieldSet

hasField(Descriptors.FieldDescriptor field)

public boolean hasField(Descriptors.FieldDescriptor field)
Parameter
NameDescription
fieldDescriptors.FieldDescriptor
Returns
TypeDescription
boolean

hasOneof(Descriptors.OneofDescriptor oneof)

public boolean hasOneof(Descriptors.OneofDescriptor oneof)

TODO(jieluo): Clear it when all subclasses have implemented this method.

Parameter
NameDescription
oneofDescriptors.OneofDescriptor
Returns
TypeDescription
boolean
Overrides

isInitialized()

public boolean isInitialized()
Returns
TypeDescription
boolean

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
NameDescription
otherMessage
Returns
TypeDescription
DynamicMessage.Builder
Overrides

mergeUnknownFields(UnknownFieldSet unknownFields)

public DynamicMessage.Builder mergeUnknownFields(UnknownFieldSet unknownFields)

Merge some unknown fields into the UnknownFieldSet for this message.

Parameter
NameDescription
unknownFieldsUnknownFieldSet
Returns
TypeDescription
DynamicMessage.Builder
Overrides

newBuilderForField(Descriptors.FieldDescriptor field)

public DynamicMessage.Builder newBuilderForField(Descriptors.FieldDescriptor field)
Parameter
NameDescription
fieldDescriptors.FieldDescriptor
Returns
TypeDescription
DynamicMessage.Builder

setField(Descriptors.FieldDescriptor field, Object value)

public DynamicMessage.Builder setField(Descriptors.FieldDescriptor field, Object value)
Parameters
NameDescription
fieldDescriptors.FieldDescriptor
valueObject
Returns
TypeDescription
DynamicMessage.Builder

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

public DynamicMessage.Builder setRepeatedField(Descriptors.FieldDescriptor field, int index, Object value)
Parameters
NameDescription
fieldDescriptors.FieldDescriptor
indexint
valueObject
Returns
TypeDescription
DynamicMessage.Builder

setUnknownFields(UnknownFieldSet unknownFields)

public DynamicMessage.Builder setUnknownFields(UnknownFieldSet unknownFields)
Parameter
NameDescription
unknownFieldsUnknownFieldSet
Returns
TypeDescription
DynamicMessage.Builder