Class DiscardUnknownFieldsParser
java.lang.Object
com.google.protobuf.DiscardUnknownFieldsParser
Parsers to discard unknown fields during parsing.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
DiscardUnknownFieldsParser
private DiscardUnknownFieldsParser()
-
-
Method Details
-
wrap
Wraps a givenParserinto a newParserthat discards unknown fields during parsing.Usage example:
private final static Parser<Foo> FOO_PARSER = DiscardUnknownFieldsParser.wrap(Foo.parser()); Foo parseFooDiscardUnknown(ByteBuffer input) throws IOException { return FOO_PARSER.parseFrom(input); }Like all other implementations of
Parser, this parser is stateless and thread-safe.Note that this discards fields which were totally unknown to the schema, but it does not discard unrecognized closed enum values (where the field was known but the value was not). This means that
message.getUnknownFields()might still be non-empty for the parsed message. Open enums are recommended for improved behavior in the face of unrecognized values (open enums are the default in all syntaxes except for Proto2).- Parameters:
parser- The delegated parser that parses messages.- Returns:
- a
Parserthat will discard unknown fields during parsing.
-