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 Builder).
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.
Like #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. Use Builder#mergeDelimitedFrom(InputStream) (or the static method
YourMessageType.parseDelimitedFrom(InputStream)) to parse messages written by this method.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Class UnknownFieldSet (3.19.4)\n\n public final class UnknownFieldSet implements MessageLite\n\n`UnknownFieldSet` keeps track of fields which were seen when parsing a protocol\nmessage but whose field numbers or types are unrecognized. This most frequently occurs when new\nfields are added to a message type and then messages containing those fields are read by old\nsoftware that was compiled before the new types were added.\n\nEvery [Message](/java/docs/reference/protobuf/latest/com.google.protobuf.Message) contains an `UnknownFieldSet` (and every [Message.Builder](/java/docs/reference/protobuf/latest/com.google.protobuf.Message.Builder)\ncontains a Builder).\n\nMost users will never need to use this class. \n\nInheritance\n-----------\n\n[Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \\\u003e UnknownFieldSet \n\nImplements\n----------\n\n[MessageLite](/java/docs/reference/protobuf/latest/com.google.protobuf.MessageLite) \n\nInherited Members\n-----------------\n\n[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) \n[Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) \n[Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) \n[Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) \n[Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) \n[Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) \n[Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) \n[Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) \n[Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) \n[Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) \n[Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)\n\nStatic Methods\n--------------\n\n### getDefaultInstance()\n\n public static UnknownFieldSet getDefaultInstance()\n\nGet an empty `UnknownFieldSet`.\n\n### newBuilder()\n\n public static UnknownFieldSet.Builder newBuilder()\n\nCreate a new Builder.\n\n### newBuilder(UnknownFieldSet copyFrom)\n\n public static UnknownFieldSet.Builder newBuilder(UnknownFieldSet copyFrom)\n\nCreate a new Builder and initialize it to be a copy of `copyFrom`.\n\n### parseFrom(byte\\[\\] data)\n\n public static UnknownFieldSet parseFrom(byte[] data)\n\nParse `data` as an `UnknownFieldSet` and return it.\n\n### parseFrom(ByteString data)\n\n public static UnknownFieldSet parseFrom(ByteString data)\n\nParse `data` as an `UnknownFieldSet` and return it.\n\n### parseFrom(CodedInputStream input)\n\n public static UnknownFieldSet parseFrom(CodedInputStream input)\n\nParse an `UnknownFieldSet` from the given input stream.\n\n### parseFrom(InputStream input)\n\n public static UnknownFieldSet parseFrom(InputStream input)\n\nParse an `UnknownFieldSet` from `input` and return it.\n\nMethods\n-------\n\n### asMap()\n\n public Map\u003cInteger,UnknownFieldSet.Field\u003e asMap()\n\nGet a map of fields in the set by number.\n\n### equals(Object other)\n\n public boolean equals(Object other)\n\n**Overrides** \n[Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-)\n\n### getDefaultInstanceForType()\n\n public UnknownFieldSet getDefaultInstanceForType()\n\nGet an instance of the type with no fields set. Because no fields are set, all getters for\nsingular fields will return default values and repeated fields will appear empty. This may or\nmay not be a singleton. This differs from the `getDefaultInstance()` method of generated\nmessage classes in that this method is an abstract method of the `MessageLite` interface\nwhereas `getDefaultInstance()` is a static method of a specific class. They return the\nsame thing.\n\n### getField(int number)\n\n public UnknownFieldSet.Field getField(int number)\n\nGet a field by number. Returns an empty field if not present. Never returns `null`.\n\n### getParserForType()\n\n public final UnknownFieldSet.Parser getParserForType()\n\nGets the parser for a message of the same type as this message.\n\n### getSerializedSize()\n\n public int getSerializedSize()\n\nGet the number of bytes required to encode this set.\n\n### getSerializedSizeAsMessageSet()\n\n public int getSerializedSizeAsMessageSet()\n\nGet the number of bytes required to encode this set using `MessageSet` wire format.\n\n### hasField(int number)\n\n public boolean hasField(int number)\n\nCheck if the given field number is present in the set.\n\n### hashCode()\n\n public int hashCode()\n\n**Overrides** \n[Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--)\n\n### isInitialized()\n\n public boolean isInitialized()\n\nReturns true if all required fields in the message and all embedded messages are set, false\notherwise.\n\nSee also: [MessageOrBuilder#getInitializationErrorString()](/java/docs/reference/protobuf/latest/com.google.protobuf.MessageOrBuilder#com_google_protobuf_MessageOrBuilder_getInitializationErrorString__)\n\n### newBuilderForType()\n\n public UnknownFieldSet.Builder newBuilderForType()\n\nConstructs a new builder for a message of the same type as this message.\n\n### toBuilder()\n\n public UnknownFieldSet.Builder toBuilder()\n\nConstructs a builder initialized with the current message. Use this to derive a new message\nfrom the current one.\n\n### toByteArray()\n\n public byte[] toByteArray()\n\nSerializes the message to a `byte` array and returns it. This is just a trivial wrapper\naround [#writeTo(CodedOutputStream)](/java/docs/reference/protobuf/latest/com.google.protobuf.UnknownFieldSet#com_google_protobuf_UnknownFieldSet_writeTo_com_google_protobuf_CodedOutputStream_).\n\n### toByteString()\n\n public ByteString toByteString()\n\nSerializes the message to a `ByteString` and returns it. This is just a trivial wrapper\naround [#writeTo(CodedOutputStream)](/java/docs/reference/protobuf/latest/com.google.protobuf.UnknownFieldSet#com_google_protobuf_UnknownFieldSet_writeTo_com_google_protobuf_CodedOutputStream_).\n\n### toString()\n\n public String toString()\n\nConverts the set to a string in protocol buffer text format. This is just a trivial wrapper\naround [TextFormat.Printer#printToString(UnknownFieldSet)](/java/docs/reference/protobuf/latest/com.google.protobuf.TextFormat.Printer#com_google_protobuf_TextFormat_Printer_printToString_com_google_protobuf_UnknownFieldSet_).\n\n**Overrides** \n[Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--)\n\n### writeAsMessageSetTo(CodedOutputStream output)\n\n public void writeAsMessageSetTo(CodedOutputStream output)\n\nSerializes the set and writes it to `output` using `MessageSet` wire format.\n\n### writeDelimitedTo(OutputStream output)\n\n public void writeDelimitedTo(OutputStream output)\n\nLike [#writeTo(OutputStream)](/java/docs/reference/protobuf/latest/com.google.protobuf.UnknownFieldSet#com_google_protobuf_UnknownFieldSet_writeTo_java_io_OutputStream_), but writes the size of the message as a varint before\nwriting the data. This allows more data to be written to the stream after the message without\nthe need to delimit the message data yourself. Use Builder#mergeDelimitedFrom(InputStream) (or the static method `\nYourMessageType.parseDelimitedFrom(InputStream)`) to parse messages written by this method.\n\n### writeTo(CodedOutputStream output)\n\n public void writeTo(CodedOutputStream output)\n\nSerializes the set and writes it to `output`.\n\n### writeTo(OutputStream output)\n\n public void writeTo(OutputStream output)\n\nSerializes the message and writes it to `output`. This is just a trivial wrapper around\n[#writeTo(CodedOutputStream)](/java/docs/reference/protobuf/latest/com.google.protobuf.UnknownFieldSet#com_google_protobuf_UnknownFieldSet_writeTo_com_google_protobuf_CodedOutputStream_)."]]