blob: dcc84ce1e3b2af35137cbf8ca105aad8e2286aa7 [file] [log] [blame]
Mark Sleee74306a2007-02-21 05:38:12 +00001from thrift.Thrift import *
Mark Sleecde2b612006-09-03 21:13:07 +00002
Mark Slee92195ae2007-02-21 05:16:30 +00003class TProtocolException(TException):
4
5 """Custom Protocol Exception class"""
6
7 UNKNOWN = 0
8 INVALID_DATA = 1
9 NEGATIVE_SIZE = 2
10 SIZE_LIMIT = 3
11
12 def __init__(self, type=UNKNOWN, message=None):
13 TException.__init__(self, message)
14 self.type = type
15
Mark Sleecde2b612006-09-03 21:13:07 +000016class TProtocolBase:
17
18 """Base class for Thrift protocol driver."""
19
Aditya Agarwal5c468192007-02-06 01:14:33 +000020 def __init__(self, trans):
21 self.trans = trans
Mark Slee4ac459f2006-10-25 21:39:01 +000022
23 def writeMessageBegin(self, name, type, seqid):
Mark Sleecde2b612006-09-03 21:13:07 +000024 pass
25
Mark Slee4ac459f2006-10-25 21:39:01 +000026 def writeMessageEnd(self):
Mark Sleecde2b612006-09-03 21:13:07 +000027 pass
28
Mark Slee4ac459f2006-10-25 21:39:01 +000029 def writeStructBegin(self, name):
Mark Sleecde2b612006-09-03 21:13:07 +000030 pass
31
Mark Slee4ac459f2006-10-25 21:39:01 +000032 def writeStructEnd(self):
Mark Sleecde2b612006-09-03 21:13:07 +000033 pass
34
Mark Slee4ac459f2006-10-25 21:39:01 +000035 def writeFieldBegin(self, name, type, id):
Mark Sleecde2b612006-09-03 21:13:07 +000036 pass
37
Mark Slee4ac459f2006-10-25 21:39:01 +000038 def writeFieldEnd(self):
Mark Sleecde2b612006-09-03 21:13:07 +000039 pass
40
Mark Slee4ac459f2006-10-25 21:39:01 +000041 def writeFieldStop(self):
Mark Sleecde2b612006-09-03 21:13:07 +000042 pass
43
Mark Slee4ac459f2006-10-25 21:39:01 +000044 def writeMapBegin(self, ktype, vtype, size):
Mark Sleecde2b612006-09-03 21:13:07 +000045 pass
46
Mark Slee4ac459f2006-10-25 21:39:01 +000047 def writeMapEnd(self):
Mark Sleecde2b612006-09-03 21:13:07 +000048 pass
49
Mark Slee4ac459f2006-10-25 21:39:01 +000050 def writeListBegin(self, etype, size):
Mark Sleecde2b612006-09-03 21:13:07 +000051 pass
52
Mark Slee4ac459f2006-10-25 21:39:01 +000053 def writeListEnd(self):
Mark Sleecde2b612006-09-03 21:13:07 +000054 pass
55
Mark Slee4ac459f2006-10-25 21:39:01 +000056 def writeSetBegin(self, etype, size):
Mark Sleecde2b612006-09-03 21:13:07 +000057 pass
58
Mark Slee4ac459f2006-10-25 21:39:01 +000059 def writeSetEnd(self):
Mark Sleecde2b612006-09-03 21:13:07 +000060 pass
61
Mark Slee4ac459f2006-10-25 21:39:01 +000062 def writeBool(self, bool):
Mark Sleecde2b612006-09-03 21:13:07 +000063 pass
64
Mark Slee4ac459f2006-10-25 21:39:01 +000065 def writeByte(self, byte):
Mark Sleecde2b612006-09-03 21:13:07 +000066 pass
67
Mark Slee4ac459f2006-10-25 21:39:01 +000068 def writeI16(self, i16):
Mark Sleecde2b612006-09-03 21:13:07 +000069 pass
70
Mark Slee4ac459f2006-10-25 21:39:01 +000071 def writeI32(self, i32):
Mark Sleecde2b612006-09-03 21:13:07 +000072 pass
73
Mark Slee4ac459f2006-10-25 21:39:01 +000074 def writeI64(self, i64):
Mark Sleecde2b612006-09-03 21:13:07 +000075 pass
76
Mark Slee4ac459f2006-10-25 21:39:01 +000077 def writeDouble(self, dub):
Mark Sleec98d0502006-09-06 02:42:25 +000078 pass
79
Mark Slee4ac459f2006-10-25 21:39:01 +000080 def writeString(self, str):
Mark Sleecde2b612006-09-03 21:13:07 +000081 pass
82
Mark Slee4ac459f2006-10-25 21:39:01 +000083 def readMessageBegin(self):
Mark Sleecde2b612006-09-03 21:13:07 +000084 pass
85
Mark Slee4ac459f2006-10-25 21:39:01 +000086 def readMessageEnd(self):
Mark Sleecde2b612006-09-03 21:13:07 +000087 pass
88
Mark Slee4ac459f2006-10-25 21:39:01 +000089 def readStructBegin(self):
Mark Sleecde2b612006-09-03 21:13:07 +000090 pass
91
Mark Slee4ac459f2006-10-25 21:39:01 +000092 def readStructEnd(self):
Mark Sleecde2b612006-09-03 21:13:07 +000093 pass
94
Mark Slee4ac459f2006-10-25 21:39:01 +000095 def readFieldBegin(self):
Mark Sleecde2b612006-09-03 21:13:07 +000096 pass
97
Mark Slee4ac459f2006-10-25 21:39:01 +000098 def readFieldEnd(self):
Mark Sleecde2b612006-09-03 21:13:07 +000099 pass
100
Mark Slee4ac459f2006-10-25 21:39:01 +0000101 def readMapBegin(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000102 pass
103
Mark Slee4ac459f2006-10-25 21:39:01 +0000104 def readMapEnd(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000105 pass
106
Mark Slee4ac459f2006-10-25 21:39:01 +0000107 def readListBegin(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000108 pass
109
Mark Slee4ac459f2006-10-25 21:39:01 +0000110 def readListEnd(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000111 pass
112
Mark Slee4ac459f2006-10-25 21:39:01 +0000113 def readSetBegin(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000114 pass
115
Mark Slee4ac459f2006-10-25 21:39:01 +0000116 def readSetEnd(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000117 pass
118
Mark Slee4ac459f2006-10-25 21:39:01 +0000119 def readBool(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000120 pass
121
Mark Slee4ac459f2006-10-25 21:39:01 +0000122 def readByte(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000123 pass
124
Mark Slee4ac459f2006-10-25 21:39:01 +0000125 def readI16(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000126 pass
127
Mark Slee4ac459f2006-10-25 21:39:01 +0000128 def readI32(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000129 pass
130
Mark Slee4ac459f2006-10-25 21:39:01 +0000131 def readI64(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000132 pass
133
Mark Slee4ac459f2006-10-25 21:39:01 +0000134 def readDouble(self):
Mark Sleec98d0502006-09-06 02:42:25 +0000135 pass
136
Mark Slee4ac459f2006-10-25 21:39:01 +0000137 def readString(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000138 pass
139
Mark Slee4ac459f2006-10-25 21:39:01 +0000140 def skip(self, type):
Mark Sleecde2b612006-09-03 21:13:07 +0000141 if type == TType.STOP:
142 return
143 elif type == TType.BOOL:
Mark Slee4ac459f2006-10-25 21:39:01 +0000144 self.readBool()
Mark Sleecde2b612006-09-03 21:13:07 +0000145 elif type == TType.BYTE:
Mark Slee4ac459f2006-10-25 21:39:01 +0000146 self.readByte()
Mark Sleecde2b612006-09-03 21:13:07 +0000147 elif type == TType.I16:
Mark Slee4ac459f2006-10-25 21:39:01 +0000148 self.readI16()
Mark Sleecde2b612006-09-03 21:13:07 +0000149 elif type == TType.I32:
Mark Slee4ac459f2006-10-25 21:39:01 +0000150 self.readI32()
Mark Sleecde2b612006-09-03 21:13:07 +0000151 elif type == TType.I64:
Mark Slee4ac459f2006-10-25 21:39:01 +0000152 self.readI64()
Mark Sleec98d0502006-09-06 02:42:25 +0000153 elif type == TType.DOUBLE:
Mark Slee4ac459f2006-10-25 21:39:01 +0000154 self.readDouble()
Mark Sleecde2b612006-09-03 21:13:07 +0000155 elif type == TType.STRING:
Mark Slee4ac459f2006-10-25 21:39:01 +0000156 self.readString()
Mark Sleecde2b612006-09-03 21:13:07 +0000157 elif type == TType.STRUCT:
Mark Slee4ac459f2006-10-25 21:39:01 +0000158 name = self.readStructBegin()
Mark Sleecde2b612006-09-03 21:13:07 +0000159 while True:
Mark Slee4ac459f2006-10-25 21:39:01 +0000160 (name, type, id) = self.readFieldBegin()
Mark Sleecde2b612006-09-03 21:13:07 +0000161 if type == TType.STOP:
162 break
Mark Slee4ac459f2006-10-25 21:39:01 +0000163 self.skip(type)
164 self.readFieldEnd()
165 self.readStructEnd()
Mark Sleecde2b612006-09-03 21:13:07 +0000166 elif type == TType.MAP:
Mark Slee4ac459f2006-10-25 21:39:01 +0000167 (ktype, vtype, size) = self.readMapBegin()
Mark Sleecde2b612006-09-03 21:13:07 +0000168 for i in range(size):
Mark Slee4ac459f2006-10-25 21:39:01 +0000169 self.skip(ktype)
170 self.skip(vtype)
171 self.readMapEnd()
Mark Sleecde2b612006-09-03 21:13:07 +0000172 elif type == TType.SET:
Mark Slee4ac459f2006-10-25 21:39:01 +0000173 (etype, size) = self.readSetBegin()
Mark Sleecde2b612006-09-03 21:13:07 +0000174 for i in range(size):
Mark Slee4ac459f2006-10-25 21:39:01 +0000175 self.skip(etype)
176 self.readSetEnd()
Mark Sleecde2b612006-09-03 21:13:07 +0000177 elif type == TType.LIST:
Mark Slee4ac459f2006-10-25 21:39:01 +0000178 (etype, size) = self.readListBegin()
Mark Sleecde2b612006-09-03 21:13:07 +0000179 for i in range(size):
Mark Slee4ac459f2006-10-25 21:39:01 +0000180 self.skip(etype)
181 self.readListEnd()
Mark Sleecde2b612006-09-03 21:13:07 +0000182
Mark Slee4ac459f2006-10-25 21:39:01 +0000183class TProtocolFactory:
Aditya Agarwal5c468192007-02-06 01:14:33 +0000184 def getProtocol(self, trans):
Mark Slee4ac459f2006-10-25 21:39:01 +0000185 pass