blob: bc1fa6cd674eec766b5f8ead38cdb3af6dac7f7c [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 {
csharptest74c5e0c2011-07-14 13:06:22 -050015 private const int MaxDepth = CodedInputStream.DefaultRecursionLimit;
csharptest6c693732011-06-11 12:30:15 -050016 protected int Depth;
csharptest3b70dd72011-06-11 12:22:17 -050017
csharptest2b868842011-06-10 14:41:47 -050018 /// <summary>
19 /// Merges the contents of stream into the provided message builder
20 /// </summary>
21 public TBuilder Merge<TBuilder>(TBuilder builder) where TBuilder : IBuilderLite
csharptest74c5e0c2011-07-14 13:06:22 -050022 {
23 return Merge(builder, ExtensionRegistry.Empty);
24 }
csharptest2b868842011-06-10 14:41:47 -050025
26 /// <summary>
27 /// Merges the contents of stream into the provided message builder
28 /// </summary>
csharptest74c5e0c2011-07-14 13:06:22 -050029 public abstract TBuilder Merge<TBuilder>(TBuilder builder, ExtensionRegistry registry)
30 where TBuilder : IBuilderLite;
csharptest2b868842011-06-10 14:41:47 -050031
32 /// <summary>
33 /// Peeks at the next field in the input stream and returns what information is available.
34 /// </summary>
35 /// <remarks>
36 /// This may be called multiple times without actually reading the field. Only after the field
37 /// is either read, or skipped, should PeekNext return a different value.
38 /// </remarks>
39 protected abstract bool PeekNext(out string field);
40
41 /// <summary>
42 /// Causes the reader to skip past this field
43 /// </summary>
44 protected abstract void Skip();
45
46 /// <summary>
47 /// Returns true if it was able to read a Boolean from the input
48 /// </summary>
49 protected abstract bool Read(ref bool value);
50
51 /// <summary>
52 /// Returns true if it was able to read a Int32 from the input
53 /// </summary>
54 protected abstract bool Read(ref int value);
55
56 /// <summary>
57 /// Returns true if it was able to read a UInt32 from the input
58 /// </summary>
59 [CLSCompliant(false)]
60 protected abstract bool Read(ref uint value);
61
62 /// <summary>
63 /// Returns true if it was able to read a Int64 from the input
64 /// </summary>
65 protected abstract bool Read(ref long value);
66
67 /// <summary>
68 /// Returns true if it was able to read a UInt64 from the input
69 /// </summary>
70 [CLSCompliant(false)]
71 protected abstract bool Read(ref ulong value);
72
73 /// <summary>
74 /// Returns true if it was able to read a Single from the input
75 /// </summary>
76 protected abstract bool Read(ref float value);
77
78 /// <summary>
79 /// Returns true if it was able to read a Double from the input
80 /// </summary>
81 protected abstract bool Read(ref double value);
82
83 /// <summary>
84 /// Returns true if it was able to read a String from the input
85 /// </summary>
86 protected abstract bool Read(ref string value);
87
88 /// <summary>
89 /// Returns true if it was able to read a ByteString from the input
90 /// </summary>
91 protected abstract bool Read(ref ByteString value);
92
93 /// <summary>
94 /// returns true if it was able to read a single value into the value reference. The value
95 /// stored may be of type System.String, System.Int32, or an IEnumLite from the IEnumLiteMap.
96 /// </summary>
97 protected abstract bool ReadEnum(ref object value);
98
99 /// <summary>
100 /// Merges the input stream into the provided IBuilderLite
101 /// </summary>
102 protected abstract bool ReadMessage(IBuilderLite builder, ExtensionRegistry registry);
103
104 /// <summary>
105 /// Merges the input stream into the provided IBuilderLite
106 /// </summary>
107 public virtual bool ReadGroup(IBuilderLite value, ExtensionRegistry registry)
108 {
109 return ReadMessage(value, registry);
110 }
111
112 /// <summary>
113 /// Cursors through the array elements and stops at the end of the array
114 /// </summary>
115 protected virtual IEnumerable<string> ForeachArrayItem(string field)
116 {
117 string next = field;
118 while (true)
119 {
120 yield return next;
121
122 if (!PeekNext(out next) || next != field)
csharptest74c5e0c2011-07-14 13:06:22 -0500123 {
csharptest2b868842011-06-10 14:41:47 -0500124 break;
csharptest74c5e0c2011-07-14 13:06:22 -0500125 }
csharptest2b868842011-06-10 14:41:47 -0500126 }
127 }
128
129 /// <summary>
130 /// Reads an array of T messages
131 /// </summary>
csharptest74c5e0c2011-07-14 13:06:22 -0500132 public virtual bool ReadMessageArray<T>(string field, ICollection<T> items, IMessageLite messageType,
133 ExtensionRegistry registry)
csharptest2b868842011-06-10 14:41:47 -0500134 {
135 bool success = false;
136 foreach (string next in ForeachArrayItem(field))
137 {
138 IBuilderLite builder = messageType.WeakCreateBuilderForType();
139 if (ReadMessage(builder, registry))
140 {
csharptest74c5e0c2011-07-14 13:06:22 -0500141 items.Add((T) builder.WeakBuild());
csharptest2b868842011-06-10 14:41:47 -0500142 success |= true;
143 }
144 }
145 return success;
146 }
147
148 /// <summary>
149 /// Reads an array of T messages as a proto-buffer group
150 /// </summary>
csharptest74c5e0c2011-07-14 13:06:22 -0500151 public virtual bool ReadGroupArray<T>(string field, ICollection<T> items, IMessageLite messageType,
152 ExtensionRegistry registry)
csharptest2b868842011-06-10 14:41:47 -0500153 {
154 bool success = false;
155 foreach (string next in ForeachArrayItem(field))
156 {
157 IBuilderLite builder = messageType.WeakCreateBuilderForType();
158 if (ReadGroup(builder, registry))
159 {
csharptest74c5e0c2011-07-14 13:06:22 -0500160 items.Add((T) builder.WeakBuild());
csharptest2b868842011-06-10 14:41:47 -0500161 success |= true;
162 }
163 }
164 return success;
165 }
166
167 /// <summary>
168 /// Reads an array of System.Enum type T and adds them to the collection
169 /// </summary>
170 public virtual bool ReadEnumArray(string field, ICollection<object> items)
171 {
172 bool success = false;
173 foreach (string next in ForeachArrayItem(field))
174 {
175 object temp = null;
176 if (ReadEnum(ref temp))
177 {
178 items.Add(temp);
179 success |= true;
180 }
181 }
182 return success;
183 }
184
185 /// <summary>
186 /// Reads an array of T, where T is a primitive type defined by FieldType
187 /// </summary>
188 public virtual bool ReadArray<T>(FieldType type, string field, ICollection<T> items)
189 {
190 bool success = false;
191 foreach (string next in ForeachArrayItem(field))
192 {
193 object temp = null;
194 if (ReadField(type, ref temp))
195 {
csharptest74c5e0c2011-07-14 13:06:22 -0500196 items.Add((T) temp);
csharptest2b868842011-06-10 14:41:47 -0500197 success |= true;
198 }
199 }
200 return success;
201 }
202
203 /// <summary>
204 /// returns true if it was able to read a single primitive value of FieldType into the value reference
205 /// </summary>
206 public virtual bool ReadField(FieldType type, ref object value)
207 {
208 switch (type)
209 {
210 case FieldType.Bool:
211 {
212 bool temp = false;
213 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500214 {
csharptest2b868842011-06-10 14:41:47 -0500215 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500216 }
csharptest2b868842011-06-10 14:41:47 -0500217 else
csharptest74c5e0c2011-07-14 13:06:22 -0500218 {
csharptest2b868842011-06-10 14:41:47 -0500219 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500220 }
csharptest2b868842011-06-10 14:41:47 -0500221 break;
222 }
223 case FieldType.Int64:
224 case FieldType.SInt64:
225 case FieldType.SFixed64:
226 {
227 long temp = 0;
228 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500229 {
csharptest2b868842011-06-10 14:41:47 -0500230 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500231 }
csharptest2b868842011-06-10 14:41:47 -0500232 else
csharptest74c5e0c2011-07-14 13:06:22 -0500233 {
csharptest2b868842011-06-10 14:41:47 -0500234 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500235 }
csharptest2b868842011-06-10 14:41:47 -0500236 break;
237 }
238 case FieldType.UInt64:
239 case FieldType.Fixed64:
240 {
241 ulong temp = 0;
242 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500243 {
csharptest2b868842011-06-10 14:41:47 -0500244 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500245 }
csharptest2b868842011-06-10 14:41:47 -0500246 else
csharptest74c5e0c2011-07-14 13:06:22 -0500247 {
csharptest2b868842011-06-10 14:41:47 -0500248 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500249 }
csharptest2b868842011-06-10 14:41:47 -0500250 break;
251 }
252 case FieldType.Int32:
253 case FieldType.SInt32:
254 case FieldType.SFixed32:
255 {
256 int temp = 0;
257 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500258 {
csharptest2b868842011-06-10 14:41:47 -0500259 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500260 }
csharptest2b868842011-06-10 14:41:47 -0500261 else
csharptest74c5e0c2011-07-14 13:06:22 -0500262 {
csharptest2b868842011-06-10 14:41:47 -0500263 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500264 }
csharptest2b868842011-06-10 14:41:47 -0500265 break;
266 }
267 case FieldType.UInt32:
268 case FieldType.Fixed32:
269 {
270 uint temp = 0;
271 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500272 {
csharptest2b868842011-06-10 14:41:47 -0500273 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500274 }
csharptest2b868842011-06-10 14:41:47 -0500275 else
csharptest74c5e0c2011-07-14 13:06:22 -0500276 {
csharptest2b868842011-06-10 14:41:47 -0500277 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500278 }
csharptest2b868842011-06-10 14:41:47 -0500279 break;
280 }
281 case FieldType.Float:
282 {
283 float temp = float.NaN;
284 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500285 {
csharptest2b868842011-06-10 14:41:47 -0500286 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500287 }
csharptest2b868842011-06-10 14:41:47 -0500288 else
csharptest74c5e0c2011-07-14 13:06:22 -0500289 {
csharptest2b868842011-06-10 14:41:47 -0500290 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500291 }
csharptest2b868842011-06-10 14:41:47 -0500292 break;
293 }
294 case FieldType.Double:
295 {
296 double temp = float.NaN;
297 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500298 {
csharptest2b868842011-06-10 14:41:47 -0500299 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500300 }
csharptest2b868842011-06-10 14:41:47 -0500301 else
csharptest74c5e0c2011-07-14 13:06:22 -0500302 {
csharptest2b868842011-06-10 14:41:47 -0500303 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500304 }
csharptest2b868842011-06-10 14:41:47 -0500305 break;
306 }
307 case FieldType.String:
308 {
309 string temp = null;
310 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500311 {
csharptest2b868842011-06-10 14:41:47 -0500312 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500313 }
csharptest2b868842011-06-10 14:41:47 -0500314 else
csharptest74c5e0c2011-07-14 13:06:22 -0500315 {
csharptest2b868842011-06-10 14:41:47 -0500316 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500317 }
csharptest2b868842011-06-10 14:41:47 -0500318 break;
319 }
320 case FieldType.Bytes:
321 {
322 ByteString temp = null;
323 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500324 {
csharptest2b868842011-06-10 14:41:47 -0500325 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500326 }
csharptest2b868842011-06-10 14:41:47 -0500327 else
csharptest74c5e0c2011-07-14 13:06:22 -0500328 {
csharptest2b868842011-06-10 14:41:47 -0500329 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500330 }
csharptest2b868842011-06-10 14:41:47 -0500331 break;
332 }
333 default:
334 throw InvalidProtocolBufferException.InvalidTag();
335 }
336 return true;
337 }
338
339 #region ICodedInputStream Members
340
341 bool ICodedInputStream.ReadTag(out uint fieldTag, out string fieldName)
342 {
343 fieldTag = 0;
344 if (PeekNext(out fieldName))
345 {
346 return true;
347 }
348 return false;
349 }
350
351 bool ICodedInputStream.ReadDouble(ref double value)
csharptest74c5e0c2011-07-14 13:06:22 -0500352 {
353 return Read(ref value);
354 }
csharptest2b868842011-06-10 14:41:47 -0500355
356 bool ICodedInputStream.ReadFloat(ref float value)
csharptest74c5e0c2011-07-14 13:06:22 -0500357 {
358 return Read(ref value);
359 }
csharptest2b868842011-06-10 14:41:47 -0500360
361 bool ICodedInputStream.ReadUInt64(ref ulong value)
csharptest74c5e0c2011-07-14 13:06:22 -0500362 {
363 return Read(ref value);
364 }
csharptest2b868842011-06-10 14:41:47 -0500365
366 bool ICodedInputStream.ReadInt64(ref long value)
csharptest74c5e0c2011-07-14 13:06:22 -0500367 {
368 return Read(ref value);
369 }
csharptest2b868842011-06-10 14:41:47 -0500370
371 bool ICodedInputStream.ReadInt32(ref int value)
csharptest74c5e0c2011-07-14 13:06:22 -0500372 {
373 return Read(ref value);
374 }
csharptest2b868842011-06-10 14:41:47 -0500375
376 bool ICodedInputStream.ReadFixed64(ref ulong value)
csharptest74c5e0c2011-07-14 13:06:22 -0500377 {
378 return Read(ref value);
379 }
csharptest2b868842011-06-10 14:41:47 -0500380
381 bool ICodedInputStream.ReadFixed32(ref uint value)
csharptest74c5e0c2011-07-14 13:06:22 -0500382 {
383 return Read(ref value);
384 }
csharptest2b868842011-06-10 14:41:47 -0500385
386 bool ICodedInputStream.ReadBool(ref bool value)
csharptest74c5e0c2011-07-14 13:06:22 -0500387 {
388 return Read(ref value);
389 }
csharptest2b868842011-06-10 14:41:47 -0500390
391 bool ICodedInputStream.ReadString(ref string value)
csharptest74c5e0c2011-07-14 13:06:22 -0500392 {
393 return Read(ref value);
394 }
csharptest2b868842011-06-10 14:41:47 -0500395
396 void ICodedInputStream.ReadGroup(int fieldNumber, IBuilderLite builder, ExtensionRegistry extensionRegistry)
csharptest3b70dd72011-06-11 12:22:17 -0500397 {
csharptest6c693732011-06-11 12:30:15 -0500398 if (Depth++ > MaxDepth)
csharptest74c5e0c2011-07-14 13:06:22 -0500399 {
csharptest3b70dd72011-06-11 12:22:17 -0500400 throw InvalidProtocolBufferException.RecursionLimitExceeded();
csharptest74c5e0c2011-07-14 13:06:22 -0500401 }
csharptest3b70dd72011-06-11 12:22:17 -0500402 ReadGroup(builder, extensionRegistry);
csharptest6c693732011-06-11 12:30:15 -0500403 Depth--;
csharptest3b70dd72011-06-11 12:22:17 -0500404 }
csharptest2b868842011-06-10 14:41:47 -0500405
406 void ICodedInputStream.ReadUnknownGroup(int fieldNumber, IBuilderLite builder)
csharptest74c5e0c2011-07-14 13:06:22 -0500407 {
408 throw new NotSupportedException();
409 }
csharptest2b868842011-06-10 14:41:47 -0500410
411 void ICodedInputStream.ReadMessage(IBuilderLite builder, ExtensionRegistry extensionRegistry)
csharptest3b70dd72011-06-11 12:22:17 -0500412 {
csharptest6c693732011-06-11 12:30:15 -0500413 if (Depth++ > MaxDepth)
csharptest74c5e0c2011-07-14 13:06:22 -0500414 {
415 throw InvalidProtocolBufferException.RecursionLimitExceeded();
416 }
csharptest3b70dd72011-06-11 12:22:17 -0500417 ReadMessage(builder, extensionRegistry);
csharptest6c693732011-06-11 12:30:15 -0500418 Depth--;
csharptest3b70dd72011-06-11 12:22:17 -0500419 }
csharptest2b868842011-06-10 14:41:47 -0500420
421 bool ICodedInputStream.ReadBytes(ref ByteString value)
csharptest74c5e0c2011-07-14 13:06:22 -0500422 {
423 return Read(ref value);
424 }
csharptest2b868842011-06-10 14:41:47 -0500425
426 bool ICodedInputStream.ReadUInt32(ref uint value)
csharptest74c5e0c2011-07-14 13:06:22 -0500427 {
428 return Read(ref value);
429 }
csharptest2b868842011-06-10 14:41:47 -0500430
431 bool ICodedInputStream.ReadEnum(ref IEnumLite value, out object unknown, IEnumLiteMap mapping)
432 {
433 value = null;
434 unknown = null;
csharptest74c5e0c2011-07-14 13:06:22 -0500435 if (ReadEnum(ref unknown))
csharptest2b868842011-06-10 14:41:47 -0500436 {
csharptest74c5e0c2011-07-14 13:06:22 -0500437 if (unknown is int)
438 {
439 value = mapping.FindValueByNumber((int) unknown);
440 }
441 else if (unknown is string)
442 {
443 value = mapping.FindValueByName((string) unknown);
444 }
csharptest2b868842011-06-10 14:41:47 -0500445 return value != null;
446 }
447 return false;
448 }
449
450 bool ICodedInputStream.ReadEnum<T>(ref T value, out object rawValue)
451 {
452 rawValue = null;
453 if (ReadEnum(ref rawValue))
454 {
csharptest74c5e0c2011-07-14 13:06:22 -0500455 if (Enum.IsDefined(typeof (T), rawValue))
csharptest2b868842011-06-10 14:41:47 -0500456 {
457 if (rawValue is int)
csharptest74c5e0c2011-07-14 13:06:22 -0500458 {
459 value = (T) rawValue;
460 }
csharptest2b868842011-06-10 14:41:47 -0500461 else if (rawValue is string)
csharptest74c5e0c2011-07-14 13:06:22 -0500462 {
463 value = (T) Enum.Parse(typeof (T), (string) rawValue, false);
464 }
csharptest2b868842011-06-10 14:41:47 -0500465 else
466 {
467 value = default(T);
468 return false;
469 }
470 return true;
471 }
472 }
473 return false;
474 }
475
476 bool ICodedInputStream.ReadSFixed32(ref int value)
csharptest74c5e0c2011-07-14 13:06:22 -0500477 {
478 return Read(ref value);
479 }
csharptest2b868842011-06-10 14:41:47 -0500480
481 bool ICodedInputStream.ReadSFixed64(ref long value)
csharptest74c5e0c2011-07-14 13:06:22 -0500482 {
483 return Read(ref value);
484 }
csharptest2b868842011-06-10 14:41:47 -0500485
486 bool ICodedInputStream.ReadSInt32(ref int value)
csharptest74c5e0c2011-07-14 13:06:22 -0500487 {
488 return Read(ref value);
489 }
csharptest2b868842011-06-10 14:41:47 -0500490
491 bool ICodedInputStream.ReadSInt64(ref long value)
csharptest74c5e0c2011-07-14 13:06:22 -0500492 {
493 return Read(ref value);
494 }
csharptest2b868842011-06-10 14:41:47 -0500495
csharptest74c5e0c2011-07-14 13:06:22 -0500496 void ICodedInputStream.ReadPrimitiveArray(FieldType fieldType, uint fieldTag, string fieldName,
497 ICollection<object> list)
498 {
499 ReadArray(fieldType, fieldName, list);
500 }
csharptest2b868842011-06-10 14:41:47 -0500501
csharptest74c5e0c2011-07-14 13:06:22 -0500502 void ICodedInputStream.ReadEnumArray(uint fieldTag, string fieldName, ICollection<IEnumLite> list,
503 out ICollection<object> unknown, IEnumLiteMap mapping)
csharptest2b868842011-06-10 14:41:47 -0500504 {
505 unknown = null;
506 List<object> array = new List<object>();
507 if (ReadEnumArray(fieldName, array))
508 {
509 foreach (object rawValue in array)
510 {
511 IEnumLite item = null;
csharptest74c5e0c2011-07-14 13:06:22 -0500512 if (rawValue is int)
513 {
514 item = mapping.FindValueByNumber((int) rawValue);
515 }
516 else if (rawValue is string)
517 {
518 item = mapping.FindValueByName((string) rawValue);
519 }
csharptest2b868842011-06-10 14:41:47 -0500520
521 if (item != null)
csharptest74c5e0c2011-07-14 13:06:22 -0500522 {
csharptest2b868842011-06-10 14:41:47 -0500523 list.Add(item);
csharptest74c5e0c2011-07-14 13:06:22 -0500524 }
csharptest2b868842011-06-10 14:41:47 -0500525 else
526 {
csharptest74c5e0c2011-07-14 13:06:22 -0500527 if (unknown == null)
528 {
529 unknown = new List<object>();
530 }
csharptest2b868842011-06-10 14:41:47 -0500531 unknown.Add(rawValue);
532 }
533 }
534 }
535 }
536
csharptest74c5e0c2011-07-14 13:06:22 -0500537 void ICodedInputStream.ReadEnumArray<T>(uint fieldTag, string fieldName, ICollection<T> list,
538 out ICollection<object> unknown)
csharptest2b868842011-06-10 14:41:47 -0500539 {
540 unknown = null;
541 List<object> array = new List<object>();
542 if (ReadEnumArray(fieldName, array))
543 {
544 foreach (object rawValue in array)
545 {
546 if (rawValue is int)
csharptest74c5e0c2011-07-14 13:06:22 -0500547 {
548 list.Add((T) rawValue);
549 }
csharptest2b868842011-06-10 14:41:47 -0500550 else if (rawValue is string)
csharptest74c5e0c2011-07-14 13:06:22 -0500551 {
552 list.Add((T) Enum.Parse(typeof (T), (string) rawValue, false));
553 }
csharptest2b868842011-06-10 14:41:47 -0500554 else
555 {
csharptest74c5e0c2011-07-14 13:06:22 -0500556 if (unknown == null)
557 {
558 unknown = new List<object>();
559 }
csharptest2b868842011-06-10 14:41:47 -0500560 unknown.Add(rawValue);
561 }
562 }
563 }
564 }
565
csharptest74c5e0c2011-07-14 13:06:22 -0500566 void ICodedInputStream.ReadMessageArray<T>(uint fieldTag, string fieldName, ICollection<T> list, T messageType,
567 ExtensionRegistry registry)
csharptest3b70dd72011-06-11 12:22:17 -0500568 {
csharptest6c693732011-06-11 12:30:15 -0500569 if (Depth++ > MaxDepth)
csharptest74c5e0c2011-07-14 13:06:22 -0500570 {
571 throw InvalidProtocolBufferException.RecursionLimitExceeded();
572 }
csharptest3b70dd72011-06-11 12:22:17 -0500573 ReadMessageArray(fieldName, list, messageType, registry);
csharptest6c693732011-06-11 12:30:15 -0500574 Depth--;
csharptest3b70dd72011-06-11 12:22:17 -0500575 }
csharptest2b868842011-06-10 14:41:47 -0500576
csharptest74c5e0c2011-07-14 13:06:22 -0500577 void ICodedInputStream.ReadGroupArray<T>(uint fieldTag, string fieldName, ICollection<T> list, T messageType,
578 ExtensionRegistry registry)
csharptest3b70dd72011-06-11 12:22:17 -0500579 {
csharptest6c693732011-06-11 12:30:15 -0500580 if (Depth++ > MaxDepth)
csharptest74c5e0c2011-07-14 13:06:22 -0500581 {
csharptest3b70dd72011-06-11 12:22:17 -0500582 throw InvalidProtocolBufferException.RecursionLimitExceeded();
csharptest74c5e0c2011-07-14 13:06:22 -0500583 }
csharptest3b70dd72011-06-11 12:22:17 -0500584 ReadGroupArray(fieldName, list, messageType, registry);
csharptest6c693732011-06-11 12:30:15 -0500585 Depth--;
csharptest3b70dd72011-06-11 12:22:17 -0500586 }
csharptest2b868842011-06-10 14:41:47 -0500587
588 bool ICodedInputStream.ReadPrimitiveField(FieldType fieldType, ref object value)
csharptest74c5e0c2011-07-14 13:06:22 -0500589 {
590 return ReadField(fieldType, ref value);
591 }
csharptest2b868842011-06-10 14:41:47 -0500592
593 bool ICodedInputStream.IsAtEnd
594 {
csharptest74c5e0c2011-07-14 13:06:22 -0500595 get
596 {
597 string next;
598 return PeekNext(out next) == false;
599 }
csharptest2b868842011-06-10 14:41:47 -0500600 }
601
602 bool ICodedInputStream.SkipField()
603 {
604 Skip();
605 return true;
606 }
607
608 void ICodedInputStream.ReadStringArray(uint fieldTag, string fieldName, ICollection<string> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500609 {
610 ReadArray(FieldType.String, fieldName, list);
611 }
csharptest2b868842011-06-10 14:41:47 -0500612
613 void ICodedInputStream.ReadBytesArray(uint fieldTag, string fieldName, ICollection<ByteString> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500614 {
615 ReadArray(FieldType.Bytes, fieldName, list);
616 }
csharptest2b868842011-06-10 14:41:47 -0500617
618 void ICodedInputStream.ReadBoolArray(uint fieldTag, string fieldName, ICollection<bool> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500619 {
620 ReadArray(FieldType.Bool, fieldName, list);
621 }
csharptest2b868842011-06-10 14:41:47 -0500622
623 void ICodedInputStream.ReadInt32Array(uint fieldTag, string fieldName, ICollection<int> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500624 {
625 ReadArray(FieldType.Int32, fieldName, list);
626 }
csharptest2b868842011-06-10 14:41:47 -0500627
628 void ICodedInputStream.ReadSInt32Array(uint fieldTag, string fieldName, ICollection<int> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500629 {
630 ReadArray(FieldType.SInt32, fieldName, list);
631 }
csharptest2b868842011-06-10 14:41:47 -0500632
633 void ICodedInputStream.ReadUInt32Array(uint fieldTag, string fieldName, ICollection<uint> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500634 {
635 ReadArray(FieldType.UInt32, fieldName, list);
636 }
csharptest2b868842011-06-10 14:41:47 -0500637
638 void ICodedInputStream.ReadFixed32Array(uint fieldTag, string fieldName, ICollection<uint> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500639 {
640 ReadArray(FieldType.Fixed32, fieldName, list);
641 }
csharptest2b868842011-06-10 14:41:47 -0500642
643 void ICodedInputStream.ReadSFixed32Array(uint fieldTag, string fieldName, ICollection<int> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500644 {
645 ReadArray(FieldType.SFixed32, fieldName, list);
646 }
csharptest2b868842011-06-10 14:41:47 -0500647
648 void ICodedInputStream.ReadInt64Array(uint fieldTag, string fieldName, ICollection<long> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500649 {
650 ReadArray(FieldType.Int64, fieldName, list);
651 }
csharptest2b868842011-06-10 14:41:47 -0500652
653 void ICodedInputStream.ReadSInt64Array(uint fieldTag, string fieldName, ICollection<long> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500654 {
655 ReadArray(FieldType.SInt64, fieldName, list);
656 }
csharptest2b868842011-06-10 14:41:47 -0500657
658 void ICodedInputStream.ReadUInt64Array(uint fieldTag, string fieldName, ICollection<ulong> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500659 {
660 ReadArray(FieldType.UInt64, fieldName, list);
661 }
csharptest2b868842011-06-10 14:41:47 -0500662
663 void ICodedInputStream.ReadFixed64Array(uint fieldTag, string fieldName, ICollection<ulong> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500664 {
665 ReadArray(FieldType.Fixed64, fieldName, list);
666 }
csharptest2b868842011-06-10 14:41:47 -0500667
668 void ICodedInputStream.ReadSFixed64Array(uint fieldTag, string fieldName, ICollection<long> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500669 {
670 ReadArray(FieldType.SFixed64, fieldName, list);
671 }
csharptest2b868842011-06-10 14:41:47 -0500672
673 void ICodedInputStream.ReadDoubleArray(uint fieldTag, string fieldName, ICollection<double> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500674 {
675 ReadArray(FieldType.Double, fieldName, list);
676 }
csharptest2b868842011-06-10 14:41:47 -0500677
678 void ICodedInputStream.ReadFloatArray(uint fieldTag, string fieldName, ICollection<float> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500679 {
680 ReadArray(FieldType.Float, fieldName, list);
681 }
csharptest2b868842011-06-10 14:41:47 -0500682
683 #endregion
684 }
csharptest74c5e0c2011-07-14 13:06:22 -0500685}