Class UnknownFieldSet.Builder
- All Implemented Interfaces:
MessageLite.Builder
,MessageLiteOrBuilder
,Cloneable
- Enclosing class:
UnknownFieldSet
UnknownFieldSet
s.
Note that this class maintains UnknownFieldSet.Field.Builder
s for all fields in the set. Thus,
adding one element to an existing UnknownFieldSet.Field
does not require making a copy. This is
important for efficient parsing of unknown repeated fields. However, it implies that UnknownFieldSet.Field
s cannot be constructed independently, nor can two UnknownFieldSet
s share the
same Field
object.
Use UnknownFieldSet.newBuilder()
to construct a Builder
.
-
Method Summary
Modifier and TypeMethodDescriptionaddField
(int number, UnknownFieldSet.Field field) Add a field to theUnknownFieldSet
.asMap()
Get all presentField
s as an immutableMap
.build()
Build theUnknownFieldSet
and return it.LikeMessageLite.Builder.build()
, but does not throw an exception if the message is missing required fields.clear()
Reset the builder to an empty set.clearField
(int number) Clear fields from the set with a given field number.clone()
Clones the Builder.Get an instance of the type with no fields set.boolean
hasField
(int number) Check if the given field number is present in the set.boolean
Returns true if all required fields in the message and all embedded messages are set, false otherwise.boolean
mergeDelimitedFrom
(InputStream input) LikeMessageLite.Builder.mergeFrom(InputStream)
, but does not read until EOF.boolean
mergeDelimitedFrom
(InputStream input, ExtensionRegistryLite extensionRegistry) LikeMessageLite.Builder.mergeDelimitedFrom(InputStream)
but supporting extensions.mergeField
(int number, UnknownFieldSet.Field field) Add a field to theUnknownFieldSet
.boolean
mergeFieldFrom
(int tag, CodedInputStream input) Parse a single field frominput
and merge it into this set.mergeFrom
(byte[] data) Parsedata
as anUnknownFieldSet
and merge it with the set being built.mergeFrom
(byte[] data, int off, int len) Parsedata
as a message of this type and merge it with the message being built.mergeFrom
(byte[] data, int off, int len, ExtensionRegistryLite extensionRegistry) Parsedata
as a message of this type and merge it with the message being built.mergeFrom
(byte[] data, ExtensionRegistryLite extensionRegistry) Parsedata
as a message of this type and merge it with the message being built.mergeFrom
(ByteString data) Parsedata
as anUnknownFieldSet
and merge it with the set being built.mergeFrom
(ByteString data, ExtensionRegistryLite extensionRegistry) Parsedata
as a message of this type and merge it with the message being built.mergeFrom
(CodedInputStream input) Parse an entire message frominput
and merge its fields into this set.mergeFrom
(CodedInputStream input, ExtensionRegistryLite extensionRegistry) LikeMessageLite.Builder.mergeFrom(CodedInputStream)
, but also parses extensions.Mergeother
into the message being built.mergeFrom
(UnknownFieldSet other) Merge the fields fromother
into this set.mergeFrom
(InputStream input) Parse anUnknownFieldSet
frominput
and merge it with the set being built.mergeFrom
(InputStream input, ExtensionRegistryLite extensionRegistry) Parse a message of this type frominput
and merge it with the message being built.mergeLengthDelimitedField
(int number, ByteString value) Convenience method for merging a length-delimited field.mergeVarintField
(int number, int value) Convenience method for merging a new field containing a single varint value.
-
Method Details
-
build
Build theUnknownFieldSet
and return it.- Specified by:
build
in interfaceMessageLite.Builder
-
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.- Specified by:
buildPartial
in interfaceMessageLite.Builder
-
clone
Description copied from interface:MessageLite.Builder
Clones the Builder.- Specified by:
clone
in interfaceMessageLite.Builder
- Overrides:
clone
in classObject
- See Also:
-
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.- Specified by:
getDefaultInstanceForType
in interfaceMessageLiteOrBuilder
-
clear
Reset the builder to an empty set.- Specified by:
clear
in interfaceMessageLite.Builder
-
clearField
Clear fields from the set with a given field number.- Throws:
IllegalArgumentException
- if number is not positive
-
mergeFrom
Merge the fields fromother
into 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
Add a field to theUnknownFieldSet
. If a field with the same number already exists, the two are merged.- Throws:
IllegalArgumentException
- if number is not positive
-
mergeVarintField
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:
IllegalArgumentException
- if number is not positive
-
mergeLengthDelimitedField
Convenience method for merging a length-delimited field.For use by generated code only.
- Throws:
IllegalArgumentException
- if number is not positive
-
hasField
public boolean hasField(int number) Check if the given field number is present in the set. -
addField
Add a field to theUnknownFieldSet
. If a field with the same number already exists, it is removed.- Throws:
IllegalArgumentException
- if number is not positive
-
asMap
Get all presentField
s as an immutableMap
. If more fields are added, the changes may or may not be reflected in this map. -
mergeFrom
Parse an entire message frominput
and merge its fields into this set.- Specified by:
mergeFrom
in interfaceMessageLite.Builder
- Throws:
IOException
- an I/O error reading from the stream
-
mergeFieldFrom
Parse a single field frominput
and merge it into this set.- Parameters:
tag
- The field's tag number, which was already parsed.- Returns:
false
if the tag is an end group tag.- Throws:
IOException
-
mergeFrom
Parsedata
as anUnknownFieldSet
and merge it with the set being built. This is just a small wrapper aroundmergeFrom(CodedInputStream)
.- Specified by:
mergeFrom
in 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
Parsedata
as anUnknownFieldSet
and merge it with the set being built. This is just a small wrapper aroundmergeFrom(CodedInputStream)
.- Specified by:
mergeFrom
in 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
Parse anUnknownFieldSet
frominput
and merge it with the set being built. This is just a small wrapper aroundmergeFrom(CodedInputStream)
.- Specified by:
mergeFrom
in interfaceMessageLite.Builder
- Returns:
- this
- Throws:
IOException
- an I/O error reading from the stream
-
mergeDelimitedFrom
Description copied from interface:MessageLite.Builder
LikeMessageLite.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:
mergeDelimitedFrom
in 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:
IOException
- an I/O error reading from the stream
-
mergeDelimitedFrom
public boolean mergeDelimitedFrom(InputStream input, ExtensionRegistryLite extensionRegistry) throws IOException Description copied from interface:MessageLite.Builder
LikeMessageLite.Builder.mergeDelimitedFrom(InputStream)
but supporting extensions.- Specified by:
mergeDelimitedFrom
in 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:
IOException
- an I/O error reading from the stream
-
mergeFrom
public UnknownFieldSet.Builder mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws IOException Description copied from interface:MessageLite.Builder
LikeMessageLite.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:
mergeFrom
in interfaceMessageLite.Builder
- Throws:
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.Builder
Parsedata
as 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:
mergeFrom
in 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.Builder
Parsedata
as 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:
mergeFrom
in 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.Builder
Parsedata
as 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:
mergeFrom
in 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.Builder
Parsedata
as 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:
mergeFrom
in 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(InputStream input, ExtensionRegistryLite extensionRegistry) throws IOException Description copied from interface:MessageLite.Builder
Parse a message of this type frominput
and merge it with the message being built. This is just a small wrapper aroundMessageLite.Builder.mergeFrom(CodedInputStream,ExtensionRegistryLite)
.- Specified by:
mergeFrom
in interfaceMessageLite.Builder
- Returns:
- this
- Throws:
IOException
-
mergeFrom
Description copied from interface:MessageLite.Builder
Mergeother
into the message being built.other
must 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 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 interfaceMessageLite.Builder
-
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.- Specified by:
isInitialized
in interfaceMessageLiteOrBuilder
-