blob: 1c88f8a194c6dcbdc4b31a488213439a469de719 [file] [log] [blame]
Mark Slee83c52a82006-06-07 06:51:18 +00001package com.facebook.thrift.protocol;
2
Mark Slee83c52a82006-06-07 06:51:18 +00003import com.facebook.thrift.TException;
4import com.facebook.thrift.transport.TTransport;
5
6/**
7 * Utility class with static methods for interacting with protocol data
8 * streams.
9 *
10 * @author Mark Slee <mcslee@facebook.com>
11 */
12public class TProtocolUtil {
Mark Slee530fd662006-08-09 00:05:18 +000013 public static void skip(TProtocol prot, TTransport in, byte type)
Mark Slee83c52a82006-06-07 06:51:18 +000014 throws TException {
15
16 switch (type) {
Mark Slee78f58e22006-09-02 04:17:07 +000017 case TType.BOOL:
18 {
19 prot.readBool(in);
20 }
Mark Slee530fd662006-08-09 00:05:18 +000021 case TType.BYTE:
Mark Slee83c52a82006-06-07 06:51:18 +000022 {
Mark Slee530fd662006-08-09 00:05:18 +000023 prot.readByte(in);
Mark Slee83c52a82006-06-07 06:51:18 +000024 }
Mark Slee78f58e22006-09-02 04:17:07 +000025 case TType.I16:
26 {
27 prot.readI16(in);
28 }
Mark Slee530fd662006-08-09 00:05:18 +000029 case TType.I32:
Mark Slee83c52a82006-06-07 06:51:18 +000030 {
Mark Slee530fd662006-08-09 00:05:18 +000031 prot.readI32(in);
Mark Slee83c52a82006-06-07 06:51:18 +000032 }
Mark Slee530fd662006-08-09 00:05:18 +000033 case TType.I64:
Mark Slee83c52a82006-06-07 06:51:18 +000034 {
Mark Slee530fd662006-08-09 00:05:18 +000035 prot.readI64(in);
Mark Slee83c52a82006-06-07 06:51:18 +000036 }
Mark Sleec98d0502006-09-06 02:42:25 +000037 case TType.DOUBLE:
38 {
39 prot.readDouble(in);
40 }
Mark Slee530fd662006-08-09 00:05:18 +000041 case TType.STRING:
Mark Slee83c52a82006-06-07 06:51:18 +000042 {
Mark Slee530fd662006-08-09 00:05:18 +000043 prot.readString(in);
Mark Slee83c52a82006-06-07 06:51:18 +000044 }
Mark Slee530fd662006-08-09 00:05:18 +000045 case TType.STRUCT:
Mark Slee83c52a82006-06-07 06:51:18 +000046 {
Mark Slee530fd662006-08-09 00:05:18 +000047 prot.readStructBegin(in);
Mark Slee83c52a82006-06-07 06:51:18 +000048 while (true) {
Mark Slee530fd662006-08-09 00:05:18 +000049 TField field = prot.readFieldBegin(in);
50 if (field.type == TType.STOP) {
Mark Slee83c52a82006-06-07 06:51:18 +000051 break;
52 }
Mark Slee530fd662006-08-09 00:05:18 +000053 skip(prot, in, field.type);
54 prot.readFieldEnd(in);
Mark Slee83c52a82006-06-07 06:51:18 +000055 }
Mark Slee530fd662006-08-09 00:05:18 +000056 prot.readStructEnd(in);
Mark Slee83c52a82006-06-07 06:51:18 +000057 }
Mark Slee530fd662006-08-09 00:05:18 +000058 case TType.MAP:
Mark Slee83c52a82006-06-07 06:51:18 +000059 {
Mark Slee530fd662006-08-09 00:05:18 +000060 TMap map = prot.readMapBegin(in);
61 for (int i = 0; i < map.size; i++) {
62 skip(prot, in, map.keyType);
63 skip(prot, in, map.valueType);
Mark Slee83c52a82006-06-07 06:51:18 +000064 }
Mark Slee530fd662006-08-09 00:05:18 +000065 prot.readMapEnd(in);
Mark Slee83c52a82006-06-07 06:51:18 +000066 }
Mark Slee530fd662006-08-09 00:05:18 +000067 case TType.SET:
68 {
69 TSet set = prot.readSetBegin(in);
70 for (int i = 0; i < set.size; i++) {
71 skip(prot, in, set.elemType);
Mark Slee83c52a82006-06-07 06:51:18 +000072 }
Mark Slee530fd662006-08-09 00:05:18 +000073 prot.readSetEnd(in);
Mark Slee83c52a82006-06-07 06:51:18 +000074 }
Mark Slee530fd662006-08-09 00:05:18 +000075 case TType.LIST:
Mark Slee83c52a82006-06-07 06:51:18 +000076 {
Mark Slee530fd662006-08-09 00:05:18 +000077 TList list = prot.readListBegin(in);
78 for (int i = 0; i < list.size; i++) {
79 skip(prot, in, list.elemType);
Mark Slee83c52a82006-06-07 06:51:18 +000080 }
Mark Slee530fd662006-08-09 00:05:18 +000081 prot.readListEnd(in);
Mark Slee83c52a82006-06-07 06:51:18 +000082 }
83 default:
Mark Slee530fd662006-08-09 00:05:18 +000084 return;
Mark Slee83c52a82006-06-07 06:51:18 +000085 }
86 }
87}