Package com.google.protobuf
Class UnknownFieldSet
java.lang.Object
com.google.protobuf.UnknownFieldSet
- All Implemented Interfaces:
MessageLite
,MessageLiteOrBuilder
UnknownFieldSet
keeps track of fields which were seen when parsing a protocol
message but whose field numbers or types are unrecognized. This most frequently occurs when new
fields are added to a message type and then messages containing those fields are read by old
software that was compiled before the new types were added.
Every Message
contains an UnknownFieldSet
(and every Message.Builder
contains a UnknownFieldSet.Builder
).
Most users will never need to use this class.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
Builder forUnknownFieldSet
s.static final class
Represents a single field in anUnknownFieldSet
.static final class
Parser to implement MessageLite interface. -
Method Summary
Modifier and TypeMethodDescriptionasMap()
Get a map of fields in the set by number.boolean
static UnknownFieldSet
Get an emptyUnknownFieldSet
.Get an instance of the type with no fields set.getField
(int number) Get a field by number.final UnknownFieldSet.Parser
Gets the parser for a message of the same type as this message.int
Get the number of bytes required to encode this set.int
Get the number of bytes required to encode this set usingMessageSet
wire format.boolean
hasField
(int number) Check if the given field number is present in the set.int
hashCode()
boolean
isEmpty()
Whether the field set has no fields.boolean
Returns true if all required fields in the message and all embedded messages are set, false otherwise.static UnknownFieldSet.Builder
Create a newUnknownFieldSet.Builder
.static UnknownFieldSet.Builder
newBuilder
(UnknownFieldSet copyFrom) Create a newUnknownFieldSet.Builder
and initialize it to be a copy ofcopyFrom
.Constructs a new builder for a message of the same type as this message.static UnknownFieldSet
parseFrom
(byte[] data) Parsedata
as anUnknownFieldSet
and return it.static UnknownFieldSet
parseFrom
(ByteString data) Parsedata
as anUnknownFieldSet
and return it.static UnknownFieldSet
parseFrom
(CodedInputStream input) Parse anUnknownFieldSet
from the given input stream.static UnknownFieldSet
parseFrom
(InputStream input) Parse anUnknownFieldSet
frominput
and return it.Constructs a builder initialized with the current message.byte[]
Serializes the message to abyte
array and returns it.Serializes the message to aByteString
and returns it.toString()
Converts the set to a string in protocol buffer text format.void
writeAsMessageSetTo
(CodedOutputStream output) Serializes the set and writes it tooutput
usingMessageSet
wire format.void
writeDelimitedTo
(OutputStream output) LikeMessageLite.writeTo(OutputStream)
, but writes the size of the message as a varint before writing the data.void
writeTo
(CodedOutputStream output) Serializes the set and writes it tooutput
.void
writeTo
(OutputStream output) Serializes the message and writes it tooutput
.
-
Method Details
-
newBuilder
Create a newUnknownFieldSet.Builder
. -
newBuilder
Create a newUnknownFieldSet.Builder
and initialize it to be a copy ofcopyFrom
. -
getDefaultInstance
Get an emptyUnknownFieldSet
. -
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
-
equals
-
hashCode
public int hashCode() -
isEmpty
public boolean isEmpty()Whether the field set has no fields. -
asMap
Get a map of fields in the set by number. -
hasField
public boolean hasField(int number) Check if the given field number is present in the set. -
getField
Get a field by number. Returns an empty field if not present. Never returnsnull
. -
writeTo
Serializes the set and writes it tooutput
.- Specified by:
writeTo
in interfaceMessageLite
- Throws:
IOException
-
toString
Converts the set to a string in protocol buffer text format. This is just a trivial wrapper aroundTextFormat.Printer.printToString(UnknownFieldSet)
. -
toByteString
Serializes the message to aByteString
and returns it. This is just a trivial wrapper aroundwriteTo(CodedOutputStream)
.- Specified by:
toByteString
in interfaceMessageLite
-
toByteArray
public byte[] toByteArray()Serializes the message to abyte
array and returns it. This is just a trivial wrapper aroundwriteTo(CodedOutputStream)
.- Specified by:
toByteArray
in interfaceMessageLite
-
writeTo
Serializes the message and writes it tooutput
. This is just a trivial wrapper aroundwriteTo(CodedOutputStream)
.- Specified by:
writeTo
in interfaceMessageLite
- Throws:
IOException
-
writeDelimitedTo
Description copied from interface:MessageLite
LikeMessageLite.writeTo(OutputStream)
, but writes the size of the message as a varint before writing the data. This allows more data to be written to the stream after the message without the need to delimit the message data yourself. UseMessageLite.Builder.mergeDelimitedFrom(InputStream)
(or the static methodYourMessageType.parseDelimitedFrom(InputStream)
) to parse messages written by this method.- Specified by:
writeDelimitedTo
in interfaceMessageLite
- Throws:
IOException
-
getSerializedSize
public int getSerializedSize()Get the number of bytes required to encode this set.- Specified by:
getSerializedSize
in interfaceMessageLite
-
writeAsMessageSetTo
Serializes the set and writes it tooutput
usingMessageSet
wire format.- Throws:
IOException
-
getSerializedSizeAsMessageSet
public int getSerializedSizeAsMessageSet()Get the number of bytes required to encode this set usingMessageSet
wire format. -
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
-
parseFrom
Parse anUnknownFieldSet
from the given input stream.- Throws:
IOException
-
parseFrom
Parsedata
as anUnknownFieldSet
and return it.- Throws:
InvalidProtocolBufferException
-
parseFrom
Parsedata
as anUnknownFieldSet
and return it.- Throws:
InvalidProtocolBufferException
-
parseFrom
Parse anUnknownFieldSet
frominput
and return it.- Throws:
IOException
-
newBuilderForType
Description copied from interface:MessageLite
Constructs a new builder for a message of the same type as this message.- Specified by:
newBuilderForType
in interfaceMessageLite
-
toBuilder
Description copied from interface:MessageLite
Constructs a builder initialized with the current message. Use this to derive a new message from the current one.- Specified by:
toBuilder
in interfaceMessageLite
-
getParserForType
Description copied from interface:MessageLite
Gets the parser for a message of the same type as this message.- Specified by:
getParserForType
in interfaceMessageLite
-