• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc.  All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
7 
8 package com.google.protobuf;
9 
10 import com.google.protobuf.ArrayDecoders.Registers;
11 import java.io.IOException;
12 
13 /**
14  * A runtime schema for a single protobuf message. A schema provides operations on message instances
15  * such as serialization/deserialization.
16  */
17 @ExperimentalApi
18 @CheckReturnValue
19 interface Schema<T> {
20   /** Writes the given message to the target {@link Writer}. */
writeTo(T message, Writer writer)21   void writeTo(T message, Writer writer) throws IOException;
22 
23   /**
24    * Reads fields from the given {@link Reader} and merges them into the message. It doesn't make
25    * the message immutable after parsing is done. To make the message immutable, use {@link
26    * #makeImmutable}.
27    */
mergeFrom(T message, Reader reader, ExtensionRegistryLite extensionRegistry)28   void mergeFrom(T message, Reader reader, ExtensionRegistryLite extensionRegistry)
29       throws IOException;
30 
31   /**
32    * Like the above but parses from a byte[] without extensions. Entry point of fast path. Note that
33    * this method may throw IndexOutOfBoundsException if the input data is not valid protobuf wire
34    * format. Protobuf public API methods should catch and convert that exception to
35    * InvalidProtocolBufferException.
36    */
mergeFrom(T message, byte[] data, int position, int limit, Registers registers)37   void mergeFrom(T message, byte[] data, int position, int limit, Registers registers)
38       throws IOException;
39 
40   /** Marks repeated/map/extension/unknown fields as immutable. */
makeImmutable(T message)41   void makeImmutable(T message);
42 
43   /** Checks whether all required fields are set. */
isInitialized(T message)44   boolean isInitialized(T message);
45 
46   /** Creates a new instance of the message class. */
newInstance()47   T newInstance();
48 
49   /** Determine of the two messages are equal. */
equals(T message, T other)50   boolean equals(T message, T other);
51 
52   /** Compute a hashCode for the message. */
hashCode(T message)53   int hashCode(T message);
54 
55   /**
56    * Merge values from {@code other} into {@code message}. This method doesn't make the message
57    * immutable. To make the message immutable after merging, use {@link #makeImmutable}.
58    */
mergeFrom(T message, T other)59   void mergeFrom(T message, T other);
60 
61   /** Compute the serialized size of the message. */
getSerializedSize(T message)62   int getSerializedSize(T message);
63 }
64