blob: 538af38f7970dfc0f63fc4747fd30fb50badb50b [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);
csharptestc2d2c1a2011-09-08 20:02:11 -0500115
116 /// <summary>
117 /// Reads the root-message preamble specific to this formatter
118 /// </summary>
119 public abstract AbstractReader ReadStartMessage();
120
121 /// <summary>
122 /// Reads the root-message close specific to this formatter
123 /// </summary>
124 public abstract void ReadEndMessage();
csharptest2b868842011-06-10 14:41:47 -0500125
126 /// <summary>
127 /// Merges the input stream into the provided IBuilderLite
128 /// </summary>
129 public virtual bool ReadGroup(IBuilderLite value, ExtensionRegistry registry)
130 {
131 return ReadMessage(value, registry);
132 }
133
134 /// <summary>
135 /// Cursors through the array elements and stops at the end of the array
136 /// </summary>
137 protected virtual IEnumerable<string> ForeachArrayItem(string field)
138 {
139 string next = field;
140 while (true)
141 {
142 yield return next;
143
144 if (!PeekNext(out next) || next != field)
csharptest74c5e0c2011-07-14 13:06:22 -0500145 {
csharptest2b868842011-06-10 14:41:47 -0500146 break;
csharptest74c5e0c2011-07-14 13:06:22 -0500147 }
csharptest2b868842011-06-10 14:41:47 -0500148 }
149 }
150
151 /// <summary>
152 /// Reads an array of T messages
153 /// </summary>
csharptest74c5e0c2011-07-14 13:06:22 -0500154 public virtual bool ReadMessageArray<T>(string field, ICollection<T> items, IMessageLite messageType,
155 ExtensionRegistry registry)
csharptest2b868842011-06-10 14:41:47 -0500156 {
157 bool success = false;
158 foreach (string next in ForeachArrayItem(field))
159 {
160 IBuilderLite builder = messageType.WeakCreateBuilderForType();
161 if (ReadMessage(builder, registry))
162 {
csharptest74c5e0c2011-07-14 13:06:22 -0500163 items.Add((T) builder.WeakBuild());
csharptest2b868842011-06-10 14:41:47 -0500164 success |= true;
165 }
166 }
167 return success;
168 }
169
170 /// <summary>
171 /// Reads an array of T messages as a proto-buffer group
172 /// </summary>
csharptest74c5e0c2011-07-14 13:06:22 -0500173 public virtual bool ReadGroupArray<T>(string field, ICollection<T> items, IMessageLite messageType,
174 ExtensionRegistry registry)
csharptest2b868842011-06-10 14:41:47 -0500175 {
176 bool success = false;
177 foreach (string next in ForeachArrayItem(field))
178 {
179 IBuilderLite builder = messageType.WeakCreateBuilderForType();
180 if (ReadGroup(builder, registry))
181 {
csharptest74c5e0c2011-07-14 13:06:22 -0500182 items.Add((T) builder.WeakBuild());
csharptest2b868842011-06-10 14:41:47 -0500183 success |= true;
184 }
185 }
186 return success;
187 }
188
189 /// <summary>
190 /// Reads an array of System.Enum type T and adds them to the collection
191 /// </summary>
192 public virtual bool ReadEnumArray(string field, ICollection<object> items)
193 {
194 bool success = false;
195 foreach (string next in ForeachArrayItem(field))
196 {
197 object temp = null;
198 if (ReadEnum(ref temp))
199 {
200 items.Add(temp);
201 success |= true;
202 }
203 }
204 return success;
205 }
206
207 /// <summary>
208 /// Reads an array of T, where T is a primitive type defined by FieldType
209 /// </summary>
210 public virtual bool ReadArray<T>(FieldType type, string field, ICollection<T> items)
211 {
212 bool success = false;
213 foreach (string next in ForeachArrayItem(field))
214 {
215 object temp = null;
216 if (ReadField(type, ref temp))
217 {
csharptest74c5e0c2011-07-14 13:06:22 -0500218 items.Add((T) temp);
csharptest2b868842011-06-10 14:41:47 -0500219 success |= true;
220 }
221 }
222 return success;
223 }
224
225 /// <summary>
226 /// returns true if it was able to read a single primitive value of FieldType into the value reference
227 /// </summary>
228 public virtual bool ReadField(FieldType type, ref object value)
229 {
230 switch (type)
231 {
232 case FieldType.Bool:
233 {
234 bool temp = false;
235 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500236 {
csharptest2b868842011-06-10 14:41:47 -0500237 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500238 }
csharptest2b868842011-06-10 14:41:47 -0500239 else
csharptest74c5e0c2011-07-14 13:06:22 -0500240 {
csharptest2b868842011-06-10 14:41:47 -0500241 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500242 }
csharptest2b868842011-06-10 14:41:47 -0500243 break;
244 }
245 case FieldType.Int64:
246 case FieldType.SInt64:
247 case FieldType.SFixed64:
248 {
249 long temp = 0;
250 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500251 {
csharptest2b868842011-06-10 14:41:47 -0500252 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500253 }
csharptest2b868842011-06-10 14:41:47 -0500254 else
csharptest74c5e0c2011-07-14 13:06:22 -0500255 {
csharptest2b868842011-06-10 14:41:47 -0500256 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500257 }
csharptest2b868842011-06-10 14:41:47 -0500258 break;
259 }
260 case FieldType.UInt64:
261 case FieldType.Fixed64:
262 {
263 ulong temp = 0;
264 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500265 {
csharptest2b868842011-06-10 14:41:47 -0500266 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500267 }
csharptest2b868842011-06-10 14:41:47 -0500268 else
csharptest74c5e0c2011-07-14 13:06:22 -0500269 {
csharptest2b868842011-06-10 14:41:47 -0500270 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500271 }
csharptest2b868842011-06-10 14:41:47 -0500272 break;
273 }
274 case FieldType.Int32:
275 case FieldType.SInt32:
276 case FieldType.SFixed32:
277 {
278 int temp = 0;
279 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500280 {
csharptest2b868842011-06-10 14:41:47 -0500281 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500282 }
csharptest2b868842011-06-10 14:41:47 -0500283 else
csharptest74c5e0c2011-07-14 13:06:22 -0500284 {
csharptest2b868842011-06-10 14:41:47 -0500285 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500286 }
csharptest2b868842011-06-10 14:41:47 -0500287 break;
288 }
289 case FieldType.UInt32:
290 case FieldType.Fixed32:
291 {
292 uint temp = 0;
293 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500294 {
csharptest2b868842011-06-10 14:41:47 -0500295 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500296 }
csharptest2b868842011-06-10 14:41:47 -0500297 else
csharptest74c5e0c2011-07-14 13:06:22 -0500298 {
csharptest2b868842011-06-10 14:41:47 -0500299 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500300 }
csharptest2b868842011-06-10 14:41:47 -0500301 break;
302 }
303 case FieldType.Float:
304 {
305 float temp = float.NaN;
306 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500307 {
csharptest2b868842011-06-10 14:41:47 -0500308 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500309 }
csharptest2b868842011-06-10 14:41:47 -0500310 else
csharptest74c5e0c2011-07-14 13:06:22 -0500311 {
csharptest2b868842011-06-10 14:41:47 -0500312 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500313 }
csharptest2b868842011-06-10 14:41:47 -0500314 break;
315 }
316 case FieldType.Double:
317 {
318 double temp = float.NaN;
319 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500320 {
csharptest2b868842011-06-10 14:41:47 -0500321 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500322 }
csharptest2b868842011-06-10 14:41:47 -0500323 else
csharptest74c5e0c2011-07-14 13:06:22 -0500324 {
csharptest2b868842011-06-10 14:41:47 -0500325 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500326 }
csharptest2b868842011-06-10 14:41:47 -0500327 break;
328 }
329 case FieldType.String:
330 {
331 string temp = null;
332 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500333 {
csharptest2b868842011-06-10 14:41:47 -0500334 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500335 }
csharptest2b868842011-06-10 14:41:47 -0500336 else
csharptest74c5e0c2011-07-14 13:06:22 -0500337 {
csharptest2b868842011-06-10 14:41:47 -0500338 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500339 }
csharptest2b868842011-06-10 14:41:47 -0500340 break;
341 }
342 case FieldType.Bytes:
343 {
344 ByteString temp = null;
345 if (Read(ref temp))
csharptest74c5e0c2011-07-14 13:06:22 -0500346 {
csharptest2b868842011-06-10 14:41:47 -0500347 value = temp;
csharptest74c5e0c2011-07-14 13:06:22 -0500348 }
csharptest2b868842011-06-10 14:41:47 -0500349 else
csharptest74c5e0c2011-07-14 13:06:22 -0500350 {
csharptest2b868842011-06-10 14:41:47 -0500351 return false;
csharptest74c5e0c2011-07-14 13:06:22 -0500352 }
csharptest2b868842011-06-10 14:41:47 -0500353 break;
354 }
355 default:
356 throw InvalidProtocolBufferException.InvalidTag();
357 }
358 return true;
359 }
360
361 #region ICodedInputStream Members
362
363 bool ICodedInputStream.ReadTag(out uint fieldTag, out string fieldName)
364 {
365 fieldTag = 0;
366 if (PeekNext(out fieldName))
367 {
368 return true;
369 }
370 return false;
371 }
372
373 bool ICodedInputStream.ReadDouble(ref double value)
csharptest74c5e0c2011-07-14 13:06:22 -0500374 {
375 return Read(ref value);
376 }
csharptest2b868842011-06-10 14:41:47 -0500377
378 bool ICodedInputStream.ReadFloat(ref float value)
csharptest74c5e0c2011-07-14 13:06:22 -0500379 {
380 return Read(ref value);
381 }
csharptest2b868842011-06-10 14:41:47 -0500382
383 bool ICodedInputStream.ReadUInt64(ref ulong value)
csharptest74c5e0c2011-07-14 13:06:22 -0500384 {
385 return Read(ref value);
386 }
csharptest2b868842011-06-10 14:41:47 -0500387
388 bool ICodedInputStream.ReadInt64(ref long value)
csharptest74c5e0c2011-07-14 13:06:22 -0500389 {
390 return Read(ref value);
391 }
csharptest2b868842011-06-10 14:41:47 -0500392
393 bool ICodedInputStream.ReadInt32(ref int value)
csharptest74c5e0c2011-07-14 13:06:22 -0500394 {
395 return Read(ref value);
396 }
csharptest2b868842011-06-10 14:41:47 -0500397
398 bool ICodedInputStream.ReadFixed64(ref ulong value)
csharptest74c5e0c2011-07-14 13:06:22 -0500399 {
400 return Read(ref value);
401 }
csharptest2b868842011-06-10 14:41:47 -0500402
403 bool ICodedInputStream.ReadFixed32(ref uint value)
csharptest74c5e0c2011-07-14 13:06:22 -0500404 {
405 return Read(ref value);
406 }
csharptest2b868842011-06-10 14:41:47 -0500407
408 bool ICodedInputStream.ReadBool(ref bool value)
csharptest74c5e0c2011-07-14 13:06:22 -0500409 {
410 return Read(ref value);
411 }
csharptest2b868842011-06-10 14:41:47 -0500412
413 bool ICodedInputStream.ReadString(ref string value)
csharptest74c5e0c2011-07-14 13:06:22 -0500414 {
415 return Read(ref value);
416 }
csharptest2b868842011-06-10 14:41:47 -0500417
418 void ICodedInputStream.ReadGroup(int fieldNumber, IBuilderLite builder, ExtensionRegistry extensionRegistry)
csharptest3b70dd72011-06-11 12:22:17 -0500419 {
csharptest0f3540e2011-08-05 20:40:14 -0500420 if (_depth++ > MaxDepth)
csharptest74c5e0c2011-07-14 13:06:22 -0500421 {
csharptest0f3540e2011-08-05 20:40:14 -0500422 throw new RecursionLimitExceededException();
csharptest74c5e0c2011-07-14 13:06:22 -0500423 }
csharptest3b70dd72011-06-11 12:22:17 -0500424 ReadGroup(builder, extensionRegistry);
csharptest0f3540e2011-08-05 20:40:14 -0500425 _depth--;
csharptest3b70dd72011-06-11 12:22:17 -0500426 }
csharptest2b868842011-06-10 14:41:47 -0500427
428 void ICodedInputStream.ReadUnknownGroup(int fieldNumber, IBuilderLite builder)
csharptest74c5e0c2011-07-14 13:06:22 -0500429 {
430 throw new NotSupportedException();
431 }
csharptest2b868842011-06-10 14:41:47 -0500432
433 void ICodedInputStream.ReadMessage(IBuilderLite builder, ExtensionRegistry extensionRegistry)
csharptest3b70dd72011-06-11 12:22:17 -0500434 {
csharptest0f3540e2011-08-05 20:40:14 -0500435 if (_depth++ > MaxDepth)
csharptest74c5e0c2011-07-14 13:06:22 -0500436 {
csharptest0f3540e2011-08-05 20:40:14 -0500437 throw new RecursionLimitExceededException();
csharptest74c5e0c2011-07-14 13:06:22 -0500438 }
csharptest3b70dd72011-06-11 12:22:17 -0500439 ReadMessage(builder, extensionRegistry);
csharptest0f3540e2011-08-05 20:40:14 -0500440 _depth--;
csharptest3b70dd72011-06-11 12:22:17 -0500441 }
csharptest2b868842011-06-10 14:41:47 -0500442
443 bool ICodedInputStream.ReadBytes(ref ByteString value)
csharptest74c5e0c2011-07-14 13:06:22 -0500444 {
445 return Read(ref value);
446 }
csharptest2b868842011-06-10 14:41:47 -0500447
448 bool ICodedInputStream.ReadUInt32(ref uint value)
csharptest74c5e0c2011-07-14 13:06:22 -0500449 {
450 return Read(ref value);
451 }
csharptest2b868842011-06-10 14:41:47 -0500452
453 bool ICodedInputStream.ReadEnum(ref IEnumLite value, out object unknown, IEnumLiteMap mapping)
454 {
455 value = null;
456 unknown = null;
csharptest74c5e0c2011-07-14 13:06:22 -0500457 if (ReadEnum(ref unknown))
csharptest2b868842011-06-10 14:41:47 -0500458 {
csharptest74c5e0c2011-07-14 13:06:22 -0500459 if (unknown is int)
460 {
461 value = mapping.FindValueByNumber((int) unknown);
462 }
463 else if (unknown is string)
464 {
465 value = mapping.FindValueByName((string) unknown);
466 }
csharptest2b868842011-06-10 14:41:47 -0500467 return value != null;
468 }
469 return false;
470 }
471
472 bool ICodedInputStream.ReadEnum<T>(ref T value, out object rawValue)
473 {
474 rawValue = null;
475 if (ReadEnum(ref rawValue))
476 {
csharptest74c5e0c2011-07-14 13:06:22 -0500477 if (Enum.IsDefined(typeof (T), rawValue))
csharptest2b868842011-06-10 14:41:47 -0500478 {
479 if (rawValue is int)
csharptest74c5e0c2011-07-14 13:06:22 -0500480 {
481 value = (T) rawValue;
482 }
csharptest2b868842011-06-10 14:41:47 -0500483 else if (rawValue is string)
csharptest74c5e0c2011-07-14 13:06:22 -0500484 {
485 value = (T) Enum.Parse(typeof (T), (string) rawValue, false);
486 }
csharptest2b868842011-06-10 14:41:47 -0500487 else
488 {
489 value = default(T);
490 return false;
491 }
492 return true;
493 }
494 }
495 return false;
496 }
497
498 bool ICodedInputStream.ReadSFixed32(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.ReadSFixed64(ref long value)
csharptest74c5e0c2011-07-14 13:06:22 -0500504 {
505 return Read(ref value);
506 }
csharptest2b868842011-06-10 14:41:47 -0500507
508 bool ICodedInputStream.ReadSInt32(ref int value)
csharptest74c5e0c2011-07-14 13:06:22 -0500509 {
510 return Read(ref value);
511 }
csharptest2b868842011-06-10 14:41:47 -0500512
513 bool ICodedInputStream.ReadSInt64(ref long value)
csharptest74c5e0c2011-07-14 13:06:22 -0500514 {
515 return Read(ref value);
516 }
csharptest2b868842011-06-10 14:41:47 -0500517
csharptest74c5e0c2011-07-14 13:06:22 -0500518 void ICodedInputStream.ReadPrimitiveArray(FieldType fieldType, uint fieldTag, string fieldName,
519 ICollection<object> list)
520 {
521 ReadArray(fieldType, fieldName, list);
522 }
csharptest2b868842011-06-10 14:41:47 -0500523
csharptest74c5e0c2011-07-14 13:06:22 -0500524 void ICodedInputStream.ReadEnumArray(uint fieldTag, string fieldName, ICollection<IEnumLite> list,
525 out ICollection<object> unknown, IEnumLiteMap mapping)
csharptest2b868842011-06-10 14:41:47 -0500526 {
527 unknown = null;
528 List<object> array = new List<object>();
529 if (ReadEnumArray(fieldName, array))
530 {
531 foreach (object rawValue in array)
532 {
533 IEnumLite item = null;
csharptest74c5e0c2011-07-14 13:06:22 -0500534 if (rawValue is int)
535 {
536 item = mapping.FindValueByNumber((int) rawValue);
537 }
538 else if (rawValue is string)
539 {
540 item = mapping.FindValueByName((string) rawValue);
541 }
csharptest2b868842011-06-10 14:41:47 -0500542
543 if (item != null)
csharptest74c5e0c2011-07-14 13:06:22 -0500544 {
csharptest2b868842011-06-10 14:41:47 -0500545 list.Add(item);
csharptest74c5e0c2011-07-14 13:06:22 -0500546 }
csharptest2b868842011-06-10 14:41:47 -0500547 else
548 {
csharptest74c5e0c2011-07-14 13:06:22 -0500549 if (unknown == null)
550 {
551 unknown = new List<object>();
552 }
csharptest2b868842011-06-10 14:41:47 -0500553 unknown.Add(rawValue);
554 }
555 }
556 }
557 }
558
csharptest74c5e0c2011-07-14 13:06:22 -0500559 void ICodedInputStream.ReadEnumArray<T>(uint fieldTag, string fieldName, ICollection<T> list,
560 out ICollection<object> unknown)
csharptest2b868842011-06-10 14:41:47 -0500561 {
562 unknown = null;
563 List<object> array = new List<object>();
564 if (ReadEnumArray(fieldName, array))
565 {
566 foreach (object rawValue in array)
567 {
568 if (rawValue is int)
csharptest74c5e0c2011-07-14 13:06:22 -0500569 {
570 list.Add((T) rawValue);
571 }
csharptest2b868842011-06-10 14:41:47 -0500572 else if (rawValue is string)
csharptest74c5e0c2011-07-14 13:06:22 -0500573 {
574 list.Add((T) Enum.Parse(typeof (T), (string) rawValue, false));
575 }
csharptest2b868842011-06-10 14:41:47 -0500576 else
577 {
csharptest74c5e0c2011-07-14 13:06:22 -0500578 if (unknown == null)
579 {
580 unknown = new List<object>();
581 }
csharptest2b868842011-06-10 14:41:47 -0500582 unknown.Add(rawValue);
583 }
584 }
585 }
586 }
587
csharptest74c5e0c2011-07-14 13:06:22 -0500588 void ICodedInputStream.ReadMessageArray<T>(uint fieldTag, string fieldName, ICollection<T> list, T messageType,
589 ExtensionRegistry registry)
csharptest3b70dd72011-06-11 12:22:17 -0500590 {
csharptest0f3540e2011-08-05 20:40:14 -0500591 if (_depth++ > MaxDepth)
csharptest74c5e0c2011-07-14 13:06:22 -0500592 {
csharptest0f3540e2011-08-05 20:40:14 -0500593 throw new RecursionLimitExceededException();
csharptest74c5e0c2011-07-14 13:06:22 -0500594 }
csharptest3b70dd72011-06-11 12:22:17 -0500595 ReadMessageArray(fieldName, list, messageType, registry);
csharptest0f3540e2011-08-05 20:40:14 -0500596 _depth--;
csharptest3b70dd72011-06-11 12:22:17 -0500597 }
csharptest2b868842011-06-10 14:41:47 -0500598
csharptest74c5e0c2011-07-14 13:06:22 -0500599 void ICodedInputStream.ReadGroupArray<T>(uint fieldTag, string fieldName, ICollection<T> list, T messageType,
600 ExtensionRegistry registry)
csharptest3b70dd72011-06-11 12:22:17 -0500601 {
csharptest0f3540e2011-08-05 20:40:14 -0500602 if (_depth++ > MaxDepth)
csharptest74c5e0c2011-07-14 13:06:22 -0500603 {
csharptest0f3540e2011-08-05 20:40:14 -0500604 throw new RecursionLimitExceededException();
csharptest74c5e0c2011-07-14 13:06:22 -0500605 }
csharptest3b70dd72011-06-11 12:22:17 -0500606 ReadGroupArray(fieldName, list, messageType, registry);
csharptest0f3540e2011-08-05 20:40:14 -0500607 _depth--;
csharptest3b70dd72011-06-11 12:22:17 -0500608 }
csharptest2b868842011-06-10 14:41:47 -0500609
610 bool ICodedInputStream.ReadPrimitiveField(FieldType fieldType, ref object value)
csharptest74c5e0c2011-07-14 13:06:22 -0500611 {
612 return ReadField(fieldType, ref value);
613 }
csharptest2b868842011-06-10 14:41:47 -0500614
615 bool ICodedInputStream.IsAtEnd
616 {
csharptest74c5e0c2011-07-14 13:06:22 -0500617 get
618 {
619 string next;
620 return PeekNext(out next) == false;
621 }
csharptest2b868842011-06-10 14:41:47 -0500622 }
623
624 bool ICodedInputStream.SkipField()
625 {
626 Skip();
627 return true;
628 }
629
630 void ICodedInputStream.ReadStringArray(uint fieldTag, string fieldName, ICollection<string> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500631 {
632 ReadArray(FieldType.String, fieldName, list);
633 }
csharptest2b868842011-06-10 14:41:47 -0500634
635 void ICodedInputStream.ReadBytesArray(uint fieldTag, string fieldName, ICollection<ByteString> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500636 {
637 ReadArray(FieldType.Bytes, fieldName, list);
638 }
csharptest2b868842011-06-10 14:41:47 -0500639
640 void ICodedInputStream.ReadBoolArray(uint fieldTag, string fieldName, ICollection<bool> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500641 {
642 ReadArray(FieldType.Bool, fieldName, list);
643 }
csharptest2b868842011-06-10 14:41:47 -0500644
645 void ICodedInputStream.ReadInt32Array(uint fieldTag, string fieldName, ICollection<int> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500646 {
647 ReadArray(FieldType.Int32, fieldName, list);
648 }
csharptest2b868842011-06-10 14:41:47 -0500649
650 void ICodedInputStream.ReadSInt32Array(uint fieldTag, string fieldName, ICollection<int> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500651 {
652 ReadArray(FieldType.SInt32, fieldName, list);
653 }
csharptest2b868842011-06-10 14:41:47 -0500654
655 void ICodedInputStream.ReadUInt32Array(uint fieldTag, string fieldName, ICollection<uint> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500656 {
657 ReadArray(FieldType.UInt32, fieldName, list);
658 }
csharptest2b868842011-06-10 14:41:47 -0500659
660 void ICodedInputStream.ReadFixed32Array(uint fieldTag, string fieldName, ICollection<uint> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500661 {
662 ReadArray(FieldType.Fixed32, fieldName, list);
663 }
csharptest2b868842011-06-10 14:41:47 -0500664
665 void ICodedInputStream.ReadSFixed32Array(uint fieldTag, string fieldName, ICollection<int> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500666 {
667 ReadArray(FieldType.SFixed32, fieldName, list);
668 }
csharptest2b868842011-06-10 14:41:47 -0500669
670 void ICodedInputStream.ReadInt64Array(uint fieldTag, string fieldName, ICollection<long> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500671 {
672 ReadArray(FieldType.Int64, fieldName, list);
673 }
csharptest2b868842011-06-10 14:41:47 -0500674
675 void ICodedInputStream.ReadSInt64Array(uint fieldTag, string fieldName, ICollection<long> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500676 {
677 ReadArray(FieldType.SInt64, fieldName, list);
678 }
csharptest2b868842011-06-10 14:41:47 -0500679
680 void ICodedInputStream.ReadUInt64Array(uint fieldTag, string fieldName, ICollection<ulong> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500681 {
682 ReadArray(FieldType.UInt64, fieldName, list);
683 }
csharptest2b868842011-06-10 14:41:47 -0500684
685 void ICodedInputStream.ReadFixed64Array(uint fieldTag, string fieldName, ICollection<ulong> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500686 {
687 ReadArray(FieldType.Fixed64, fieldName, list);
688 }
csharptest2b868842011-06-10 14:41:47 -0500689
690 void ICodedInputStream.ReadSFixed64Array(uint fieldTag, string fieldName, ICollection<long> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500691 {
692 ReadArray(FieldType.SFixed64, fieldName, list);
693 }
csharptest2b868842011-06-10 14:41:47 -0500694
695 void ICodedInputStream.ReadDoubleArray(uint fieldTag, string fieldName, ICollection<double> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500696 {
697 ReadArray(FieldType.Double, fieldName, list);
698 }
csharptest2b868842011-06-10 14:41:47 -0500699
700 void ICodedInputStream.ReadFloatArray(uint fieldTag, string fieldName, ICollection<float> list)
csharptest74c5e0c2011-07-14 13:06:22 -0500701 {
702 ReadArray(FieldType.Float, fieldName, list);
703 }
csharptest2b868842011-06-10 14:41:47 -0500704
705 #endregion
706 }
csharptest74c5e0c2011-07-14 13:06:22 -0500707}