blob: 0932a7f1450d87e036149843f6b9c5733322b620 [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{
Jens Geyerd5436f52014-10-03 19:50:38 +020028 public static class TProtocolUtil
29 {
30 public static void Skip(TProtocol prot, TType type)
31 {
Jens Geyer40180362015-07-09 23:02:46 +020032 prot.IncrementRecursionDepth();
33 try
Jens Geyerd5436f52014-10-03 19:50:38 +020034 {
Jens Geyer40180362015-07-09 23:02:46 +020035 switch (type)
36 {
37 case TType.Bool:
38 prot.ReadBool();
39 break;
40 case TType.Byte:
41 prot.ReadByte();
42 break;
43 case TType.I16:
44 prot.ReadI16();
45 break;
46 case TType.I32:
47 prot.ReadI32();
48 break;
49 case TType.I64:
50 prot.ReadI64();
51 break;
52 case TType.Double:
53 prot.ReadDouble();
54 break;
55 case TType.String:
56 // Don't try to decode the string, just skip it.
57 prot.ReadBinary();
58 break;
59 case TType.Struct:
60 prot.ReadStructBegin();
61 while (true)
Jens Geyerd5436f52014-10-03 19:50:38 +020062 {
Jens Geyer40180362015-07-09 23:02:46 +020063 TField field = prot.ReadFieldBegin();
64 if (field.Type == TType.Stop)
65 {
66 break;
67 }
68 Skip(prot, field.Type);
69 prot.ReadFieldEnd();
Jens Geyerd5436f52014-10-03 19:50:38 +020070 }
Jens Geyer40180362015-07-09 23:02:46 +020071 prot.ReadStructEnd();
72 break;
73 case TType.Map:
74 TMap map = prot.ReadMapBegin();
75 for (int i = 0; i < map.Count; i++)
76 {
77 Skip(prot, map.KeyType);
78 Skip(prot, map.ValueType);
79 }
80 prot.ReadMapEnd();
81 break;
82 case TType.Set:
83 TSet set = prot.ReadSetBegin();
84 for (int i = 0; i < set.Count; i++)
85 {
86 Skip(prot, set.ElementType);
87 }
88 prot.ReadSetEnd();
89 break;
90 case TType.List:
91 TList list = prot.ReadListBegin();
92 for (int i = 0; i < list.Count; i++)
93 {
94 Skip(prot, list.ElementType);
95 }
96 prot.ReadListEnd();
97 break;
98 }
99
100 }
101 finally
102 {
103 prot.DecrementRecursionDepth();
Jens Geyerd5436f52014-10-03 19:50:38 +0200104 }
105 }
106 }
David Reiss7f42bcf2008-01-11 20:59:12 +0000107}