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. |
| 18 | */ |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 19 | |
| 20 | using System; |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 21 | |
| 22 | namespace Thrift.Protocol |
| 23 | { |
| 24 | public static class TProtocolUtil |
| 25 | { |
| 26 | public static void Skip(TProtocol prot, TType type) |
| 27 | { |
| 28 | switch (type) |
| 29 | { |
| 30 | case TType.Bool: |
| 31 | prot.ReadBool(); |
| 32 | break; |
| 33 | case TType.Byte: |
| 34 | prot.ReadByte(); |
| 35 | break; |
| 36 | case TType.I16: |
| 37 | prot.ReadI16(); |
| 38 | break; |
| 39 | case TType.I32: |
| 40 | prot.ReadI32(); |
| 41 | break; |
| 42 | case TType.I64: |
| 43 | prot.ReadI64(); |
| 44 | break; |
| 45 | case TType.Double: |
| 46 | prot.ReadDouble(); |
| 47 | break; |
| 48 | case TType.String: |
David Reiss | cba5727 | 2008-02-06 22:09:44 +0000 | [diff] [blame] | 49 | // Don't try to decode the string, just skip it. |
| 50 | prot.ReadBinary(); |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 51 | break; |
| 52 | case TType.Struct: |
| 53 | prot.ReadStructBegin(); |
| 54 | while (true) |
| 55 | { |
| 56 | TField field = prot.ReadFieldBegin(); |
| 57 | if (field.Type == TType.Stop) |
| 58 | { |
| 59 | break; |
| 60 | } |
| 61 | Skip(prot, field.Type); |
| 62 | prot.ReadFieldEnd(); |
| 63 | } |
| 64 | prot.ReadStructEnd(); |
| 65 | break; |
| 66 | case TType.Map: |
| 67 | TMap map = prot.ReadMapBegin(); |
| 68 | for (int i = 0; i < map.Count; i++) |
| 69 | { |
| 70 | Skip(prot, map.KeyType); |
| 71 | Skip(prot, map.ValueType); |
| 72 | } |
| 73 | prot.ReadMapEnd(); |
| 74 | break; |
| 75 | case TType.Set: |
| 76 | TSet set = prot.ReadSetBegin(); |
| 77 | for (int i = 0; i < set.Count; i++) |
| 78 | { |
| 79 | Skip(prot, set.ElementType); |
| 80 | } |
| 81 | prot.ReadSetEnd(); |
| 82 | break; |
| 83 | case TType.List: |
| 84 | TList list = prot.ReadListBegin(); |
| 85 | for (int i = 0; i < list.Count; i++) |
| 86 | { |
| 87 | Skip(prot, list.ElementType); |
| 88 | } |
| 89 | prot.ReadListEnd(); |
| 90 | break; |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | } |