Mark Slee | 7e9eea4 | 2007-09-10 21:00:23 +0000 | [diff] [blame] | 1 | #import "TProtocolUtil.h" |
| 2 | |
| 3 | @implementation TProtocolUtil |
| 4 | |
| 5 | + (void) skipType: (int) type onProtocol: (id <TProtocol>) protocol |
| 6 | { |
| 7 | switch (type) { |
| 8 | case TType_BOOL: |
| 9 | [protocol readBool]; |
| 10 | break; |
| 11 | case TType_BYTE: |
| 12 | [protocol readByte]; |
| 13 | break; |
| 14 | case TType_I16: |
| 15 | [protocol readI16]; |
| 16 | break; |
| 17 | case TType_I32: |
| 18 | [protocol readI32]; |
| 19 | break; |
| 20 | case TType_I64: |
| 21 | [protocol readI64]; |
| 22 | break; |
| 23 | case TType_DOUBLE: |
| 24 | [protocol readDouble]; |
| 25 | break; |
| 26 | case TType_STRING: |
| 27 | [protocol readString]; |
| 28 | break; |
| 29 | case TType_STRUCT: |
Mark Slee | 33a7d89 | 2007-09-14 19:44:30 +0000 | [diff] [blame] | 30 | [protocol readStructBeginReturningName: NULL]; |
Mark Slee | 7e9eea4 | 2007-09-10 21:00:23 +0000 | [diff] [blame] | 31 | while (true) { |
| 32 | int fieldType; |
Mark Slee | 33a7d89 | 2007-09-14 19:44:30 +0000 | [diff] [blame] | 33 | [protocol readFieldBeginReturningName: nil type: &fieldType fieldID: nil]; |
Mark Slee | 7e9eea4 | 2007-09-10 21:00:23 +0000 | [diff] [blame] | 34 | if (fieldType == TType_STOP) { |
| 35 | break; |
| 36 | } |
| 37 | [TProtocolUtil skipType: fieldType onProtocol: protocol]; |
| 38 | [protocol readFieldEnd]; |
| 39 | } |
| 40 | [protocol readStructEnd]; |
| 41 | break; |
| 42 | case TType_MAP: |
| 43 | { |
| 44 | int keyType; |
| 45 | int valueType; |
| 46 | int size; |
Mark Slee | 33a7d89 | 2007-09-14 19:44:30 +0000 | [diff] [blame] | 47 | [protocol readMapBeginReturningKeyType: &keyType valueType: &valueType size: &size]; |
Mark Slee | 7e9eea4 | 2007-09-10 21:00:23 +0000 | [diff] [blame] | 48 | int i; |
| 49 | for (i = 0; i < size; i++) { |
| 50 | [TProtocolUtil skipType: keyType onProtocol: protocol]; |
| 51 | [TProtocolUtil skipType: valueType onProtocol: protocol]; |
| 52 | } |
| 53 | [protocol readMapEnd]; |
| 54 | } |
| 55 | break; |
| 56 | case TType_SET: |
| 57 | { |
| 58 | int elemType; |
| 59 | int size; |
Mark Slee | 33a7d89 | 2007-09-14 19:44:30 +0000 | [diff] [blame] | 60 | [protocol readSetBeginReturningElementType: &elemType size: &size]; |
Mark Slee | 7e9eea4 | 2007-09-10 21:00:23 +0000 | [diff] [blame] | 61 | int i; |
| 62 | for (i = 0; i < size; i++) { |
| 63 | [TProtocolUtil skipType: elemType onProtocol: protocol]; |
| 64 | } |
| 65 | [protocol readSetEnd]; |
| 66 | } |
| 67 | break; |
| 68 | case TType_LIST: |
| 69 | { |
| 70 | int elemType; |
| 71 | int size; |
Mark Slee | 33a7d89 | 2007-09-14 19:44:30 +0000 | [diff] [blame] | 72 | [protocol readListBeginReturningElementType: &elemType size: &size]; |
Mark Slee | 7e9eea4 | 2007-09-10 21:00:23 +0000 | [diff] [blame] | 73 | int i; |
| 74 | for (i = 0; i < size; i++) { |
| 75 | [TProtocolUtil skipType: elemType onProtocol: protocol]; |
| 76 | } |
| 77 | [protocol readListEnd]; |
| 78 | } |
| 79 | break; |
| 80 | default: |
| 81 | return; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | @end |