public static final class UnknownFieldSet.Builder implements MessageLite.Builder
Builder for UnknownFieldSets.
Note that this class maintains Field.Builders for all fields in the set. Thus,
adding one element to an existing Field does not require making a copy. This is
important for efficient parsing of unknown repeated fields. However, it implies that Fields cannot be constructed independently, nor can two UnknownFieldSets share the
same Field
object.
Use UnknownFieldSet#newBuilder() to construct a Builder
.
Methods
addField(int number, UnknownFieldSet.Field field)
public UnknownFieldSet.Builder addField(int number, UnknownFieldSet.Field field)
Add a field to the UnknownFieldSet
. If a field with the same number already exists,
it is removed.
asMap()
public Map<Integer,UnknownFieldSet.Field> asMap()
Get all present Field
s as an immutable Map
. If more fields are added, the
changes may or may not be reflected in this map.
build()
public UnknownFieldSet build()
buildPartial()
public UnknownFieldSet buildPartial()
Like #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.
clear()
public UnknownFieldSet.Builder clear()
Reset the builder to an empty set.
clearField(int number)
public UnknownFieldSet.Builder clearField(int number)
Clear fields from the set with a given field number.
Parameter |
Name |
Description |
number |
int
|
clone()
public UnknownFieldSet.Builder clone()
Overrides
getDefaultInstanceForType()
public UnknownFieldSet getDefaultInstanceForType()
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 the getDefaultInstance()
method of generated
message classes in that this method is an abstract method of the MessageLite
interface
whereas getDefaultInstance()
is a static method of a specific class. They return the
same thing.
hasField(int number)
public boolean hasField(int number)
Check if the given field number is present in the set.
Parameter |
Name |
Description |
number |
int
|
isInitialized()
public boolean isInitialized()
public boolean mergeDelimitedFrom(InputStream input)
public boolean mergeDelimitedFrom(InputStream input, ExtensionRegistryLite extensionRegistry)
mergeField(int number, UnknownFieldSet.Field field)
public UnknownFieldSet.Builder mergeField(int number, UnknownFieldSet.Field field)
Add a field to the UnknownFieldSet
. If a field with the same number already exists,
the two are merged.
public boolean mergeFieldFrom(int tag, CodedInputStream input)
Parse a single field from input
and merge it into this set.
Parameters |
Name |
Description |
tag |
int
The field's tag number, which was already parsed.
|
input |
CodedInputStream
|
Returns |
Type |
Description |
boolean |
false if the tag is an end group tag.
|
mergeFrom(byte[] data)
public UnknownFieldSet.Builder mergeFrom(byte[] data)
Parameter |
Name |
Description |
data |
byte[]
|
mergeFrom(byte[] data, ExtensionRegistryLite extensionRegistry)
public UnknownFieldSet.Builder mergeFrom(byte[] data, ExtensionRegistryLite extensionRegistry)
mergeFrom(byte[] data, int off, int len)
public UnknownFieldSet.Builder mergeFrom(byte[] data, int off, int len)
Parse data
as a message of this type and merge it with the message being built. This
is just a small wrapper around #mergeFrom(CodedInputStream).
Parameters |
Name |
Description |
data |
byte[]
|
off |
int
|
len |
int
|
mergeFrom(byte[] data, int off, int len, ExtensionRegistryLite extensionRegistry)
public UnknownFieldSet.Builder mergeFrom(byte[] data, int off, int len, ExtensionRegistryLite extensionRegistry)
mergeFrom(ByteString data)
public UnknownFieldSet.Builder mergeFrom(ByteString data)
mergeFrom(ByteString data, ExtensionRegistryLite extensionRegistry)
public UnknownFieldSet.Builder mergeFrom(ByteString data, ExtensionRegistryLite extensionRegistry)
public UnknownFieldSet.Builder mergeFrom(CodedInputStream input)
Parse an entire message from input
and merge its fields into this set.
public UnknownFieldSet.Builder mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry)
Like Builder#mergeFrom(CodedInputStream), but also parses extensions. The extensions
that you want to be able to parse must be registered in extensionRegistry
. Extensions
not in the registry will be treated as unknown fields.
mergeFrom(MessageLite m)
public UnknownFieldSet.Builder mergeFrom(MessageLite m)
Merge other
into the message being built. other
must have the exact same type
as this
(i.e. getClass().equals(getDefaultInstanceForType().getClass())
).
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++.
mergeFrom(UnknownFieldSet other)
public UnknownFieldSet.Builder mergeFrom(UnknownFieldSet other)
Merge the fields from other
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.
public UnknownFieldSet.Builder mergeFrom(InputStream input)
Parse an UnknownFieldSet
from input
and merge it with the set being built.
This is just a small wrapper around #mergeFrom(CodedInputStream).
public UnknownFieldSet.Builder mergeFrom(InputStream input, ExtensionRegistryLite extensionRegistry)
mergeLengthDelimitedField(int number, ByteString value)
public UnknownFieldSet.Builder mergeLengthDelimitedField(int number, ByteString value)
Convenience method for merging a length-delimited field.
For use by generated code only.
mergeVarintField(int number, int value)
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.
Parameters |
Name |
Description |
number |
int
|
value |
int
|