aboutsummaryrefslogtreecommitdiff
path: root/java/core/src/main/java/com/google/protobuf/Reader.java
blob: aa5b330f2f617d9fe0e134d195ca59fe6afab551 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc.  All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//     * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

package com.google.protobuf;

import java.io.IOException;
import java.util.List;

/** A reader of fields from a serialized protobuf message. */
// TODO(nathanmittler): Refactor to allow the reader to allocate properly sized lists.
@ExperimentalApi
public interface Reader {
  /** Value used to indicate that the end of input has been reached. */
  int READ_DONE = Integer.MAX_VALUE;

  /**
   * Gets the field number for the current field being read.
   *
   * @return the current field number or {@link #READ_DONE} if the end of input has been reached.
   */
  int getFieldNumber() throws IOException;

  /**
   * Skips the current field and advances the reader to the next field.
   *
   * @return {@code true} if there are more fields or {@link #READ_DONE} if the end of input has
   *     been reached.
   */
  boolean skipField() throws IOException;

  /**
   * Reads and returns the next field of type {@code DOUBLE} and advances the reader to the next
   * field.
   */
  double readDouble() throws IOException;

  /**
   * Reads and returns the next field of type {@code FLOAT} and advances the reader to the next
   * field.
   */
  float readFloat() throws IOException;

  /**
   * Reads and returns the next field of type {@code UINT64} and advances the reader to the next
   * field.
   */
  long readUInt64() throws IOException;

  /**
   * Reads and returns the next field of type {@code INT64} and advances the reader to the next
   * field.
   */
  long readInt64() throws IOException;

  /**
   * Reads and returns the next field of type {@code INT32} and advances the reader to the next
   * field.
   */
  int readInt32() throws IOException;

  /**
   * Reads and returns the next field of type {@code FIXED64} and advances the reader to the next
   * field.
   */
  long readFixed64() throws IOException;

  /**
   * Reads and returns the next field of type {@code FIXED32} and advances the reader to the next
   * field.
   */
  int readFixed32() throws IOException;

  /**
   * Reads and returns the next field of type {@code BOOL} and advances the reader to the next
   * field.
   */
  boolean readBool() throws IOException;

  /**
   * Reads and returns the next field of type {@code STRING} and advances the reader to the next
   * field.
   */
  String readString() throws IOException;

  /**
   * Reads and returns the next field of type {@code MESSAGE} and advances the reader to the next
   * field.
   */
  <T> T readMessage(Class<T> clazz) throws IOException;

  /**
   * Reads and returns the next field of type {@code GROUP} and advances the reader to the next
   * field.
   *
   * @deprecated groups fields are deprecated.
   */
  @Deprecated
  <T> T readGroup(Class<T> clazz) throws IOException;

  /**
   * Reads and returns the next field of type {@code BYTES} and advances the reader to the next
   * field.
   */
  ByteString readBytes() throws IOException;

  /**
   * Reads and returns the next field of type {@code UINT32} and advances the reader to the next
   * field.
   */
  int readUInt32() throws IOException;

  /**
   * Reads and returns the next field of type {@code ENUM} and advances the reader to the next
   * field.
   */
  int readEnum() throws IOException;

  /**
   * Reads and returns the next field of type {@code SFIXED32} and advances the reader to the next
   * field.
   */
  int readSFixed32() throws IOException;

  /**
   * Reads and returns the next field of type {@code SFIXED64} and advances the reader to the next
   * field.
   */
  long readSFixed64() throws IOException;

  /**
   * Reads and returns the next field of type {@code SINT32} and advances the reader to the next
   * field.
   */
  int readSInt32() throws IOException;

  /**
   * Reads and returns the next field of type {@code SINT64} and advances the reader to the next
   * field.
   */
  long readSInt64() throws IOException;

  /**
   * Reads the next field of type {@code DOUBLE_LIST} or {@code DOUBLE_LIST_PACKED} and advances the
   * reader to the next field.
   *
   * @param target the list that will receive the read values.
   */
  void readDoubleList(List<Double> target) throws IOException;

  /**
   * Reads the next field of type {@code FLOAT_LIST} or {@code FLOAT_LIST_PACKED} and advances the
   * reader to the next field.
   *
   * @param target the list that will receive the read values.
   */
  void readFloatList(List<Float> target) throws IOException;

  /**
   * Reads the next field of type {@code UINT64_LIST} or {@code UINT64_LIST_PACKED} and advances the
   * reader to the next field.
   *
   * @param target the list that will receive the read values.
   */
  void readUInt64List(List<Long> target) throws IOException;

  /**
   * Reads the next field of type {@code INT64_LIST} or {@code INT64_LIST_PACKED} and advances the
   * reader to the next field.
   *
   * @param target the list that will receive the read values.
   */
  void readInt64List(List<Long> target) throws IOException;

  /**
   * Reads the next field of type {@code INT32_LIST} or {@code INT32_LIST_PACKED} and advances the
   * reader to the next field.
   *
   * @param target the list that will receive the read values.
   */
  void readInt32List(List<Integer> target) throws IOException;

  /**
   * Reads the next field of type {@code FIXED64_LIST} or {@code FIXED64_LIST_PACKED} and advances
   * the reader to the next field.
   *
   * @param target the list that will receive the read values.
   */
  void readFixed64List(List<Long> target) throws IOException;

  /**
   * Reads the next field of type {@code FIXED32_LIST} or {@code FIXED32_LIST_PACKED} and advances
   * the reader to the next field.
   *
   * @param target the list that will receive the read values.
   */
  void readFixed32List(List<Integer> target) throws IOException;

  /**
   * Reads the next field of type {@code BOOL_LIST} or {@code BOOL_LIST_PACKED} and advances the
   * reader to the next field.
   *
   * @param target the list that will receive the read values.
   */
  void readBoolList(List<Boolean> target) throws IOException;

  /**
   * Reads the next field of type {@code STRING_LIST} and advances the reader to the next field.
   *
   * @param target the list that will receive the read values.
   */
  void readStringList(List<String> target) throws IOException;

  /**
   * Reads the next field of type {@code MESSAGE_LIST} and advances the reader to the next field.
   *
   * @param target the list that will receive the read values.
   * @param targetType the type of the elements stored in the {@code target} list.
   */
  <T> void readMessageList(List<T> target, Class<T> targetType) throws IOException;

  /**
   * Reads the next field of type {@code GROUP_LIST} and advances the reader to the next field.
   *
   * @param target the list that will receive the read values.
   * @param targetType the type of the elements stored in the {@code target} list.
   * @deprecated groups fields are deprecated.
   */
  @Deprecated
  <T> void readGroupList(List<T> target, Class<T> targetType) throws IOException;

  /**
   * Reads the next field of type {@code BYTES_LIST} and advances the reader to the next field.
   *
   * @param target the list that will receive the read values.
   */
  void readBytesList(List<ByteString> target) throws IOException;

  /**
   * Reads the next field of type {@code UINT32_LIST} or {@code UINT32_LIST_PACKED} and advances the
   * reader to the next field.
   *
   * @param target the list that will receive the read values.
   */
  void readUInt32List(List<Integer> target) throws IOException;

  /**
   * Reads the next field of type {@code ENUM_LIST} or {@code ENUM_LIST_PACKED} and advances the
   * reader to the next field.
   *
   * @param target the list that will receive the read values.
   */
  void readEnumList(List<Integer> target) throws IOException;

  /**
   * Reads the next field of type {@code SFIXED32_LIST} or {@code SFIXED32_LIST_PACKED} and advances
   * the reader to the next field.
   *
   * @param target the list that will receive the read values.
   */
  void readSFixed32List(List<Integer> target) throws IOException;

  /**
   * Reads the next field of type {@code SFIXED64_LIST} or {@code SFIXED64_LIST_PACKED} and advances
   * the reader to the next field.
   *
   * @param target the list that will receive the read values.
   */
  void readSFixed64List(List<Long> target) throws IOException;

  /**
   * Reads the next field of type {@code SINT32_LIST} or {@code SINT32_LIST_PACKED} and advances the
   * reader to the next field.
   *
   * @param target the list that will receive the read values.
   */
  void readSInt32List(List<Integer> target) throws IOException;

  /**
   * Reads the next field of type {@code SINT64_LIST} or {@code SINT64_LIST_PACKED} and advances the
   * reader to the next field.
   *
   * @param target the list that will receive the read values.
   */
  void readSInt64List(List<Long> target) throws IOException;
}