Class UnknownFieldSet.Builder
- java.lang.Object
-
- com.google.protobuf.UnknownFieldSet.Builder
-
- All Implemented Interfaces:
MessageLite.Builder,MessageLiteOrBuilder,java.lang.Cloneable
- Enclosing class:
- UnknownFieldSet
public static final class UnknownFieldSet.Builder extends java.lang.Object implements MessageLite.Builder
Builder forUnknownFieldSets.Note that this class maintains
UnknownFieldSet.Field.Builders for all fields in the set. Thus, adding one element to an existingUnknownFieldSet.Fielddoes not require making a copy. This is important for efficient parsing of unknown repeated fields. However, it implies thatUnknownFieldSet.Fields cannot be constructed independently, nor can twoUnknownFieldSets share the sameFieldobject.Use
UnknownFieldSet.newBuilder()to construct aBuilder.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description UnknownFieldSet.BuilderaddField(int number, UnknownFieldSet.Field field)Add a field to theUnknownFieldSet.java.util.Map<java.lang.Integer,UnknownFieldSet.Field>asMap()Get all presentFields as an immutableMap.UnknownFieldSetbuild()Build theUnknownFieldSetand return it.UnknownFieldSetbuildPartial()LikeMessageLite.Builder.build(), but does not throw an exception if the message is missing required fields.UnknownFieldSet.Builderclear()Reset the builder to an empty set.UnknownFieldSet.BuilderclearField(int number)Clear fields from the set with a given field number.UnknownFieldSet.Builderclone()Clones the Builder.UnknownFieldSetgetDefaultInstanceForType()Get an instance of the type with no fields set.booleanhasField(int number)Check if the given field number is present in the set.booleanisInitialized()Returns true if all required fields in the message and all embedded messages are set, false otherwise.booleanmergeDelimitedFrom(java.io.InputStream input)LikeMessageLite.Builder.mergeFrom(InputStream), but does not read until EOF.booleanmergeDelimitedFrom(java.io.InputStream input, ExtensionRegistryLite extensionRegistry)LikeMessageLite.Builder.mergeDelimitedFrom(InputStream)but supporting extensions.UnknownFieldSet.BuildermergeField(int number, UnknownFieldSet.Field field)Add a field to theUnknownFieldSet.booleanmergeFieldFrom(int tag, CodedInputStream input)Parse a single field frominputand merge it into this set.UnknownFieldSet.BuildermergeFrom(byte[] data)Parsedataas anUnknownFieldSetand merge it with the set being built.UnknownFieldSet.BuildermergeFrom(byte[] data, int off, int len)Parsedataas a message of this type and merge it with the message being built.UnknownFieldSet.BuildermergeFrom(byte[] data, int off, int len, ExtensionRegistryLite extensionRegistry)Parsedataas a message of this type and merge it with the message being built.UnknownFieldSet.BuildermergeFrom(byte[] data, ExtensionRegistryLite extensionRegistry)Parsedataas a message of this type and merge it with the message being built.UnknownFieldSet.BuildermergeFrom(ByteString data)Parsedataas anUnknownFieldSetand merge it with the set being built.UnknownFieldSet.BuildermergeFrom(ByteString data, ExtensionRegistryLite extensionRegistry)Parsedataas a message of this type and merge it with the message being built.UnknownFieldSet.BuildermergeFrom(CodedInputStream input)Parse an entire message frominputand merge its fields into this set.UnknownFieldSet.BuildermergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry)LikeMessageLite.Builder.mergeFrom(CodedInputStream), but also parses extensions.UnknownFieldSet.BuildermergeFrom(MessageLite m)Mergeotherinto the message being built.UnknownFieldSet.BuildermergeFrom(UnknownFieldSet other)Merge the fields fromotherinto this set.UnknownFieldSet.BuildermergeFrom(java.io.InputStream input)Parse anUnknownFieldSetfrominputand merge it with the set being built.UnknownFieldSet.BuildermergeFrom(java.io.InputStream input, ExtensionRegistryLite extensionRegistry)Parse a message of this type frominputand merge it with the message being built.UnknownFieldSet.BuildermergeLengthDelimitedField(int number, ByteString value)Convenience method for merging a length-delimited field.UnknownFieldSet.BuildermergeVarintField(int number, int value)Convenience method for merging a new field containing a single varint value.
-
-
-
Method Detail
-
build
public UnknownFieldSet build()
Build theUnknownFieldSetand return it.- Specified by:
buildin interfaceMessageLite.Builder
-
buildPartial
public UnknownFieldSet 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.- Specified by:
buildPartialin interfaceMessageLite.Builder
-
clone
public UnknownFieldSet.Builder clone()
Description copied from interface:MessageLite.BuilderClones the Builder.- Specified by:
clonein interfaceMessageLite.Builder- Overrides:
clonein classjava.lang.Object- See Also:
Object.clone()
-
getDefaultInstanceForType
public UnknownFieldSet 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.- Specified by:
getDefaultInstanceForTypein interfaceMessageLiteOrBuilder
-
clear
public UnknownFieldSet.Builder clear()
Reset the builder to an empty set.- Specified by:
clearin interfaceMessageLite.Builder
-
clearField
public UnknownFieldSet.Builder clearField(int number)
Clear fields from the set with a given field number.- Throws:
java.lang.IllegalArgumentException- if number is not positive
-
mergeFrom
public UnknownFieldSet.Builder mergeFrom(UnknownFieldSet other)
Merge the fields fromotherinto this set. If a field number exists in both sets,other's values for that field will be appended to the values in this set.
-
mergeField
public UnknownFieldSet.Builder mergeField(int number, UnknownFieldSet.Field field)
Add a field to theUnknownFieldSet. If a field with the same number already exists, the two are merged.- Throws:
java.lang.IllegalArgumentException- if number is not positive
-
mergeVarintField
public UnknownFieldSet.Builder mergeVarintField(int number, int value)
Convenience method for merging a new field containing a single varint value. This is used in particular when an unknown enum value is encountered.- Throws:
java.lang.IllegalArgumentException- if number is not positive
-
mergeLengthDelimitedField
public UnknownFieldSet.Builder mergeLengthDelimitedField(int number, ByteString value)
Convenience method for merging a length-delimited field.For use by generated code only.
- Throws:
java.lang.IllegalArgumentException- if number is not positive
-
hasField
public boolean hasField(int number)
Check if the given field number is present in the set.
-
addField
public UnknownFieldSet.Builder addField(int number, UnknownFieldSet.Field field)
Add a field to theUnknownFieldSet. If a field with the same number already exists, it is removed.- Throws:
java.lang.IllegalArgumentException- if number is not positive
-
asMap
public java.util.Map<java.lang.Integer,UnknownFieldSet.Field> asMap()
Get all presentFields as an immutableMap. If more fields are added, the changes may or may not be reflected in this map.
-
mergeFrom
public UnknownFieldSet.Builder mergeFrom(CodedInputStream input) throws java.io.IOException
Parse an entire message frominputand merge its fields into this set.- Specified by:
mergeFromin interfaceMessageLite.Builder- Throws:
InvalidProtocolBufferException- the bytes read are not syntactically correct according to the protobuf wire format specification. The data is corrupt, incomplete, or was never a protobuf in the first place.java.io.IOException- an I/O error reading from the stream
-
mergeFieldFrom
public boolean mergeFieldFrom(int tag, CodedInputStream input) throws java.io.IOExceptionParse a single field frominputand merge it into this set.- Parameters:
tag- The field's tag number, which was already parsed.- Returns:
falseif the tag is an end group tag.- Throws:
java.io.IOException
-
mergeFrom
public UnknownFieldSet.Builder mergeFrom(ByteString data) throws InvalidProtocolBufferException
Parsedataas anUnknownFieldSetand merge it with the set being built. This is just a small wrapper aroundmergeFrom(CodedInputStream).- Specified by:
mergeFromin interfaceMessageLite.Builder- Returns:
- this
- Throws:
InvalidProtocolBufferException- the bytes in data are not syntactically correct according to the protobuf wire format specification. The data is corrupt, incomplete, or was never a protobuf in the first place.
-
mergeFrom
public UnknownFieldSet.Builder mergeFrom(byte[] data) throws InvalidProtocolBufferException
Parsedataas anUnknownFieldSetand merge it with the set being built. This is just a small wrapper aroundmergeFrom(CodedInputStream).- Specified by:
mergeFromin interfaceMessageLite.Builder- Returns:
- this
- Throws:
InvalidProtocolBufferException- the bytes in data are not syntactically correct according to the protobuf wire format specification. The data is corrupt, incomplete, or was never a protobuf in the first place.
-
mergeFrom
public UnknownFieldSet.Builder mergeFrom(java.io.InputStream input) throws java.io.IOException
Parse anUnknownFieldSetfrominputand merge it with the set being built. This is just a small wrapper aroundmergeFrom(CodedInputStream).- Specified by:
mergeFromin interfaceMessageLite.Builder- Returns:
- this
- Throws:
InvalidProtocolBufferException- the bytes read are not syntactically correct according to the protobuf wire format specification. The data is corrupt, incomplete, or was never a protobuf in the first place.java.io.IOException- an I/O error reading from the stream
-
mergeDelimitedFrom
public boolean mergeDelimitedFrom(java.io.InputStream input) throws java.io.IOExceptionDescription copied from interface:MessageLite.BuilderLikeMessageLite.Builder.mergeFrom(InputStream), but does not read until EOF. Instead, the size of the message (encoded as a varint) is read first, then the message data. UseMessageLite.writeDelimitedTo(OutputStream)to write messages in this format.- Specified by:
mergeDelimitedFromin interfaceMessageLite.Builder- Returns:
- true if successful, or false if the stream is at EOF when the method starts. Any other error (including reaching EOF during parsing) causes an exception to be thrown.
- Throws:
InvalidProtocolBufferException- the bytes read are not syntactically correct according to the protobuf wire format specification. The data is corrupt, incomplete, or was never a protobuf in the first place.java.io.IOException- an I/O error reading from the stream
-
mergeDelimitedFrom
public boolean mergeDelimitedFrom(java.io.InputStream input, ExtensionRegistryLite extensionRegistry) throws java.io.IOExceptionDescription copied from interface:MessageLite.BuilderLikeMessageLite.Builder.mergeDelimitedFrom(InputStream)but supporting extensions.- Specified by:
mergeDelimitedFromin interfaceMessageLite.Builder- Returns:
- true if successful, or false if the stream is at EOF when the method starts. Any other error (including reaching EOF during parsing) causes an exception to be thrown.
- Throws:
InvalidProtocolBufferException- the bytes read are not syntactically correct according to the protobuf wire format specification. The data is corrupt, incomplete, or was never a protobuf in the first place.java.io.IOException- an I/O error reading from the stream
-
mergeFrom
public UnknownFieldSet.Builder mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws java.io.IOException
Description copied from interface:MessageLite.BuilderLikeMessageLite.Builder.mergeFrom(CodedInputStream), but also parses extensions. The extensions that you want to be able to parse must be registered inextensionRegistry. Extensions not in the registry will be treated as unknown fields.- Specified by:
mergeFromin interfaceMessageLite.Builder- Throws:
InvalidProtocolBufferException- the bytes read are not syntactically correct according to the protobuf wire format specification. The data is corrupt, incomplete, or was never a protobuf in the first place.java.io.IOException- an I/O error reading from the stream
-
mergeFrom
public UnknownFieldSet.Builder mergeFrom(ByteString data, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException
Description copied from interface:MessageLite.BuilderParsedataas a message of this type and merge it with the message being built. This is just a small wrapper aroundMessageLite.Builder.mergeFrom(CodedInputStream,ExtensionRegistryLite).- Specified by:
mergeFromin interfaceMessageLite.Builder- Returns:
- this
- Throws:
InvalidProtocolBufferException- the bytes in data are not syntactically correct according to the protobuf wire format specification. The data is corrupt, incomplete, or was never a protobuf in the first place.
-
mergeFrom
public UnknownFieldSet.Builder mergeFrom(byte[] data, int off, int len) throws InvalidProtocolBufferException
Description copied from interface:MessageLite.BuilderParsedataas a message of this type and merge it with the message being built. This is just a small wrapper aroundMessageLite.Builder.mergeFrom(CodedInputStream).- Specified by:
mergeFromin interfaceMessageLite.Builder- Returns:
- this
- Throws:
InvalidProtocolBufferException- the bytes in data are not syntactically correct according to the protobuf wire format specification. The data is corrupt, incomplete, or was never a protobuf in the first place.
-
mergeFrom
public UnknownFieldSet.Builder mergeFrom(byte[] data, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException
Description copied from interface:MessageLite.BuilderParsedataas a message of this type and merge it with the message being built. This is just a small wrapper aroundMessageLite.Builder.mergeFrom(CodedInputStream,ExtensionRegistryLite).- Specified by:
mergeFromin interfaceMessageLite.Builder- Returns:
- this
- Throws:
InvalidProtocolBufferException- the bytes in data are not syntactically correct according to the protobuf wire format specification. The data is corrupt, incomplete, or was never a protobuf in the first place.
-
mergeFrom
public UnknownFieldSet.Builder mergeFrom(byte[] data, int off, int len, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException
Description copied from interface:MessageLite.BuilderParsedataas a message of this type and merge it with the message being built. This is just a small wrapper aroundMessageLite.Builder.mergeFrom(CodedInputStream,ExtensionRegistryLite).- Specified by:
mergeFromin interfaceMessageLite.Builder- Returns:
- this
- Throws:
InvalidProtocolBufferException- the bytes in data are not syntactically correct according to the protobuf wire format specification. The data is corrupt, incomplete, or was never a protobuf in the first place.
-
mergeFrom
public UnknownFieldSet.Builder mergeFrom(java.io.InputStream input, ExtensionRegistryLite extensionRegistry) throws java.io.IOException
Description copied from interface:MessageLite.BuilderParse a message of this type frominputand merge it with the message being built. This is just a small wrapper aroundMessageLite.Builder.mergeFrom(CodedInputStream,ExtensionRegistryLite).- Specified by:
mergeFromin interfaceMessageLite.Builder- Returns:
- this
- Throws:
java.io.IOException
-
mergeFrom
public UnknownFieldSet.Builder mergeFrom(MessageLite m)
Description copied from interface:MessageLite.BuilderMergeotherinto the message being built.othermust have the exact same type asthis(i.e.getClass().equals(getDefaultInstanceForType().getClass())).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. * 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::MergeFrommethod in C++.- Specified by:
mergeFromin interfaceMessageLite.Builder
-
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.- Specified by:
isInitializedin interfaceMessageLiteOrBuilder
-
-