• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc.  All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 //     * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //     * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 //     * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 package com.google.protobuf;
32 
33 import java.util.List;
34 import java.util.Map;
35 
36 /**
37  * Base interface for methods common to {@link Message} and {@link Message.Builder} to provide type
38  * equivalency.
39  *
40  * @author jonp@google.com (Jon Perlow)
41  */
42 public interface MessageOrBuilder extends MessageLiteOrBuilder {
43 
44   // (From MessageLite, re-declared here only for return type covariance.)
45   @Override
getDefaultInstanceForType()46   Message getDefaultInstanceForType();
47 
48   /**
49    * Returns a list of field paths (e.g. "foo.bar.baz") of required fields which are not set in this
50    * message. You should call {@link MessageLiteOrBuilder#isInitialized()} first to check if there
51    * are any missing fields, as that method is likely to be much faster than this one even when the
52    * message is fully-initialized.
53    */
findInitializationErrors()54   List<String> findInitializationErrors();
55 
56   /**
57    * Returns a comma-delimited list of required fields which are not set in this message object. You
58    * should call {@link MessageLiteOrBuilder#isInitialized()} first to check if there are any
59    * missing fields, as that method is likely to be much faster than this one even when the message
60    * is fully-initialized.
61    */
getInitializationErrorString()62   String getInitializationErrorString();
63 
64   /**
65    * Get the message's type's descriptor. This differs from the {@code getDescriptor()} method of
66    * generated message classes in that this method is an abstract method of the {@code Message}
67    * interface whereas {@code getDescriptor()} is a static method of a specific class. They return
68    * the same thing.
69    */
getDescriptorForType()70   Descriptors.Descriptor getDescriptorForType();
71 
72   /**
73    * Returns a collection of all the fields in this message which are set and their corresponding
74    * values. A singular ("required" or "optional") field is set iff hasField() returns true for that
75    * field. A "repeated" field is set iff getRepeatedFieldCount() is greater than zero. The values
76    * are exactly what would be returned by calling {@link #getField(Descriptors.FieldDescriptor)}
77    * for each field. The map is guaranteed to be a sorted map, so iterating over it will return
78    * fields in order by field number. <br>
79    * If this is for a builder, the returned map may or may not reflect future changes to the
80    * builder. Either way, the returned map is itself unmodifiable.
81    */
getAllFields()82   Map<Descriptors.FieldDescriptor, Object> getAllFields();
83 
84   /**
85    * Returns true if the given oneof is set.
86    *
87    * @throws IllegalArgumentException if {@code oneof.getContainingType() !=
88    *     getDescriptorForType()}.
89    */
hasOneof(Descriptors.OneofDescriptor oneof)90   boolean hasOneof(Descriptors.OneofDescriptor oneof);
91 
92   /** Obtains the FieldDescriptor if the given oneof is set. Returns null if no field is set. */
getOneofFieldDescriptor(Descriptors.OneofDescriptor oneof)93   Descriptors.FieldDescriptor getOneofFieldDescriptor(Descriptors.OneofDescriptor oneof);
94 
95   /**
96    * Returns true if the given field is set. This is exactly equivalent to calling the generated
97    * "has" accessor method corresponding to the field.
98    *
99    * @throws IllegalArgumentException The field is a repeated field, or {@code
100    *     field.getContainingType() != getDescriptorForType()}.
101    */
hasField(Descriptors.FieldDescriptor field)102   boolean hasField(Descriptors.FieldDescriptor field);
103 
104   /**
105    * Obtains the value of the given field, or the default value if it is not set. For primitive
106    * fields, the boxed primitive value is returned. For enum fields, the EnumValueDescriptor for the
107    * value is returned. For embedded message fields, the sub-message is returned. For repeated
108    * fields, a java.util.List is returned.
109    */
getField(Descriptors.FieldDescriptor field)110   Object getField(Descriptors.FieldDescriptor field);
111 
112   /**
113    * Gets the number of elements of a repeated field. This is exactly equivalent to calling the
114    * generated "Count" accessor method corresponding to the field.
115    *
116    * @throws IllegalArgumentException The field is not a repeated field, or {@code
117    *     field.getContainingType() != getDescriptorForType()}.
118    */
getRepeatedFieldCount(Descriptors.FieldDescriptor field)119   int getRepeatedFieldCount(Descriptors.FieldDescriptor field);
120 
121   /**
122    * Gets an element of a repeated field. For primitive fields, the boxed primitive value is
123    * returned. For enum fields, the EnumValueDescriptor for the value is returned. For embedded
124    * message fields, the sub-message is returned.
125    *
126    * @throws IllegalArgumentException The field is not a repeated field, or {@code
127    *     field.getContainingType() != getDescriptorForType()}.
128    */
getRepeatedField(Descriptors.FieldDescriptor field, int index)129   Object getRepeatedField(Descriptors.FieldDescriptor field, int index);
130 
131   /** Get the {@link UnknownFieldSet} for this message. */
getUnknownFields()132   UnknownFieldSet getUnknownFields();
133 }
134