blob: ae5a10786aaeeecb1c7e7f61eb59c405dd341d57 [file] [log] [blame]
David Reiss7f42bcf2008-01-11 20:59:12 +00001//
2// TProtocolUtil.cs
3//
4// Begin: Aug 19, 2007
5// Authors:
6// Todd Berman <tberman@imeem.com>
7//
8// Distributed under the Thrift Software License
9//
10// See accompanying file LICENSE or visit the Thrift site at:
11// http://developers.facebook.com/thrift/using
12
13using System;
14using System.Collections.Generic;
15using System.Text;
16
17namespace Thrift.Protocol
18{
19 public static class TProtocolUtil
20 {
21 public static void Skip(TProtocol prot, TType type)
22 {
23 switch (type)
24 {
25 case TType.Bool:
26 prot.ReadBool();
27 break;
28 case TType.Byte:
29 prot.ReadByte();
30 break;
31 case TType.I16:
32 prot.ReadI16();
33 break;
34 case TType.I32:
35 prot.ReadI32();
36 break;
37 case TType.I64:
38 prot.ReadI64();
39 break;
40 case TType.Double:
41 prot.ReadDouble();
42 break;
43 case TType.String:
David Reisscba57272008-02-06 22:09:44 +000044 // Don't try to decode the string, just skip it.
45 prot.ReadBinary();
David Reiss7f42bcf2008-01-11 20:59:12 +000046 break;
47 case TType.Struct:
48 prot.ReadStructBegin();
49 while (true)
50 {
51 TField field = prot.ReadFieldBegin();
52 if (field.Type == TType.Stop)
53 {
54 break;
55 }
56 Skip(prot, field.Type);
57 prot.ReadFieldEnd();
58 }
59 prot.ReadStructEnd();
60 break;
61 case TType.Map:
62 TMap map = prot.ReadMapBegin();
63 for (int i = 0; i < map.Count; i++)
64 {
65 Skip(prot, map.KeyType);
66 Skip(prot, map.ValueType);
67 }
68 prot.ReadMapEnd();
69 break;
70 case TType.Set:
71 TSet set = prot.ReadSetBegin();
72 for (int i = 0; i < set.Count; i++)
73 {
74 Skip(prot, set.ElementType);
75 }
76 prot.ReadSetEnd();
77 break;
78 case TType.List:
79 TList list = prot.ReadListBegin();
80 for (int i = 0; i < list.Count; i++)
81 {
82 Skip(prot, list.ElementType);
83 }
84 prot.ReadListEnd();
85 break;
86 }
87 }
88 }
89}