blob: 13d70954f741cdf967ce66ae2f6154385d01033e [file] [log] [blame]
David Reissea2cba82009-03-30 21:35:00 +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.
18 */
19
Mark Slee7e9eea42007-09-10 21:00:23 +000020#import "TProtocolUtil.h"
21
22@implementation TProtocolUtil
23
24+ (void) skipType: (int) type onProtocol: (id <TProtocol>) protocol
25{
26 switch (type) {
27 case TType_BOOL:
28 [protocol readBool];
29 break;
30 case TType_BYTE:
31 [protocol readByte];
32 break;
33 case TType_I16:
34 [protocol readI16];
35 break;
36 case TType_I32:
37 [protocol readI32];
38 break;
39 case TType_I64:
40 [protocol readI64];
41 break;
42 case TType_DOUBLE:
43 [protocol readDouble];
44 break;
45 case TType_STRING:
46 [protocol readString];
47 break;
48 case TType_STRUCT:
Mark Slee33a7d892007-09-14 19:44:30 +000049 [protocol readStructBeginReturningName: NULL];
Mark Slee7e9eea42007-09-10 21:00:23 +000050 while (true) {
51 int fieldType;
Mark Slee33a7d892007-09-14 19:44:30 +000052 [protocol readFieldBeginReturningName: nil type: &fieldType fieldID: nil];
Mark Slee7e9eea42007-09-10 21:00:23 +000053 if (fieldType == TType_STOP) {
54 break;
55 }
56 [TProtocolUtil skipType: fieldType onProtocol: protocol];
57 [protocol readFieldEnd];
58 }
59 [protocol readStructEnd];
60 break;
61 case TType_MAP:
62 {
63 int keyType;
64 int valueType;
65 int size;
Mark Slee33a7d892007-09-14 19:44:30 +000066 [protocol readMapBeginReturningKeyType: &keyType valueType: &valueType size: &size];
Mark Slee7e9eea42007-09-10 21:00:23 +000067 int i;
68 for (i = 0; i < size; i++) {
69 [TProtocolUtil skipType: keyType onProtocol: protocol];
70 [TProtocolUtil skipType: valueType onProtocol: protocol];
71 }
72 [protocol readMapEnd];
73 }
74 break;
75 case TType_SET:
76 {
77 int elemType;
78 int size;
Mark Slee33a7d892007-09-14 19:44:30 +000079 [protocol readSetBeginReturningElementType: &elemType size: &size];
Mark Slee7e9eea42007-09-10 21:00:23 +000080 int i;
81 for (i = 0; i < size; i++) {
82 [TProtocolUtil skipType: elemType onProtocol: protocol];
83 }
84 [protocol readSetEnd];
85 }
86 break;
87 case TType_LIST:
88 {
89 int elemType;
90 int size;
Mark Slee33a7d892007-09-14 19:44:30 +000091 [protocol readListBeginReturningElementType: &elemType size: &size];
Mark Slee7e9eea42007-09-10 21:00:23 +000092 int i;
93 for (i = 0; i < size; i++) {
94 [TProtocolUtil skipType: elemType onProtocol: protocol];
95 }
96 [protocol readListEnd];
97 }
98 break;
99 default:
100 return;
101 }
102}
103
104@end