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
Name Description
field Descriptors.FieldDescriptor
value Object
Returns
Type Description
DynamicMessage.Builder

build()

public DynamicMessage build()
Returns
Type Description
DynamicMessage

buildPartial()

public DynamicMessage buildPartial()
Returns
Type Description
DynamicMessage

clear()

public DynamicMessage.Builder clear()

Resets all fields to their default values.

Returns
Type Description
DynamicMessage.Builder
Overrides

clearField(Descriptors.FieldDescriptor field)

public DynamicMessage.Builder clearField(Descriptors.FieldDescriptor field)
Parameter
Name Description
field Descriptors.FieldDescriptor
Returns
Type Description
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
Name Description
oneof Descriptors.OneofDescriptor
Returns
Type Description
DynamicMessage.Builder
Overrides

clone()

public DynamicMessage.Builder clone()

Clones the Builder.

Returns
Type Description
DynamicMessage.Builder
Overrides

getAllFields()

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

getDefaultInstanceForType()

public DynamicMessage getDefaultInstanceForType()
Returns
Type Description
DynamicMessage

getDescriptorForType()

public Descriptors.Descriptor getDescriptorForType()
Returns
Type Description
Descriptors.Descriptor

getField(Descriptors.FieldDescriptor field)

public Object getField(Descriptors.FieldDescriptor field)
Parameter
Name Description
field Descriptors.FieldDescriptor
Returns
Type Description
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
Name Description
field Descriptors.FieldDescriptor
Returns
Type Description
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
Name Description
oneof Descriptors.OneofDescriptor
Returns
Type Description
Descriptors.FieldDescriptor
Overrides

getRepeatedField(Descriptors.FieldDescriptor field, int index)

public Object getRepeatedField(Descriptors.FieldDescriptor field, int index)
Parameters
Name Description
field Descriptors.FieldDescriptor
index int
Returns
Type Description
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
Name Description
field Descriptors.FieldDescriptor
index int
Returns
Type Description
Message.Builder
Overrides

getRepeatedFieldCount(Descriptors.FieldDescriptor field)

public int getRepeatedFieldCount(Descriptors.FieldDescriptor field)
Parameter
Name Description
field Descriptors.FieldDescriptor
Returns
Type Description
int

getUnknownFields()

public UnknownFieldSet getUnknownFields()
Returns
Type Description
UnknownFieldSet

hasField(Descriptors.FieldDescriptor field)

public boolean hasField(Descriptors.FieldDescriptor field)
Parameter
Name Description
field Descriptors.FieldDescriptor
Returns
Type Description
boolean

hasOneof(Descriptors.OneofDescriptor oneof)

public boolean hasOneof(Descriptors.OneofDescriptor oneof)

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

Parameter
Name Description
oneof Descriptors.OneofDescriptor
Returns
Type Description
boolean
Overrides

isInitialized()

public boolean isInitialized()
Returns
Type Description
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
Name Description
other Message
Returns
Type Description
DynamicMessage.Builder
Overrides

mergeUnknownFields(UnknownFieldSet unknownFields)

public DynamicMessage.Builder mergeUnknownFields(UnknownFieldSet unknownFields)

Merge some unknown fields into the UnknownFieldSet for this message.

Parameter
Name Description
unknownFields UnknownFieldSet
Returns
Type Description
DynamicMessage.Builder
Overrides

newBuilderForField(Descriptors.FieldDescriptor field)

public DynamicMessage.Builder newBuilderForField(Descriptors.FieldDescriptor field)
Parameter
Name Description
field Descriptors.FieldDescriptor
Returns
Type Description
DynamicMessage.Builder

setField(Descriptors.FieldDescriptor field, Object value)

public DynamicMessage.Builder setField(Descriptors.FieldDescriptor field, Object value)
Parameters
Name Description
field Descriptors.FieldDescriptor
value Object
Returns
Type Description
DynamicMessage.Builder

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

public DynamicMessage.Builder setRepeatedField(Descriptors.FieldDescriptor field, int index, Object value)
Parameters
Name Description
field Descriptors.FieldDescriptor
index int
value Object
Returns
Type Description
DynamicMessage.Builder

setUnknownFields(UnknownFieldSet unknownFields)

public DynamicMessage.Builder setUnknownFields(UnknownFieldSet unknownFields)
Parameter
Name Description
unknownFields UnknownFieldSet
Returns
Type Description
DynamicMessage.Builder