Class UnknownFieldSet.Builder

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.

Inheritance

java.lang.Object > UnknownFieldSet.Builder

Implements

MessageLite.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.

Parameters
NameDescription
numberint
fieldUnknownFieldSet.Field
Returns
TypeDescription
UnknownFieldSet.Builder

asMap()

public Map<Integer,UnknownFieldSet.Field> asMap()

Get all present Fields as an immutable Map. If more fields are added, the changes may or may not be reflected in this map.

Returns
TypeDescription
Map<Integer,Field>

build()

public UnknownFieldSet build()

Build the UnknownFieldSet and return it.

Returns
TypeDescription
UnknownFieldSet

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.

Returns
TypeDescription
UnknownFieldSet

clear()

public UnknownFieldSet.Builder clear()

Reset the builder to an empty set.

Returns
TypeDescription
UnknownFieldSet.Builder

clearField(int number)

public UnknownFieldSet.Builder clearField(int number)

Clear fields from the set with a given field number.

Parameter
NameDescription
numberint
Returns
TypeDescription
UnknownFieldSet.Builder

clone()

public UnknownFieldSet.Builder clone()

Clones the Builder.

Returns
TypeDescription
UnknownFieldSet.Builder
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.

Returns
TypeDescription
UnknownFieldSet

hasField(int number)

public boolean hasField(int number)

Check if the given field number is present in the set.

Parameter
NameDescription
numberint
Returns
TypeDescription
boolean

isInitialized()

public boolean isInitialized()

Returns true if all required fields in the message and all embedded messages are set, false otherwise.

See also: MessageOrBuilder#getInitializationErrorString()

Returns
TypeDescription
boolean

mergeDelimitedFrom(InputStream input)

public boolean mergeDelimitedFrom(InputStream input)

Like #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. Use MessageLite#writeDelimitedTo(OutputStream) to write messages in this format.

Parameter
NameDescription
inputInputStream
Returns
TypeDescription
boolean
Exceptions
TypeDescription
IOException

mergeDelimitedFrom(InputStream input, ExtensionRegistryLite extensionRegistry)

public boolean mergeDelimitedFrom(InputStream input, ExtensionRegistryLite extensionRegistry)

Like #mergeDelimitedFrom(InputStream) but supporting extensions.

Parameters
NameDescription
inputInputStream
extensionRegistryExtensionRegistryLite
Returns
TypeDescription
boolean
Exceptions
TypeDescription
IOException

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.

Parameters
NameDescription
numberint
fieldUnknownFieldSet.Field
Returns
TypeDescription
UnknownFieldSet.Builder

mergeFieldFrom(int tag, CodedInputStream input)

public boolean mergeFieldFrom(int tag, CodedInputStream input)

Parse a single field from input and merge it into this set.

Parameters
NameDescription
tagint

The field's tag number, which was already parsed.

inputCodedInputStream
Returns
TypeDescription
boolean

false if the tag is an end group tag.

Exceptions
TypeDescription
IOException

mergeFrom(byte[] data)

public UnknownFieldSet.Builder mergeFrom(byte[] data)

Parse data as an UnknownFieldSet and merge it with the set being built. This is just a small wrapper around #mergeFrom(CodedInputStream).

Parameter
NameDescription
databyte[]
Returns
TypeDescription
UnknownFieldSet.Builder
Exceptions
TypeDescription
InvalidProtocolBufferException

mergeFrom(byte[] data, ExtensionRegistryLite extensionRegistry)

public UnknownFieldSet.Builder mergeFrom(byte[] data, ExtensionRegistryLite extensionRegistry)

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,ExtensionRegistryLite).

Parameters
NameDescription
databyte[]
extensionRegistryExtensionRegistryLite
Returns
TypeDescription
UnknownFieldSet.Builder
Exceptions
TypeDescription
InvalidProtocolBufferException

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
NameDescription
databyte[]
offint
lenint
Returns
TypeDescription
UnknownFieldSet.Builder
Exceptions
TypeDescription
InvalidProtocolBufferException

mergeFrom(byte[] data, int off, int len, ExtensionRegistryLite extensionRegistry)

public UnknownFieldSet.Builder mergeFrom(byte[] data, int off, int len, ExtensionRegistryLite extensionRegistry)

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,ExtensionRegistryLite).

Parameters
NameDescription
databyte[]
offint
lenint
extensionRegistryExtensionRegistryLite
Returns
TypeDescription
UnknownFieldSet.Builder
Exceptions
TypeDescription
InvalidProtocolBufferException

mergeFrom(ByteString data)

public UnknownFieldSet.Builder mergeFrom(ByteString data)

Parse data as an UnknownFieldSet and merge it with the set being built. This is just a small wrapper around #mergeFrom(CodedInputStream).

Parameter
NameDescription
dataByteString
Returns
TypeDescription
UnknownFieldSet.Builder
Exceptions
TypeDescription
InvalidProtocolBufferException

mergeFrom(ByteString data, ExtensionRegistryLite extensionRegistry)

public UnknownFieldSet.Builder mergeFrom(ByteString data, ExtensionRegistryLite extensionRegistry)

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,ExtensionRegistryLite).

Parameters
NameDescription
dataByteString
extensionRegistryExtensionRegistryLite
Returns
TypeDescription
UnknownFieldSet.Builder
Exceptions
TypeDescription
InvalidProtocolBufferException

mergeFrom(CodedInputStream input)

public UnknownFieldSet.Builder mergeFrom(CodedInputStream input)

Parse an entire message from input and merge its fields into this set.

Parameter
NameDescription
inputCodedInputStream
Returns
TypeDescription
UnknownFieldSet.Builder
Exceptions
TypeDescription
IOException

mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry)

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.

Parameters
NameDescription
inputCodedInputStream
extensionRegistryExtensionRegistryLite
Returns
TypeDescription
UnknownFieldSet.Builder
Exceptions
TypeDescription
IOException

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++.

Parameter
NameDescription
mMessageLite
Returns
TypeDescription
UnknownFieldSet.Builder

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.

Parameter
NameDescription
otherUnknownFieldSet
Returns
TypeDescription
UnknownFieldSet.Builder

mergeFrom(InputStream input)

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).

Parameter
NameDescription
inputInputStream
Returns
TypeDescription
UnknownFieldSet.Builder
Exceptions
TypeDescription
IOException

mergeFrom(InputStream input, ExtensionRegistryLite extensionRegistry)

public UnknownFieldSet.Builder mergeFrom(InputStream input, ExtensionRegistryLite extensionRegistry)

Parse a message of this type from input and merge it with the message being built. This is just a small wrapper around #mergeFrom(CodedInputStream,ExtensionRegistryLite).

Parameters
NameDescription
inputInputStream
extensionRegistryExtensionRegistryLite
Returns
TypeDescription
UnknownFieldSet.Builder
Exceptions
TypeDescription
IOException

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.

Parameters
NameDescription
numberint
valueByteString
Returns
TypeDescription
UnknownFieldSet.Builder

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
NameDescription
numberint
valueint
Returns
TypeDescription
UnknownFieldSet.Builder