blob: 82cd3e35f69172752f88263d75d44f15d71d89a7 [file] [log] [blame]
Kevin Clarkab4460d2009-03-20 02:28:41 +00001/**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
Todd Lipcon53ae9f32009-12-07 00:42:38 +000018 *
19 * Contains some contributions under the Thrift Software License.
20 * Please see doc/old-thrift-license.txt in the Thrift distribution for
21 * details.
Kevin Clarkab4460d2009-03-20 02:28:41 +000022 */
David Reiss7f42bcf2008-01-11 20:59:12 +000023
24using System;
David Reiss7f42bcf2008-01-11 20:59:12 +000025
26namespace Thrift.Protocol
27{
28 public static class TProtocolUtil
29 {
30 public static void Skip(TProtocol prot, TType type)
31 {
32 switch (type)
33 {
34 case TType.Bool:
35 prot.ReadBool();
36 break;
37 case TType.Byte:
38 prot.ReadByte();
39 break;
40 case TType.I16:
41 prot.ReadI16();
42 break;
43 case TType.I32:
44 prot.ReadI32();
45 break;
46 case TType.I64:
47 prot.ReadI64();
48 break;
49 case TType.Double:
50 prot.ReadDouble();
51 break;
52 case TType.String:
David Reisscba57272008-02-06 22:09:44 +000053 // Don't try to decode the string, just skip it.
54 prot.ReadBinary();
David Reiss7f42bcf2008-01-11 20:59:12 +000055 break;
56 case TType.Struct:
57 prot.ReadStructBegin();
58 while (true)
59 {
60 TField field = prot.ReadFieldBegin();
61 if (field.Type == TType.Stop)
62 {
63 break;
64 }
65 Skip(prot, field.Type);
66 prot.ReadFieldEnd();
67 }
68 prot.ReadStructEnd();
69 break;
70 case TType.Map:
71 TMap map = prot.ReadMapBegin();
72 for (int i = 0; i < map.Count; i++)
73 {
74 Skip(prot, map.KeyType);
75 Skip(prot, map.ValueType);
76 }
77 prot.ReadMapEnd();
78 break;
79 case TType.Set:
80 TSet set = prot.ReadSetBegin();
81 for (int i = 0; i < set.Count; i++)
82 {
83 Skip(prot, set.ElementType);
84 }
85 prot.ReadSetEnd();
86 break;
87 case TType.List:
88 TList list = prot.ReadListBegin();
89 for (int i = 0; i < list.Count; i++)
90 {
91 Skip(prot, list.ElementType);
92 }
93 prot.ReadListEnd();
94 break;
95 }
96 }
97 }
98}