Class DynamicMessage.Builder
- java.lang.Object
-
- com.google.protobuf.AbstractMessageLite.Builder
-
- com.google.protobuf.AbstractMessage.Builder<DynamicMessage.Builder>
-
- com.google.protobuf.DynamicMessage.Builder
-
- All Implemented Interfaces:
Message.Builder
,MessageLite.Builder
,MessageLiteOrBuilder
,MessageOrBuilder
,java.lang.Cloneable
- Enclosing class:
- DynamicMessage
public static final class DynamicMessage.Builder extends AbstractMessage.Builder<DynamicMessage.Builder>
Builder forDynamicMessage
s.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DynamicMessage.Builder
addRepeatedField(Descriptors.FieldDescriptor field, java.lang.Object value)
LikesetRepeatedField
, but appends the value as a new element.DynamicMessage
build()
Constructs the message based on the state of the Builder.DynamicMessage
buildPartial()
LikeMessageLite.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
clearOneof(Descriptors.OneofDescriptor oneof)
TODO(jieluo): Clear it when all subclasses have implemented this method.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.Descriptors.FieldDescriptor
getOneofFieldDescriptor(Descriptors.OneofDescriptor oneof)
TODO(jieluo): Clear it when all subclasses have implemented this method.java.lang.Object
getRepeatedField(Descriptors.FieldDescriptor field, int index)
Gets an element of a repeated field.Message.Builder
getRepeatedFieldBuilder(Descriptors.FieldDescriptor field, int index)
Get a nested builder instance for the given repeated field instance.int
getRepeatedFieldCount(Descriptors.FieldDescriptor field)
Gets the number of elements of a repeated field.UnknownFieldSet
getUnknownFields()
Get theUnknownFieldSet
for this message.boolean
hasField(Descriptors.FieldDescriptor field)
Returns true if the given field is set.boolean
hasOneof(Descriptors.OneofDescriptor oneof)
TODO(jieluo): Clear it when all subclasses have implemented this method.boolean
isInitialized()
Returns true if all required fields in the message and all embedded messages are set, false otherwise.DynamicMessage.Builder
mergeFrom(Message other)
Mergeother
into the message being built.DynamicMessage.Builder
mergeUnknownFields(UnknownFieldSet unknownFields)
Merge some unknown fields into theUnknownFieldSet
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 theUnknownFieldSet
for this message.-
Methods inherited from class com.google.protobuf.AbstractMessage.Builder
findInitializationErrors, getInitializationErrorString, getUnknownFieldSetBuilder, internalMergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, newUninitializedMessageException, setUnknownFieldSetBuilder, toString
-
Methods inherited from class com.google.protobuf.AbstractMessageLite.Builder
addAll, addAll, mergeDelimitedFrom, mergeDelimitedFrom, mergeFrom, newUninitializedMessageException
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.google.protobuf.Message.Builder
mergeDelimitedFrom, mergeDelimitedFrom
-
Methods inherited from interface com.google.protobuf.MessageLite.Builder
mergeFrom
-
-
-
-
Method Detail
-
clear
public DynamicMessage.Builder clear()
Description copied from interface:MessageLite.Builder
Resets all fields to their default values.- Specified by:
clear
in interfaceMessage.Builder
- Specified by:
clear
in interfaceMessageLite.Builder
- Overrides:
clear
in classAbstractMessage.Builder<DynamicMessage.Builder>
-
mergeFrom
public DynamicMessage.Builder mergeFrom(Message other)
Description copied from interface:Message.Builder
Mergeother
into the message being built.other
must have the exact same type asthis
(i.e.getDescriptorForType() == other.getDescriptorForType()
).Merging occurs as follows. For each field:
* For singular primitive fields, if the field is set inother
, thenother
's value overwrites the value in this message.
* For singular message fields, if the field is set inother
, it is merged into the corresponding sub-message of this message using the same merging rules.
* For repeated fields, the elements inother
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++.- Specified by:
mergeFrom
in interfaceMessage.Builder
- Overrides:
mergeFrom
in classAbstractMessage.Builder<DynamicMessage.Builder>
-
build
public DynamicMessage build()
Description copied from interface:MessageLite.Builder
Constructs the message based on the state of the Builder. Subsequent changes to the Builder will not affect the returned message.
-
buildPartial
public DynamicMessage buildPartial()
Description copied from interface:MessageLite.Builder
LikeMessageLite.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.
-
clone
public DynamicMessage.Builder clone()
Description copied from interface:MessageLite.Builder
Clones the Builder.- Specified by:
clone
in interfaceMessage.Builder
- Specified by:
clone
in interfaceMessageLite.Builder
- Overrides:
clone
in classAbstractMessage.Builder<DynamicMessage.Builder>
- See Also:
Object.clone()
-
isInitialized
public boolean isInitialized()
Description copied from interface:MessageLiteOrBuilder
Returns true if all required fields in the message and all embedded messages are set, false otherwise.
-
getDescriptorForType
public Descriptors.Descriptor getDescriptorForType()
Description copied from interface:Message.Builder
Get the message's type's descriptor. SeeMessageOrBuilder.getDescriptorForType()
.
-
getDefaultInstanceForType
public DynamicMessage getDefaultInstanceForType()
Description copied from interface:MessageLiteOrBuilder
Get an instance of the type with no fields set. Because no fields are set, all getters for singular fields will return default values and repeated fields will appear empty. This may or may not be a singleton. This differs from thegetDefaultInstance()
method of generated message classes in that this method is an abstract method of theMessageLite
interface whereasgetDefaultInstance()
is a static method of a specific class. They return the same thing.
-
getAllFields
public java.util.Map<Descriptors.FieldDescriptor,java.lang.Object> getAllFields()
Description copied from interface:MessageOrBuilder
Returns a collection of all the fields in this message which are set and their corresponding values. A singular ("required" or "optional") field is set iff hasField() returns true for that field. A "repeated" field is set iff getRepeatedFieldCount() is greater than zero. The values are exactly what would be returned by callingMessageOrBuilder.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.
If this is for a builder, the returned map may or may not reflect future changes to the builder. Either way, the returned map is itself unmodifiable.
-
newBuilderForField
public DynamicMessage.Builder newBuilderForField(Descriptors.FieldDescriptor field)
Description copied from interface:Message.Builder
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 theMessage.Builder.setField(Descriptors.FieldDescriptor, Object)
,Message.Builder.setRepeatedField(Descriptors.FieldDescriptor, int, Object)
, orMessage.Builder.addRepeatedField(Descriptors.FieldDescriptor, Object)
method of the current builder.To obtain a builder nested in the current builder, use
Message.Builder.getFieldBuilder(Descriptors.FieldDescriptor)
instead.
-
hasOneof
public boolean hasOneof(Descriptors.OneofDescriptor oneof)
Description copied from class:AbstractMessage.Builder
TODO(jieluo): Clear it when all subclasses have implemented this method.- Specified by:
hasOneof
in interfaceMessageOrBuilder
- Overrides:
hasOneof
in classAbstractMessage.Builder<DynamicMessage.Builder>
-
getOneofFieldDescriptor
public Descriptors.FieldDescriptor getOneofFieldDescriptor(Descriptors.OneofDescriptor oneof)
Description copied from class:AbstractMessage.Builder
TODO(jieluo): Clear it when all subclasses have implemented this method.- Specified by:
getOneofFieldDescriptor
in interfaceMessageOrBuilder
- Overrides:
getOneofFieldDescriptor
in classAbstractMessage.Builder<DynamicMessage.Builder>
-
clearOneof
public DynamicMessage.Builder clearOneof(Descriptors.OneofDescriptor oneof)
Description copied from class:AbstractMessage.Builder
TODO(jieluo): Clear it when all subclasses have implemented this method.- Specified by:
clearOneof
in interfaceMessage.Builder
- Overrides:
clearOneof
in classAbstractMessage.Builder<DynamicMessage.Builder>
-
hasField
public boolean hasField(Descriptors.FieldDescriptor field)
Description copied from interface:MessageOrBuilder
Returns true if the given field is set. This is exactly equivalent to calling the generated "has" accessor method corresponding to the field. The return value of hasField() is semantically meaningful only for fields where field.hasPresence() == true.
-
getField
public java.lang.Object getField(Descriptors.FieldDescriptor field)
Description copied from interface:MessageOrBuilder
Obtains the value of the given field, or the default value if it is not set. For primitive fields, the boxed primitive value is returned. For enum fields, the EnumValueDescriptor for the value is returned. For embedded message fields, the sub-message is returned. For repeated fields, a java.util.List is returned.
-
setField
public DynamicMessage.Builder setField(Descriptors.FieldDescriptor field, java.lang.Object value)
Description copied from interface:Message.Builder
Sets a field to the given value. The value must be of the correct type for this field, that is, the same type thatMessageOrBuilder.getField(Descriptors.FieldDescriptor)
returns.
-
clearField
public DynamicMessage.Builder clearField(Descriptors.FieldDescriptor field)
Description copied from interface:Message.Builder
Clears the field. This is exactly equivalent to calling the generated "clear" accessor method corresponding to the field.
-
getRepeatedFieldCount
public int getRepeatedFieldCount(Descriptors.FieldDescriptor field)
Description copied from interface:MessageOrBuilder
Gets the number of elements of a repeated field. This is exactly equivalent to calling the generated "Count" accessor method corresponding to the field.
-
getRepeatedField
public java.lang.Object getRepeatedField(Descriptors.FieldDescriptor field, int index)
Description copied from interface:MessageOrBuilder
Gets an element of a repeated field. For primitive fields, the boxed primitive value is returned. For enum fields, the EnumValueDescriptor for the value is returned. For embedded message fields, the sub-message is returned.
-
setRepeatedField
public DynamicMessage.Builder setRepeatedField(Descriptors.FieldDescriptor field, int index, java.lang.Object value)
Description copied from interface:Message.Builder
Sets an element of a repeated field to the given value. The value must be of the correct type for this field; that is, the same type thatMessageOrBuilder.getRepeatedField(Descriptors.FieldDescriptor,int)
returns.
-
addRepeatedField
public DynamicMessage.Builder addRepeatedField(Descriptors.FieldDescriptor field, java.lang.Object value)
Description copied from interface:Message.Builder
LikesetRepeatedField
, but appends the value as a new element.
-
getUnknownFields
public UnknownFieldSet getUnknownFields()
Description copied from interface:MessageOrBuilder
Get theUnknownFieldSet
for this message.
-
setUnknownFields
public DynamicMessage.Builder setUnknownFields(UnknownFieldSet unknownFields)
Description copied from interface:Message.Builder
Set theUnknownFieldSet
for this message.
-
mergeUnknownFields
public DynamicMessage.Builder mergeUnknownFields(UnknownFieldSet unknownFields)
Description copied from interface:Message.Builder
Merge some unknown fields into theUnknownFieldSet
for this message.- Specified by:
mergeUnknownFields
in interfaceMessage.Builder
- Overrides:
mergeUnknownFields
in classAbstractMessage.Builder<DynamicMessage.Builder>
-
getFieldBuilder
public Message.Builder getFieldBuilder(Descriptors.FieldDescriptor field)
Description copied from interface:Message.Builder
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) 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 is returned. Otherwise, a new field builder is created and returned. The original message field (if one exists) is merged into the field builder, which is then nested into its parent builder.
- Specified by:
getFieldBuilder
in interfaceMessage.Builder
- Overrides:
getFieldBuilder
in classAbstractMessage.Builder<DynamicMessage.Builder>
-
getRepeatedFieldBuilder
public Message.Builder getRepeatedFieldBuilder(Descriptors.FieldDescriptor field, int index)
Description copied from interface:Message.Builder
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) 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 is returned. Otherwise, a new field builder is created and returned. The original message field (if one exists) is merged into the field builder, which is then nested into its parent builder.
- Specified by:
getRepeatedFieldBuilder
in interfaceMessage.Builder
- Overrides:
getRepeatedFieldBuilder
in classAbstractMessage.Builder<DynamicMessage.Builder>
-
-