blob: c83950d8601cc5c1fdc8fce6d5ab841e0b3056b7 [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 Slee456b7a82006-10-25 20:53:37 +000013 public static void skip(TProtocol prot, 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 {
Mark Slee456b7a82006-10-25 20:53:37 +000019 prot.readBool();
Mark Slee78f58e22006-09-02 04:17:07 +000020 }
Mark Slee530fd662006-08-09 00:05:18 +000021 case TType.BYTE:
Mark Slee83c52a82006-06-07 06:51:18 +000022 {
Mark Slee456b7a82006-10-25 20:53:37 +000023 prot.readByte();
Mark Slee83c52a82006-06-07 06:51:18 +000024 }
Mark Slee78f58e22006-09-02 04:17:07 +000025 case TType.I16:
26 {
Mark Slee456b7a82006-10-25 20:53:37 +000027 prot.readI16();
Mark Slee78f58e22006-09-02 04:17:07 +000028 }
Mark Slee530fd662006-08-09 00:05:18 +000029 case TType.I32:
Mark Slee83c52a82006-06-07 06:51:18 +000030 {
Mark Slee456b7a82006-10-25 20:53:37 +000031 prot.readI32();
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 Slee456b7a82006-10-25 20:53:37 +000035 prot.readI64();
Mark Slee83c52a82006-06-07 06:51:18 +000036 }
Mark Sleec98d0502006-09-06 02:42:25 +000037 case TType.DOUBLE:
38 {
Mark Slee456b7a82006-10-25 20:53:37 +000039 prot.readDouble();
Mark Sleec98d0502006-09-06 02:42:25 +000040 }
Mark Slee530fd662006-08-09 00:05:18 +000041 case TType.STRING:
Mark Slee83c52a82006-06-07 06:51:18 +000042 {
Mark Slee456b7a82006-10-25 20:53:37 +000043 prot.readString();
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 Slee456b7a82006-10-25 20:53:37 +000047 prot.readStructBegin();
Mark Slee83c52a82006-06-07 06:51:18 +000048 while (true) {
Mark Slee456b7a82006-10-25 20:53:37 +000049 TField field = prot.readFieldBegin();
Mark Slee530fd662006-08-09 00:05:18 +000050 if (field.type == TType.STOP) {
Mark Slee83c52a82006-06-07 06:51:18 +000051 break;
52 }
Mark Slee456b7a82006-10-25 20:53:37 +000053 skip(prot, field.type);
54 prot.readFieldEnd();
Mark Slee83c52a82006-06-07 06:51:18 +000055 }
Mark Slee456b7a82006-10-25 20:53:37 +000056 prot.readStructEnd();
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 Slee456b7a82006-10-25 20:53:37 +000060 TMap map = prot.readMapBegin();
Mark Slee530fd662006-08-09 00:05:18 +000061 for (int i = 0; i < map.size; i++) {
Mark Slee456b7a82006-10-25 20:53:37 +000062 skip(prot, map.keyType);
63 skip(prot, map.valueType);
Mark Slee83c52a82006-06-07 06:51:18 +000064 }
Mark Slee456b7a82006-10-25 20:53:37 +000065 prot.readMapEnd();
Mark Slee83c52a82006-06-07 06:51:18 +000066 }
Mark Slee530fd662006-08-09 00:05:18 +000067 case TType.SET:
68 {
Mark Slee456b7a82006-10-25 20:53:37 +000069 TSet set = prot.readSetBegin();
Mark Slee530fd662006-08-09 00:05:18 +000070 for (int i = 0; i < set.size; i++) {
Mark Slee456b7a82006-10-25 20:53:37 +000071 skip(prot, set.elemType);
Mark Slee83c52a82006-06-07 06:51:18 +000072 }
Mark Slee456b7a82006-10-25 20:53:37 +000073 prot.readSetEnd();
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 Slee456b7a82006-10-25 20:53:37 +000077 TList list = prot.readListBegin();
Mark Slee530fd662006-08-09 00:05:18 +000078 for (int i = 0; i < list.size; i++) {
Mark Slee456b7a82006-10-25 20:53:37 +000079 skip(prot, list.elemType);
Mark Slee83c52a82006-06-07 06:51:18 +000080 }
Mark Slee456b7a82006-10-25 20:53:37 +000081 prot.readListEnd();
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}