blob: f54c27071367f441709968db2519e79874026d5d [file] [log] [blame]
csharptest2b868842011-06-10 14:41:47 -05001using System;
2using System.Collections.Generic;
3using Google.ProtocolBuffers.Descriptors;
4
5//Disable CS3011: only CLS-compliant members can be abstract
6#pragma warning disable 3011
7
8namespace Google.ProtocolBuffers.Serialization
9{
10 /// <summary>
11 /// Provides a base-class that provides some basic functionality for handling type dispatching
12 /// </summary>
13 public abstract class AbstractReader : ICodedInputStream
14 {
csharptest0f3540e2011-08-05 20:40:14 -050015 private const int DefaultMaxDepth = 64;
16 private int _depth;
17
18 /// <summary> Constructs a new reader </summary>
19 protected AbstractReader() { MaxDepth = DefaultMaxDepth; }
20 /// <summary> Constructs a new child reader </summary>
21 protected AbstractReader(AbstractReader copyFrom)
22 {
23 _depth = copyFrom._depth + 1;
24 MaxDepth = copyFrom.MaxDepth;
25 }
26
27 /// <summary> Gets or sets the maximum recursion depth allowed </summary>
28 public int MaxDepth { get; set; }
csharptest3b70dd72011-06-11 12:22:17 -050029
csharptest2b868842011-06-10 14:41:47 -050030 /// <summary>
31 /// Merges the contents of stream into the provided message builder
32 /// </summary>
33 public TBuilder Merge<TBuilder>(TBuilder builder) where TBuilder : IBuilderLite
csharptest74c5e0c2011-07-14 13:06:22 -050034 {
35 return Merge(builder, ExtensionRegistry.Empty);
36 }
csharptest2b868842011-06-10 14:41:47 -050037
38 /// <summary>
39 /// Merges the contents of stream into the provided message builder
40 /// </summary>
csharptest74c5e0c2011-07-14 13:06:22 -050041 public abstract TBuilder Merge<TBuilder>(TBuilder builder, ExtensionRegistry registry)
42 where TBuilder : IBuilderLite;
csharptest2b868842011-06-10 14:41:47 -050043
44 /// <summary>
45 /// Peeks at the next field in the input stream and returns what information is available.
46 /// </summary>
47 /// <remarks>
48 /// This may be called multiple times without actually reading the field. Only after the field
49 /// is either read, or skipped, should PeekNext return a different value.
50 /// </remarks>
51 protected abstract bool PeekNext(out string field);
52
53 /// <summary>
54 /// Causes the reader to skip past this field
55 /// </summary>
56 protected abstract void Skip();
57
58 /// <summary>
59 /// Returns true if it was able to read a Boolean from the input
60 /// </summary>
61 protected abstract bool Read(ref bool value);
62
63 /// <summary>
64 /// Returns true if it was able to read a Int32 from the input
65 /// </summary>
66 protected abstract bool Read(ref int value);
67
68 /// <summary>
69 /// Returns true if it was able to read a UInt32 from the input
70 /// </summary>
71 [CLSCompliant(false)]
72 protected abstract bool Read(ref uint value);
73
74 /// <summary>
75 /// Returns true if it was able to read a Int64 from the input
76 /// </summary>
77 protected abstract bool Read(ref long value);
78
79 /// <summary>
80 /// Returns true if it was able to read a UInt64 from the input
81 /// </summary>
82 [CLSCompliant(false)]
83 protected abstract bool Read(ref ulong value);
84
85 /// <summary>
86 /// Returns true if it was able to read a Single from the input
87 /// </summary>
88 protected abstract bool Read(ref float value);
89
90 /// <summary>
91 /// Returns true if it was able to read a Double from the input
92 /// </summary>
93 protected abstract bool Read(ref double value);
94
95 /// <summary>
96 /// Returns true if it was able to read a String from the input
97 /// </summary>
98 protected abstract bool Read(ref string value);
99
100 /// <summary>
101 /// Returns true if it was able to read a ByteString from the input
102 /// </summary>
103 protected abstract bool Read(ref ByteString value);
104
105 /// <summary>
106 /// returns true if it was able to read a single value into the value reference. The value
107 /// stored may be of type System.String, System.Int32, or an IEnumLite from the IEnumLiteMap.
108 /// </summary>
109 protected abstract bool ReadEnum(ref object value);
110
111 /// <summary>
112 /// Merges the input stream into the provided IBuilderLite
113 /// </summary>
114 protected abstract bool ReadMessage(IBuilderLite builder, ExtensionRegistry registry);
115
116 /// <summary>
117 /// Merges the input stream into the provided IBuilderLite
118 /// </summary>
119 public virtual bool ReadGroup(IBuilderLite value, ExtensionRegistry registry)
120 {
121 return ReadMessage(value, registry);
122 }
123
124 /// <summary>
125 /// Cursors through the array elements and stops at the end of the array
126 /// </summary>
127 protected virtual IEnumerable<string> ForeachArrayItem(string field)
128 {
129 string next = field;
130 while (true)
131 {
132 yield return next;
133
134 if (!PeekNext(out next) || next != field)
csharptest74c5e0c2011-07-14 13:06:22 -0500135 {
csharptest2b868842011-06-10 14:41:47 -0500136 break;
csharptest74c5e0c2011-07-14 13:06:22 -0500137 }
csharptest2b868842011-06-10 14:41:47 -0500138 }
139 }
140
141 /// <summary>
142 /// Reads an array of T messages
143 /// </summary>
csharptest74c5e0c2011-07-14 13:06:22 -0500144 public virtual bool ReadMessageArray<T>(string field, ICollection<T> items, IMessageLite messageType,
145 ExtensionRegistry registry)
csharptest2b868842011-06-10 14:41:47 -0500146 {
147 bool success = false;
148 foreach (string next in ForeachArrayItem(field))
149 {
150 IBuilderLite builder = messageType.WeakCreateBuilderForType();
151 if (ReadMessage(builder, registry))
152 {
csharptest74c5e0c2011-07-14 13:06:22 -0500153 items.Add((T) builder.WeakBuild());
csharptest2b868842011-06-10 14:41:47 -0500154 success |= true;
155 }
156 }
157 return success;
158 }
159
160 /// <summary>
161 /// Reads an array of T messages as a proto-buffer group
162 /// </summary>
csharptest74c5e0c2011-07-14 13:06:22 -0500163 public virtual bool ReadGroupArray<T>(string field, ICollection<T> items, IMessageLite messageType,
164 ExtensionRegistry registry)
csharptest2b868842011-06-10 14:41:47 -0500165 {
166 bool success = false;
167 foreach (string next in ForeachArrayItem(field))
168 {
169 IBuilderLite builder = messageType.WeakCreateBuilderForType();
170 if (ReadGroup(builder, registry))
171 {
csharptest74c5e0c2011-07-14 13:06:22 -0500172 items.Add((T) builder.WeakBuild());
csharptest2b868842011-06-10 14:41:47 -0500173 success |= true;
174 }
175 }
176 return success;
177 }
178
179 /// <summary>
180 /// Reads an array of System.Enum type T and adds them to the collection
181 /// </summary>
182 public virtual bool ReadEnumArray(string field, ICollection<object> items)
183 {
184 bool success = false;
185 foreach (string next in ForeachArrayItem(field))
186 {
187 object temp = null;
188 if (ReadEnum(ref temp))
189 {
190 items.Add(temp);
191 success |= true;
192 }
193 }
194 return success;
195 }
196
197 /// <summary>
198 /// Reads an array of T, where T is a primitive type defined by FieldType
199 /// </summary>
200 public virtual bool ReadArray<T>(FieldType type, string field, ICollection<T> items)
201 {
202 bool success = false;
203 foreach (string next in ForeachArrayItem(field))
204 {
205 object temp = null;
206 if (ReadField(type, ref temp))
207 {
csharptest74c5e0c2011-07-14 13:06:22 -0500208 items.Add((T) temp);
csharptest2b868842011-06-10 14:41:47 -0500209 success |= true;
210 }
211 }
212 return success;
213 }
214
215 /// <summary>
216 /// returns true if it was able to read a single primitive value of FieldType into the value reference
217 /// </summary>
218 public virtual bool ReadField(FieldType type, ref object value)
219 {
220 switch (type)
221 {
222 case FieldType.Bool:
223 {
224 bool temp = false;
225 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500226 {
csharptest2b868842011-06-10 14:41:47 -0500227 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500228 }
csharptest2b868842011-06-10 14:41:47 -0500229 else
csharptest74c5e0c2011-07-14 13:06:22 -0500230 {
csharptest2b868842011-06-10 14:41:47 -0500231 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500232 }
csharptest2b868842011-06-10 14:41:47 -0500233 break;
234 }
235 case FieldType.Int64:
236 case FieldType.SInt64:
237 case FieldType.SFixed64:
238 {
239 long temp = 0;
240 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500241 {
csharptest2b868842011-06-10 14:41:47 -0500242 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500243 }
csharptest2b868842011-06-10 14:41:47 -0500244 else
csharptest74c5e0c2011-07-14 13:06:22 -0500245 {
csharptest2b868842011-06-10 14:41:47 -0500246 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500247 }
csharptest2b868842011-06-10 14:41:47 -0500248 break;
249 }
250 case FieldType.UInt64:
251 case FieldType.Fixed64:
252 {
253 ulong temp = 0;
254 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500255 {
csharptest2b868842011-06-10 14:41:47 -0500256 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500257 }
csharptest2b868842011-06-10 14:41:47 -0500258 else
csharptest74c5e0c2011-07-14 13:06:22 -0500259 {
csharptest2b868842011-06-10 14:41:47 -0500260 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500261 }
csharptest2b868842011-06-10 14:41:47 -0500262 break;
263 }
264 case FieldType.Int32:
265 case FieldType.SInt32:
266 case FieldType.SFixed32:
267 {
268 int temp = 0;
269 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500270 {
csharptest2b868842011-06-10 14:41:47 -0500271 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500272 }
csharptest2b868842011-06-10 14:41:47 -0500273 else
csharptest74c5e0c2011-07-14 13:06:22 -0500274 {
csharptest2b868842011-06-10 14:41:47 -0500275 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500276 }
csharptest2b868842011-06-10 14:41:47 -0500277 break;
278 }
279 case FieldType.UInt32:
280 case FieldType.Fixed32:
281 {
282 uint temp = 0;
283 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500284 {
csharptest2b868842011-06-10 14:41:47 -0500285 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500286 }
csharptest2b868842011-06-10 14:41:47 -0500287 else
csharptest74c5e0c2011-07-14 13:06:22 -0500288 {
csharptest2b868842011-06-10 14:41:47 -0500289 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500290 }
csharptest2b868842011-06-10 14:41:47 -0500291 break;
292 }
293 case FieldType.Float:
294 {
295 float temp = float.NaN;
296 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500297 {
csharptest2b868842011-06-10 14:41:47 -0500298 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500299 }
csharptest2b868842011-06-10 14:41:47 -0500300 else
csharptest74c5e0c2011-07-14 13:06:22 -0500301 {
csharptest2b868842011-06-10 14:41:47 -0500302 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500303 }
csharptest2b868842011-06-10 14:41:47 -0500304 break;
305 }
306 case FieldType.Double:
307 {
308 double temp = float.NaN;
309 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500310 {
csharptest2b868842011-06-10 14:41:47 -0500311 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500312 }
csharptest2b868842011-06-10 14:41:47 -0500313 else
csharptest74c5e0c2011-07-14 13:06:22 -0500314 {
csharptest2b868842011-06-10 14:41:47 -0500315 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500316 }
csharptest2b868842011-06-10 14:41:47 -0500317 break;
318 }
319 case FieldType.String:
320 {
321 string temp = null;
322 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500323 {
csharptest2b868842011-06-10 14:41:47 -0500324 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500325 }
csharptest2b868842011-06-10 14:41:47 -0500326 else
csharptest74c5e0c2011-07-14 13:06:22 -0500327 {
csharptest2b868842011-06-10 14:41:47 -0500328 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500329 }
csharptest2b868842011-06-10 14:41:47 -0500330 break;
331 }
332 case FieldType.Bytes:
333 {
334 ByteString temp = null;
335 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500336 {
csharptest2b868842011-06-10 14:41:47 -0500337 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500338 }
csharptest2b868842011-06-10 14:41:47 -0500339 else
csharptest74c5e0c2011-07-14 13:06:22 -0500340 {
csharptest2b868842011-06-10 14:41:47 -0500341 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500342 }
csharptest2b868842011-06-10 14:41:47 -0500343 break;
344 }
345 default:
346 throw InvalidProtocolBufferException.InvalidTag();
347 }
348 return true;
349 }
350
351 #region ICodedInputStream Members
352
353 bool ICodedInputStream.ReadTag(out uint fieldTag, out string fieldName)
354 {
355 fieldTag = 0;
356 if (PeekNext(out fieldName))
357 {
358 return true;
359 }
360 return false;
361 }
362
363 bool ICodedInputStream.ReadDouble(ref double value)
csharptest74c5e0c2011-07-14 13:06:22 -0500364 {
365 return Read(ref value);
366 }
csharptest2b868842011-06-10 14:41:47 -0500367
368 bool ICodedInputStream.ReadFloat(ref float value)
csharptest74c5e0c2011-07-14 13:06:22 -0500369 {
370 return Read(ref value);
371 }
csharptest2b868842011-06-10 14:41:47 -0500372
373 bool ICodedInputStream.ReadUInt64(ref ulong value)
csharptest74c5e0c2011-07-14 13:06:22 -0500374 {
375 return Read(ref value);
376 }
csharptest2b868842011-06-10 14:41:47 -0500377
378 bool ICodedInputStream.ReadInt64(ref long value)
csharptest74c5e0c2011-07-14 13:06:22 -0500379 {
380 return Read(ref value);
381 }
csharptest2b868842011-06-10 14:41:47 -0500382
383 bool ICodedInputStream.ReadInt32(ref int value)
csharptest74c5e0c2011-07-14 13:06:22 -0500384 {
385 return Read(ref value);
386 }
csharptest2b868842011-06-10 14:41:47 -0500387
388 bool ICodedInputStream.ReadFixed64(ref ulong value)
csharptest74c5e0c2011-07-14 13:06:22 -0500389 {
390 return Read(ref value);
391 }
csharptest2b868842011-06-10 14:41:47 -0500392
393 bool ICodedInputStream.ReadFixed32(ref uint value)
csharptest74c5e0c2011-07-14 13:06:22 -0500394 {
395 return Read(ref value);
396 }
csharptest2b868842011-06-10 14:41:47 -0500397
398 bool ICodedInputStream.ReadBool(ref bool value)
csharptest74c5e0c2011-07-14 13:06:22 -0500399 {
400 return Read(ref value);
401 }
csharptest2b868842011-06-10 14:41:47 -0500402
403 bool ICodedInputStream.ReadString(ref string value)
csharptest74c5e0c2011-07-14 13:06:22 -0500404 {
405 return Read(ref value);
406 }
csharptest2b868842011-06-10 14:41:47 -0500407
408 void ICodedInputStream.ReadGroup(int fieldNumber, IBuilderLite builder, ExtensionRegistry extensionRegistry)
csharptest3b70dd72011-06-11 12:22:17 -0500409 {
csharptest0f3540e2011-08-05 20:40:14 -0500410 if (_depth++ > MaxDepth)
csharptest74c5e0c2011-07-14 13:06:22 -0500411 {
csharptest0f3540e2011-08-05 20:40:14 -0500412 throw new RecursionLimitExceededException();
csharptest74c5e0c2011-07-14 13:06:22 -0500413 }
csharptest3b70dd72011-06-11 12:22:17 -0500414 ReadGroup(builder, extensionRegistry);
csharptest0f3540e2011-08-05 20:40:14 -0500415 _depth--;
csharptest3b70dd72011-06-11 12:22:17 -0500416 }
csharptest2b868842011-06-10 14:41:47 -0500417
418 void ICodedInputStream.ReadUnknownGroup(int fieldNumber, IBuilderLite builder)
csharptest74c5e0c2011-07-14 13:06:22 -0500419 {
420 throw new NotSupportedException();
421 }
csharptest2b868842011-06-10 14:41:47 -0500422
423 void ICodedInputStream.ReadMessage(IBuilderLite builder, ExtensionRegistry extensionRegistry)
csharptest3b70dd72011-06-11 12:22:17 -0500424 {
csharptest0f3540e2011-08-05 20:40:14 -0500425 if (_depth++ > MaxDepth)
csharptest74c5e0c2011-07-14 13:06:22 -0500426 {
csharptest0f3540e2011-08-05 20:40:14 -0500427 throw new RecursionLimitExceededException();
csharptest74c5e0c2011-07-14 13:06:22 -0500428 }
csharptest3b70dd72011-06-11 12:22:17 -0500429 ReadMessage(builder, extensionRegistry);
csharptest0f3540e2011-08-05 20:40:14 -0500430 _depth--;
csharptest3b70dd72011-06-11 12:22:17 -0500431 }
csharptest2b868842011-06-10 14:41:47 -0500432
433 bool ICodedInputStream.ReadBytes(ref ByteString value)
csharptest74c5e0c2011-07-14 13:06:22 -0500434 {
435 return Read(ref value);
436 }
csharptest2b868842011-06-10 14:41:47 -0500437
438 bool ICodedInputStream.ReadUInt32(ref uint value)
csharptest74c5e0c2011-07-14 13:06:22 -0500439 {
440 return Read(ref value);
441 }
csharptest2b868842011-06-10 14:41:47 -0500442
443 bool ICodedInputStream.ReadEnum(ref IEnumLite value, out object unknown, IEnumLiteMap mapping)
444 {
445 value = null;
446 unknown = null;
csharptest74c5e0c2011-07-14 13:06:22 -0500447 if (ReadEnum(ref unknown))
csharptest2b868842011-06-10 14:41:47 -0500448 {
csharptest74c5e0c2011-07-14 13:06:22 -0500449 if (unknown is int)
450 {
451 value = mapping.FindValueByNumber((int) unknown);
452 }
453 else if (unknown is string)
454 {
455 value = mapping.FindValueByName((string) unknown);
456 }
csharptest2b868842011-06-10 14:41:47 -0500457 return value != null;
458 }
459 return false;
460 }
461
462 bool ICodedInputStream.ReadEnum<T>(ref T value, out object rawValue)
463 {
464 rawValue = null;
465 if (ReadEnum(ref rawValue))
466 {
csharptest74c5e0c2011-07-14 13:06:22 -0500467 if (Enum.IsDefined(typeof (T), rawValue))
csharptest2b868842011-06-10 14:41:47 -0500468 {
469 if (rawValue is int)
csharptest74c5e0c2011-07-14 13:06:22 -0500470 {
471 value = (T) rawValue;
472 }
csharptest2b868842011-06-10 14:41:47 -0500473 else if (rawValue is string)
csharptest74c5e0c2011-07-14 13:06:22 -0500474 {
475 value = (T) Enum.Parse(typeof (T), (string) rawValue, false);
476 }
csharptest2b868842011-06-10 14:41:47 -0500477 else
478 {
479 value = default(T);
480 return false;
481 }
482 return true;
483 }
484 }
485 return false;
486 }
487
488 bool ICodedInputStream.ReadSFixed32(ref int value)
csharptest74c5e0c2011-07-14 13:06:22 -0500489 {
490 return Read(ref value);
491 }
csharptest2b868842011-06-10 14:41:47 -0500492
493 bool ICodedInputStream.ReadSFixed64(ref long value)
csharptest74c5e0c2011-07-14 13:06:22 -0500494 {
495 return Read(ref value);
496 }
csharptest2b868842011-06-10 14:41:47 -0500497
498 bool ICodedInputStream.ReadSInt32(ref int value)
csharptest74c5e0c2011-07-14 13:06:22 -0500499 {
500 return Read(ref value);
501 }
csharptest2b868842011-06-10 14:41:47 -0500502
503 bool ICodedInputStream.ReadSInt64(ref long value)
csharptest74c5e0c2011-07-14 13:06:22 -0500504 {
505 return Read(ref value);
506 }
csharptest2b868842011-06-10 14:41:47 -0500507
csharptest74c5e0c2011-07-14 13:06:22 -0500508 void ICodedInputStream.ReadPrimitiveArray(FieldType fieldType, uint fieldTag, string fieldName,
509 ICollection<object> list)
510 {
511 ReadArray(fieldType, fieldName, list);
512 }
csharptest2b868842011-06-10 14:41:47 -0500513
csharptest74c5e0c2011-07-14 13:06:22 -0500514 void ICodedInputStream.ReadEnumArray(uint fieldTag, string fieldName, ICollection<IEnumLite> list,
515 out ICollection<object> unknown, IEnumLiteMap mapping)
csharptest2b868842011-06-10 14:41:47 -0500516 {
517 unknown = null;
518 List<object> array = new List<object>();
519 if (ReadEnumArray(fieldName, array))
520 {
521 foreach (object rawValue in array)
522 {
523 IEnumLite item = null;
csharptest74c5e0c2011-07-14 13:06:22 -0500524 if (rawValue is int)
525 {
526 item = mapping.FindValueByNumber((int) rawValue);
527 }
528 else if (rawValue is string)
529 {
530 item = mapping.FindValueByName((string) rawValue);
531 }
csharptest2b868842011-06-10 14:41:47 -0500532
533 if (item != null)
csharptest74c5e0c2011-07-14 13:06:22 -0500534 {
csharptest2b868842011-06-10 14:41:47 -0500535 list.Add(item);
csharptest74c5e0c2011-07-14 13:06:22 -0500536 }
csharptest2b868842011-06-10 14:41:47 -0500537 else
538 {
csharptest74c5e0c2011-07-14 13:06:22 -0500539 if (unknown == null)
540 {
541 unknown = new List<object>();
542 }
csharptest2b868842011-06-10 14:41:47 -0500543 unknown.Add(rawValue);
544 }
545 }
546 }
547 }
548
csharptest74c5e0c2011-07-14 13:06:22 -0500549 void ICodedInputStream.ReadEnumArray<T>(uint fieldTag, string fieldName, ICollection<T> list,
550 out ICollection<object> unknown)
csharptest2b868842011-06-10 14:41:47 -0500551 {
552 unknown = null;
553 List<object> array = new List<object>();
554 if (ReadEnumArray(fieldName, array))
555 {
556 foreach (object rawValue in array)
557 {
558 if (rawValue is int)
csharptest74c5e0c2011-07-14 13:06:22 -0500559 {
560 list.Add((T) rawValue);
561 }
csharptest2b868842011-06-10 14:41:47 -0500562 else if (rawValue is string)
csharptest74c5e0c2011-07-14 13:06:22 -0500563 {
564 list.Add((T) Enum.Parse(typeof (T), (string) rawValue, false));
565 }
csharptest2b868842011-06-10 14:41:47 -0500566 else
567 {
csharptest74c5e0c2011-07-14 13:06:22 -0500568 if (unknown == null)
569 {
570 unknown = new List<object>();
571 }
csharptest2b868842011-06-10 14:41:47 -0500572 unknown.Add(rawValue);
573 }
574 }
575 }
576 }
577
csharptest74c5e0c2011-07-14 13:06:22 -0500578 void ICodedInputStream.ReadMessageArray<T>(uint fieldTag, string fieldName, ICollection<T> list, T messageType,
579 ExtensionRegistry registry)
csharptest3b70dd72011-06-11 12:22:17 -0500580 {
csharptest0f3540e2011-08-05 20:40:14 -0500581 if (_depth++ > MaxDepth)
csharptest74c5e0c2011-07-14 13:06:22 -0500582 {
csharptest0f3540e2011-08-05 20:40:14 -0500583 throw new RecursionLimitExceededException();
csharptest74c5e0c2011-07-14 13:06:22 -0500584 }
csharptest3b70dd72011-06-11 12:22:17 -0500585 ReadMessageArray(fieldName, list, messageType, registry);
csharptest0f3540e2011-08-05 20:40:14 -0500586 _depth--;
csharptest3b70dd72011-06-11 12:22:17 -0500587 }
csharptest2b868842011-06-10 14:41:47 -0500588
csharptest74c5e0c2011-07-14 13:06:22 -0500589 void ICodedInputStream.ReadGroupArray<T>(uint fieldTag, string fieldName, ICollection<T> list, T messageType,
590 ExtensionRegistry registry)
csharptest3b70dd72011-06-11 12:22:17 -0500591 {
csharptest0f3540e2011-08-05 20:40:14 -0500592 if (_depth++ > MaxDepth)
csharptest74c5e0c2011-07-14 13:06:22 -0500593 {
csharptest0f3540e2011-08-05 20:40:14 -0500594 throw new RecursionLimitExceededException();
csharptest74c5e0c2011-07-14 13:06:22 -0500595 }
csharptest3b70dd72011-06-11 12:22:17 -0500596 ReadGroupArray(fieldName, list, messageType, registry);
csharptest0f3540e2011-08-05 20:40:14 -0500597 _depth--;
csharptest3b70dd72011-06-11 12:22:17 -0500598 }
csharptest2b868842011-06-10 14:41:47 -0500599
600 bool ICodedInputStream.ReadPrimitiveField(FieldType fieldType, ref object value)
csharptest74c5e0c2011-07-14 13:06:22 -0500601 {
602 return ReadField(fieldType, ref value);
603 }
csharptest2b868842011-06-10 14:41:47 -0500604
605 bool ICodedInputStream.IsAtEnd
606 {
csharptest74c5e0c2011-07-14 13:06:22 -0500607 get
608 {
609 string next;
610 return PeekNext(out next) == false;
611 }
csharptest2b868842011-06-10 14:41:47 -0500612 }
613
614 bool ICodedInputStream.SkipField()
615 {
616 Skip();
617 return true;
618 }
619
620 void ICodedInputStream.ReadStringArray(uint fieldTag, string fieldName, ICollection<string> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500621 {
622 ReadArray(FieldType.String, fieldName, list);
623 }
csharptest2b868842011-06-10 14:41:47 -0500624
625 void ICodedInputStream.ReadBytesArray(uint fieldTag, string fieldName, ICollection<ByteString> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500626 {
627 ReadArray(FieldType.Bytes, fieldName, list);
628 }
csharptest2b868842011-06-10 14:41:47 -0500629
630 void ICodedInputStream.ReadBoolArray(uint fieldTag, string fieldName, ICollection<bool> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500631 {
632 ReadArray(FieldType.Bool, fieldName, list);
633 }
csharptest2b868842011-06-10 14:41:47 -0500634
635 void ICodedInputStream.ReadInt32Array(uint fieldTag, string fieldName, ICollection<int> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500636 {
637 ReadArray(FieldType.Int32, fieldName, list);
638 }
csharptest2b868842011-06-10 14:41:47 -0500639
640 void ICodedInputStream.ReadSInt32Array(uint fieldTag, string fieldName, ICollection<int> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500641 {
642 ReadArray(FieldType.SInt32, fieldName, list);
643 }
csharptest2b868842011-06-10 14:41:47 -0500644
645 void ICodedInputStream.ReadUInt32Array(uint fieldTag, string fieldName, ICollection<uint> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500646 {
647 ReadArray(FieldType.UInt32, fieldName, list);
648 }
csharptest2b868842011-06-10 14:41:47 -0500649
650 void ICodedInputStream.ReadFixed32Array(uint fieldTag, string fieldName, ICollection<uint> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500651 {
652 ReadArray(FieldType.Fixed32, fieldName, list);
653 }
csharptest2b868842011-06-10 14:41:47 -0500654
655 void ICodedInputStream.ReadSFixed32Array(uint fieldTag, string fieldName, ICollection<int> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500656 {
657 ReadArray(FieldType.SFixed32, fieldName, list);
658 }
csharptest2b868842011-06-10 14:41:47 -0500659
660 void ICodedInputStream.ReadInt64Array(uint fieldTag, string fieldName, ICollection<long> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500661 {
662 ReadArray(FieldType.Int64, fieldName, list);
663 }
csharptest2b868842011-06-10 14:41:47 -0500664
665 void ICodedInputStream.ReadSInt64Array(uint fieldTag, string fieldName, ICollection<long> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500666 {
667 ReadArray(FieldType.SInt64, fieldName, list);
668 }
csharptest2b868842011-06-10 14:41:47 -0500669
670 void ICodedInputStream.ReadUInt64Array(uint fieldTag, string fieldName, ICollection<ulong> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500671 {
672 ReadArray(FieldType.UInt64, fieldName, list);
673 }
csharptest2b868842011-06-10 14:41:47 -0500674
675 void ICodedInputStream.ReadFixed64Array(uint fieldTag, string fieldName, ICollection<ulong> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500676 {
677 ReadArray(FieldType.Fixed64, fieldName, list);
678 }
csharptest2b868842011-06-10 14:41:47 -0500679
680 void ICodedInputStream.ReadSFixed64Array(uint fieldTag, string fieldName, ICollection<long> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500681 {
682 ReadArray(FieldType.SFixed64, fieldName, list);
683 }
csharptest2b868842011-06-10 14:41:47 -0500684
685 void ICodedInputStream.ReadDoubleArray(uint fieldTag, string fieldName, ICollection<double> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500686 {
687 ReadArray(FieldType.Double, fieldName, list);
688 }
csharptest2b868842011-06-10 14:41:47 -0500689
690 void ICodedInputStream.ReadFloatArray(uint fieldTag, string fieldName, ICollection<float> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500691 {
692 ReadArray(FieldType.Float, fieldName, list);
693 }
csharptest2b868842011-06-10 14:41:47 -0500694
695 #endregion
696 }
csharptest74c5e0c2011-07-14 13:06:22 -0500697}