]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
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 | */ | |
19 | ||
20 | package org.apache.thrift.protocol; | |
21 | ||
22 | import org.apache.thrift.*; | |
23 | ||
24 | /** | |
25 | * Utility class with static methods for interacting with protocol data | |
26 | * streams. | |
27 | * | |
28 | */ | |
29 | class TProtocolUtil { | |
30 | ||
31 | /** | |
32 | * Skips over the next data element from the provided input TProtocol object. | |
33 | * | |
34 | * @param prot the protocol object to read from | |
35 | * @param type the next value will be intepreted as this TType value. | |
36 | */ | |
37 | public static function skip(prot:TProtocol, type : Int) : Void { | |
38 | prot.IncrementRecursionDepth(); | |
39 | try | |
40 | { | |
41 | switch (type) { | |
42 | case TType.BOOL: | |
43 | prot.readBool(); | |
44 | ||
45 | case TType.BYTE: | |
46 | prot.readByte(); | |
47 | ||
48 | case TType.I16: | |
49 | prot.readI16(); | |
50 | ||
51 | case TType.I32: | |
52 | prot.readI32(); | |
53 | ||
54 | case TType.I64: | |
55 | prot.readI64(); | |
56 | ||
57 | case TType.DOUBLE: | |
58 | prot.readDouble(); | |
59 | ||
60 | case TType.STRING: | |
61 | prot.readBinary(); | |
62 | ||
63 | case TType.STRUCT: | |
64 | prot.readStructBegin(); | |
65 | while (true) { | |
66 | var field:TField = prot.readFieldBegin(); | |
67 | if (field.type == TType.STOP) { | |
68 | break; | |
69 | } | |
70 | skip(prot, field.type); | |
71 | prot.readFieldEnd(); | |
72 | } | |
73 | prot.readStructEnd(); | |
74 | ||
75 | case TType.MAP: | |
76 | var map:TMap = prot.readMapBegin(); | |
77 | for (i in 0 ... map.size) { | |
78 | skip(prot, map.keyType); | |
79 | skip(prot, map.valueType); | |
80 | } | |
81 | prot.readMapEnd(); | |
82 | ||
83 | case TType.SET: | |
84 | var set:TSet = prot.readSetBegin(); | |
85 | for (j in 0 ... set.size) { | |
86 | skip(prot, set.elemType); | |
87 | } | |
88 | prot.readSetEnd(); | |
89 | ||
90 | case TType.LIST: | |
91 | var list:TList = prot.readListBegin(); | |
92 | for (k in 0 ... list.size) { | |
93 | skip(prot, list.elemType); | |
94 | } | |
95 | prot.readListEnd(); | |
96 | ||
97 | default: | |
98 | throw new TProtocolException(TProtocolException.UNKNOWN, "Unknown field type ${type}"); | |
99 | } | |
100 | ||
101 | prot.DecrementRecursionDepth(); | |
102 | } | |
103 | catch(e:Dynamic) | |
104 | { | |
105 | prot.DecrementRecursionDepth(); | |
106 | throw e; | |
107 | } | |
108 | } | |
109 | ||
110 | } |