Package com.google.protobuf
Class DynamicMessage.Builder
java.lang.Object
com.google.protobuf.AbstractMessageLite.Builder<BuilderType>
com.google.protobuf.AbstractMessage.Builder<DynamicMessage.Builder>
com.google.protobuf.DynamicMessage.Builder
- All Implemented Interfaces:
Message.Builder,MessageLite.Builder,MessageLiteOrBuilder,MessageOrBuilder,Cloneable
- Enclosing class:
- DynamicMessage
public static final class DynamicMessage.Builder
extends AbstractMessage.Builder<DynamicMessage.Builder>
Builder for
DynamicMessages.-
Method Summary
Modifier and TypeMethodDescriptionaddRepeatedField(Descriptors.FieldDescriptor field, Object value) LikesetRepeatedField, but appends the value as a new element.build()Constructs the message based on the state of the Builder.LikeMessageLite.Builder.build(), but does not throw an exception if the message is missing required fields.clear()Resets all fields to their default values.Clears the field.TODO(jieluo): Clear it when all subclasses have implemented this method.clone()Clones the Builder.Returns a collection of all the fields in this message which are set and their corresponding values.Get an instance of the type with no fields set.Get the message's type's descriptor.Obtains the value of the given field, or the default value if it is not set.Get a nested builder instance for the given field.TODO(jieluo): Clear it when all subclasses have implemented this method.getRepeatedField(Descriptors.FieldDescriptor field, int index) Gets an element of a repeated field.intGets the number of elements of a repeated field.Get theUnknownFieldSetfor this message.booleanReturns true if the given field is set.booleanTODO(jieluo): Clear it when all subclasses have implemented this method.booleanReturns true if all required fields in the message and all embedded messages are set, false otherwise.Mergeotherinto the message being built.mergeUnknownFields(UnknownFieldSet unknownFields) Merge some unknown fields into theUnknownFieldSetfor this message.Create a Builder for messages of the appropriate type for the given field.setField(Descriptors.FieldDescriptor field, Object value) Sets a field to the given value.setRepeatedField(Descriptors.FieldDescriptor field, int index, Object value) Sets an element of a repeated field to the given value.setUnknownFields(UnknownFieldSet unknownFields) Set theUnknownFieldSetfor this message.Methods inherited from class com.google.protobuf.AbstractMessage.Builder
findInitializationErrors, getInitializationErrorString, mergeDelimitedFrom, mergeDelimitedFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, newUninitializedMessageException, toStringMethods inherited from class com.google.protobuf.AbstractMessageLite.Builder
addAll, newUninitializedMessageException
-
Method Details
-
clear
Description copied from interface:MessageLite.BuilderResets all fields to their default values.- Specified by:
clearin interfaceMessage.Builder- Specified by:
clearin interfaceMessageLite.Builder- Overrides:
clearin classAbstractMessage.Builder<DynamicMessage.Builder>
-
mergeFrom
Description copied from interface:Message.BuilderMergeotherinto the message being built.othermust 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 inotherare concatenated with the elements in this message. This is equivalent to theMessage::MergeFrommethod in C++.- Specified by:
mergeFromin interfaceMessage.Builder- Overrides:
mergeFromin classAbstractMessage.Builder<DynamicMessage.Builder>
-
build
Description copied from interface:MessageLite.BuilderConstructs the message based on the state of the Builder. Subsequent changes to the Builder will not affect the returned message. -
buildPartial
Description copied from interface:MessageLite.BuilderLikeMessageLite.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
Description copied from interface:MessageLite.BuilderClones the Builder.- Specified by:
clonein interfaceMessage.Builder- Specified by:
clonein interfaceMessageLite.Builder- Specified by:
clonein classAbstractMessage.Builder<DynamicMessage.Builder>- See Also:
-
isInitialized
public boolean isInitialized()Description copied from interface:MessageLiteOrBuilderReturns true if all required fields in the message and all embedded messages are set, false otherwise. -
getDescriptorForType
Description copied from interface:Message.BuilderGet the message's type's descriptor. SeeMessageOrBuilder.getDescriptorForType(). -
getDefaultInstanceForType
Description copied from interface:MessageLiteOrBuilderGet 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 theMessageLiteinterface whereasgetDefaultInstance()is a static method of a specific class. They return the same thing. -
getAllFields
Description copied from interface:MessageOrBuilderReturns 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
Description copied from interface:Message.BuilderCreate a Builder for messages of the appropriate type for the given field. Messages built with this can then be passed to setField(), setRepeatedField(), or addRepeatedField(). -
hasOneof
Description copied from class:AbstractMessage.BuilderTODO(jieluo): Clear it when all subclasses have implemented this method.- Specified by:
hasOneofin interfaceMessageOrBuilder- Overrides:
hasOneofin classAbstractMessage.Builder<DynamicMessage.Builder>
-
getOneofFieldDescriptor
Description copied from class:AbstractMessage.BuilderTODO(jieluo): Clear it when all subclasses have implemented this method.- Specified by:
getOneofFieldDescriptorin interfaceMessageOrBuilder- Overrides:
getOneofFieldDescriptorin classAbstractMessage.Builder<DynamicMessage.Builder>
-
clearOneof
Description copied from class:AbstractMessage.BuilderTODO(jieluo): Clear it when all subclasses have implemented this method.- Specified by:
clearOneofin interfaceMessage.Builder- Overrides:
clearOneofin classAbstractMessage.Builder<DynamicMessage.Builder>
-
hasField
Description copied from interface:MessageOrBuilderReturns true if the given field is set. This is exactly equivalent to calling the generated "has" accessor method corresponding to the field. -
getField
Description copied from interface:MessageOrBuilderObtains 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
Description copied from interface:Message.BuilderSets a field to the given value. The value must be of the correct type for this field, i.e. the same type thatMessageOrBuilder.getField(Descriptors.FieldDescriptor)would return. -
clearField
Description copied from interface:Message.BuilderClears the field. This is exactly equivalent to calling the generated "clear" accessor method corresponding to the field. -
getRepeatedFieldCount
Description copied from interface:MessageOrBuilderGets the number of elements of a repeated field. This is exactly equivalent to calling the generated "Count" accessor method corresponding to the field. -
getRepeatedField
Description copied from interface:MessageOrBuilderGets 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, Object value) Description copied from interface:Message.BuilderSets an element of a repeated field to the given value. The value must be of the correct type for this field, i.e. the same type thatMessageOrBuilder.getRepeatedField(Descriptors.FieldDescriptor,int)would return. -
addRepeatedField
Description copied from interface:Message.BuilderLikesetRepeatedField, but appends the value as a new element. -
getUnknownFields
Description copied from interface:MessageOrBuilderGet theUnknownFieldSetfor this message. -
setUnknownFields
Description copied from interface:Message.BuilderSet theUnknownFieldSetfor this message. -
mergeUnknownFields
Description copied from interface:Message.BuilderMerge some unknown fields into theUnknownFieldSetfor this message.- Specified by:
mergeUnknownFieldsin interfaceMessage.Builder- Overrides:
mergeUnknownFieldsin classAbstractMessage.Builder<DynamicMessage.Builder>
-
getFieldBuilder
Description copied from interface:Message.BuilderGet 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
UnsupportedException.- Specified by:
getFieldBuilderin interfaceMessage.Builder- Overrides:
getFieldBuilderin classAbstractMessage.Builder<DynamicMessage.Builder>
-