All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.protobuf.DiscardUnknownFieldsParser Maven / Gradle / Ivy

Go to download

Core Protocol Buffers library. Protocol Buffers are a way of encoding structured data in an efficient yet extensible format.

The newest version!
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc.  All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd

package com.google.protobuf;

/** Parsers to discard unknown fields during parsing. */
public final class DiscardUnknownFieldsParser {

  /**
   * Wraps a given {@link Parser} into a new {@link Parser} that discards unknown fields during
   * parsing.
   *
   * 

Usage example: * *

{@code
   * private final static Parser FOO_PARSER = DiscardUnknownFieldsParser.wrap(Foo.parser());
   * Foo parseFooDiscardUnknown(ByteBuffer input) throws IOException {
   *   return FOO_PARSER.parseFrom(input);
   * }
   * }
* *

Like all other implementations of {@code Parser}, this parser is stateless and thread-safe. * * @param parser The delegated parser that parses messages. * @return a {@link Parser} that will discard unknown fields during parsing. */ public static final Parser wrap(final Parser parser) { return new AbstractParser() { @Override public T parsePartialFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException { try { input.discardUnknownFields(); return parser.parsePartialFrom(input, extensionRegistry); } finally { input.unsetDiscardUnknownFields(); } } }; } private DiscardUnknownFieldsParser() {} }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy