Kevin Clark | ab4460d | 2009-03-20 02:28:41 +0000 | [diff] [blame] | 1 | /** |
| 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 Lipcon | 53ae9f3 | 2009-12-07 00:42:38 +0000 | [diff] [blame] | 18 | * |
| 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 Clark | ab4460d | 2009-03-20 02:28:41 +0000 | [diff] [blame] | 22 | */ |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 23 | |
| 24 | using System; |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 25 | |
| 26 | namespace 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 Reiss | cba5727 | 2008-02-06 22:09:44 +0000 | [diff] [blame] | 53 | // Don't try to decode the string, just skip it. |
| 54 | prot.ReadBinary(); |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 55 | 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 | } |