blob: 935163c8070fb6fa845462b2ed018baa39b0d1b0 [file] [log] [blame]
Mark Slee7eb0d632007-03-01 00:00:27 +00001// Copyright (c) 2006- Facebook
2// Distributed under the Thrift Software License
3//
4// See accompanying file LICENSE or visit the Thrift site at:
5// http://developers.facebook.com/thrift/
6
Mark Slee83c52a82006-06-07 06:51:18 +00007package com.facebook.thrift.protocol;
8
Mark Slee83c52a82006-06-07 06:51:18 +00009import com.facebook.thrift.TException;
10import com.facebook.thrift.transport.TTransport;
11
12/**
13 * Utility class with static methods for interacting with protocol data
14 * streams.
15 *
16 * @author Mark Slee <mcslee@facebook.com>
17 */
18public class TProtocolUtil {
Mark Slee456b7a82006-10-25 20:53:37 +000019 public static void skip(TProtocol prot, byte type)
Mark Slee83c52a82006-06-07 06:51:18 +000020 throws TException {
21
22 switch (type) {
Mark Slee78f58e22006-09-02 04:17:07 +000023 case TType.BOOL:
24 {
Mark Slee456b7a82006-10-25 20:53:37 +000025 prot.readBool();
Mark Slee78f58e22006-09-02 04:17:07 +000026 }
Mark Slee530fd662006-08-09 00:05:18 +000027 case TType.BYTE:
Mark Slee83c52a82006-06-07 06:51:18 +000028 {
Mark Slee456b7a82006-10-25 20:53:37 +000029 prot.readByte();
Mark Slee83c52a82006-06-07 06:51:18 +000030 }
Mark Slee78f58e22006-09-02 04:17:07 +000031 case TType.I16:
32 {
Mark Slee456b7a82006-10-25 20:53:37 +000033 prot.readI16();
Mark Slee78f58e22006-09-02 04:17:07 +000034 }
Mark Slee530fd662006-08-09 00:05:18 +000035 case TType.I32:
Mark Slee83c52a82006-06-07 06:51:18 +000036 {
Mark Slee456b7a82006-10-25 20:53:37 +000037 prot.readI32();
Mark Slee83c52a82006-06-07 06:51:18 +000038 }
Mark Slee530fd662006-08-09 00:05:18 +000039 case TType.I64:
Mark Slee83c52a82006-06-07 06:51:18 +000040 {
Mark Slee456b7a82006-10-25 20:53:37 +000041 prot.readI64();
Mark Slee83c52a82006-06-07 06:51:18 +000042 }
Mark Sleec98d0502006-09-06 02:42:25 +000043 case TType.DOUBLE:
44 {
Mark Slee456b7a82006-10-25 20:53:37 +000045 prot.readDouble();
Mark Sleec98d0502006-09-06 02:42:25 +000046 }
Mark Slee530fd662006-08-09 00:05:18 +000047 case TType.STRING:
Mark Slee83c52a82006-06-07 06:51:18 +000048 {
Mark Slee456b7a82006-10-25 20:53:37 +000049 prot.readString();
Mark Slee83c52a82006-06-07 06:51:18 +000050 }
Mark Slee530fd662006-08-09 00:05:18 +000051 case TType.STRUCT:
Mark Slee83c52a82006-06-07 06:51:18 +000052 {
Mark Slee456b7a82006-10-25 20:53:37 +000053 prot.readStructBegin();
Mark Slee83c52a82006-06-07 06:51:18 +000054 while (true) {
Mark Slee456b7a82006-10-25 20:53:37 +000055 TField field = prot.readFieldBegin();
Mark Slee530fd662006-08-09 00:05:18 +000056 if (field.type == TType.STOP) {
Mark Slee83c52a82006-06-07 06:51:18 +000057 break;
58 }
Mark Slee456b7a82006-10-25 20:53:37 +000059 skip(prot, field.type);
60 prot.readFieldEnd();
Mark Slee83c52a82006-06-07 06:51:18 +000061 }
Mark Slee456b7a82006-10-25 20:53:37 +000062 prot.readStructEnd();
Mark Slee83c52a82006-06-07 06:51:18 +000063 }
Mark Slee530fd662006-08-09 00:05:18 +000064 case TType.MAP:
Mark Slee83c52a82006-06-07 06:51:18 +000065 {
Mark Slee456b7a82006-10-25 20:53:37 +000066 TMap map = prot.readMapBegin();
Mark Slee530fd662006-08-09 00:05:18 +000067 for (int i = 0; i < map.size; i++) {
Mark Slee456b7a82006-10-25 20:53:37 +000068 skip(prot, map.keyType);
69 skip(prot, map.valueType);
Mark Slee83c52a82006-06-07 06:51:18 +000070 }
Mark Slee456b7a82006-10-25 20:53:37 +000071 prot.readMapEnd();
Mark Slee83c52a82006-06-07 06:51:18 +000072 }
Mark Slee530fd662006-08-09 00:05:18 +000073 case TType.SET:
74 {
Mark Slee456b7a82006-10-25 20:53:37 +000075 TSet set = prot.readSetBegin();
Mark Slee530fd662006-08-09 00:05:18 +000076 for (int i = 0; i < set.size; i++) {
Mark Slee456b7a82006-10-25 20:53:37 +000077 skip(prot, set.elemType);
Mark Slee83c52a82006-06-07 06:51:18 +000078 }
Mark Slee456b7a82006-10-25 20:53:37 +000079 prot.readSetEnd();
Mark Slee83c52a82006-06-07 06:51:18 +000080 }
Mark Slee530fd662006-08-09 00:05:18 +000081 case TType.LIST:
Mark Slee83c52a82006-06-07 06:51:18 +000082 {
Mark Slee456b7a82006-10-25 20:53:37 +000083 TList list = prot.readListBegin();
Mark Slee530fd662006-08-09 00:05:18 +000084 for (int i = 0; i < list.size; i++) {
Mark Slee456b7a82006-10-25 20:53:37 +000085 skip(prot, list.elemType);
Mark Slee83c52a82006-06-07 06:51:18 +000086 }
Mark Slee456b7a82006-10-25 20:53:37 +000087 prot.readListEnd();
Mark Slee83c52a82006-06-07 06:51:18 +000088 }
89 default:
Mark Slee530fd662006-08-09 00:05:18 +000090 return;
Mark Slee83c52a82006-06-07 06:51:18 +000091 }
92 }
93}