blob: e35688e1acd91a170c69bb8cd8366a9c3203d010 [file] [log] [blame]
Mark Slee92195ae2007-02-21 05:16:30 +00001from thrift.Thrift import TException
2
Mark Sleecde2b612006-09-03 21:13:07 +00003class TType:
4 STOP = 0
5 VOID = 1
6 BOOL = 2
7 BYTE = 3
Mark Sleec98d0502006-09-06 02:42:25 +00008 I08 = 3
9 DOUBLE = 4
Mark Sleecde2b612006-09-03 21:13:07 +000010 I16 = 6
11 I32 = 8
12 I64 = 10
13 STRING = 11
14 UTF7 = 11
15 STRUCT = 12
16 MAP = 13
17 SET = 14
18 LIST = 15
19 UTF8 = 16
20 UTF16 = 17
21
22class TMessageType:
23 CALL = 1
24 REPLY = 2
25
Mark Slee92195ae2007-02-21 05:16:30 +000026class TProtocolException(TException):
27
28 """Custom Protocol Exception class"""
29
30 UNKNOWN = 0
31 INVALID_DATA = 1
32 NEGATIVE_SIZE = 2
33 SIZE_LIMIT = 3
34
35 def __init__(self, type=UNKNOWN, message=None):
36 TException.__init__(self, message)
37 self.type = type
38
Mark Sleecde2b612006-09-03 21:13:07 +000039class TProtocolBase:
40
41 """Base class for Thrift protocol driver."""
42
Aditya Agarwal5c468192007-02-06 01:14:33 +000043 def __init__(self, trans):
44 self.trans = trans
Mark Slee4ac459f2006-10-25 21:39:01 +000045
46 def writeMessageBegin(self, name, type, seqid):
Mark Sleecde2b612006-09-03 21:13:07 +000047 pass
48
Mark Slee4ac459f2006-10-25 21:39:01 +000049 def writeMessageEnd(self):
Mark Sleecde2b612006-09-03 21:13:07 +000050 pass
51
Mark Slee4ac459f2006-10-25 21:39:01 +000052 def writeStructBegin(self, name):
Mark Sleecde2b612006-09-03 21:13:07 +000053 pass
54
Mark Slee4ac459f2006-10-25 21:39:01 +000055 def writeStructEnd(self):
Mark Sleecde2b612006-09-03 21:13:07 +000056 pass
57
Mark Slee4ac459f2006-10-25 21:39:01 +000058 def writeFieldBegin(self, name, type, id):
Mark Sleecde2b612006-09-03 21:13:07 +000059 pass
60
Mark Slee4ac459f2006-10-25 21:39:01 +000061 def writeFieldEnd(self):
Mark Sleecde2b612006-09-03 21:13:07 +000062 pass
63
Mark Slee4ac459f2006-10-25 21:39:01 +000064 def writeFieldStop(self):
Mark Sleecde2b612006-09-03 21:13:07 +000065 pass
66
Mark Slee4ac459f2006-10-25 21:39:01 +000067 def writeMapBegin(self, ktype, vtype, size):
Mark Sleecde2b612006-09-03 21:13:07 +000068 pass
69
Mark Slee4ac459f2006-10-25 21:39:01 +000070 def writeMapEnd(self):
Mark Sleecde2b612006-09-03 21:13:07 +000071 pass
72
Mark Slee4ac459f2006-10-25 21:39:01 +000073 def writeListBegin(self, etype, size):
Mark Sleecde2b612006-09-03 21:13:07 +000074 pass
75
Mark Slee4ac459f2006-10-25 21:39:01 +000076 def writeListEnd(self):
Mark Sleecde2b612006-09-03 21:13:07 +000077 pass
78
Mark Slee4ac459f2006-10-25 21:39:01 +000079 def writeSetBegin(self, etype, size):
Mark Sleecde2b612006-09-03 21:13:07 +000080 pass
81
Mark Slee4ac459f2006-10-25 21:39:01 +000082 def writeSetEnd(self):
Mark Sleecde2b612006-09-03 21:13:07 +000083 pass
84
Mark Slee4ac459f2006-10-25 21:39:01 +000085 def writeBool(self, bool):
Mark Sleecde2b612006-09-03 21:13:07 +000086 pass
87
Mark Slee4ac459f2006-10-25 21:39:01 +000088 def writeByte(self, byte):
Mark Sleecde2b612006-09-03 21:13:07 +000089 pass
90
Mark Slee4ac459f2006-10-25 21:39:01 +000091 def writeI16(self, i16):
Mark Sleecde2b612006-09-03 21:13:07 +000092 pass
93
Mark Slee4ac459f2006-10-25 21:39:01 +000094 def writeI32(self, i32):
Mark Sleecde2b612006-09-03 21:13:07 +000095 pass
96
Mark Slee4ac459f2006-10-25 21:39:01 +000097 def writeI64(self, i64):
Mark Sleecde2b612006-09-03 21:13:07 +000098 pass
99
Mark Slee4ac459f2006-10-25 21:39:01 +0000100 def writeDouble(self, dub):
Mark Sleec98d0502006-09-06 02:42:25 +0000101 pass
102
Mark Slee4ac459f2006-10-25 21:39:01 +0000103 def writeString(self, str):
Mark Sleecde2b612006-09-03 21:13:07 +0000104 pass
105
Mark Slee4ac459f2006-10-25 21:39:01 +0000106 def readMessageBegin(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000107 pass
108
Mark Slee4ac459f2006-10-25 21:39:01 +0000109 def readMessageEnd(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000110 pass
111
Mark Slee4ac459f2006-10-25 21:39:01 +0000112 def readStructBegin(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000113 pass
114
Mark Slee4ac459f2006-10-25 21:39:01 +0000115 def readStructEnd(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000116 pass
117
Mark Slee4ac459f2006-10-25 21:39:01 +0000118 def readFieldBegin(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000119 pass
120
Mark Slee4ac459f2006-10-25 21:39:01 +0000121 def readFieldEnd(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000122 pass
123
Mark Slee4ac459f2006-10-25 21:39:01 +0000124 def readMapBegin(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000125 pass
126
Mark Slee4ac459f2006-10-25 21:39:01 +0000127 def readMapEnd(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000128 pass
129
Mark Slee4ac459f2006-10-25 21:39:01 +0000130 def readListBegin(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000131 pass
132
Mark Slee4ac459f2006-10-25 21:39:01 +0000133 def readListEnd(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000134 pass
135
Mark Slee4ac459f2006-10-25 21:39:01 +0000136 def readSetBegin(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000137 pass
138
Mark Slee4ac459f2006-10-25 21:39:01 +0000139 def readSetEnd(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000140 pass
141
Mark Slee4ac459f2006-10-25 21:39:01 +0000142 def readBool(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000143 pass
144
Mark Slee4ac459f2006-10-25 21:39:01 +0000145 def readByte(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000146 pass
147
Mark Slee4ac459f2006-10-25 21:39:01 +0000148 def readI16(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000149 pass
150
Mark Slee4ac459f2006-10-25 21:39:01 +0000151 def readI32(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000152 pass
153
Mark Slee4ac459f2006-10-25 21:39:01 +0000154 def readI64(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000155 pass
156
Mark Slee4ac459f2006-10-25 21:39:01 +0000157 def readDouble(self):
Mark Sleec98d0502006-09-06 02:42:25 +0000158 pass
159
Mark Slee4ac459f2006-10-25 21:39:01 +0000160 def readString(self):
Mark Sleecde2b612006-09-03 21:13:07 +0000161 pass
162
Mark Slee4ac459f2006-10-25 21:39:01 +0000163 def skip(self, type):
Mark Sleecde2b612006-09-03 21:13:07 +0000164 if type == TType.STOP:
165 return
166 elif type == TType.BOOL:
Mark Slee4ac459f2006-10-25 21:39:01 +0000167 self.readBool()
Mark Sleecde2b612006-09-03 21:13:07 +0000168 elif type == TType.BYTE:
Mark Slee4ac459f2006-10-25 21:39:01 +0000169 self.readByte()
Mark Sleecde2b612006-09-03 21:13:07 +0000170 elif type == TType.I16:
Mark Slee4ac459f2006-10-25 21:39:01 +0000171 self.readI16()
Mark Sleecde2b612006-09-03 21:13:07 +0000172 elif type == TType.I32:
Mark Slee4ac459f2006-10-25 21:39:01 +0000173 self.readI32()
Mark Sleecde2b612006-09-03 21:13:07 +0000174 elif type == TType.I64:
Mark Slee4ac459f2006-10-25 21:39:01 +0000175 self.readI64()
Mark Sleec98d0502006-09-06 02:42:25 +0000176 elif type == TType.DOUBLE:
Mark Slee4ac459f2006-10-25 21:39:01 +0000177 self.readDouble()
Mark Sleecde2b612006-09-03 21:13:07 +0000178 elif type == TType.STRING:
Mark Slee4ac459f2006-10-25 21:39:01 +0000179 self.readString()
Mark Sleecde2b612006-09-03 21:13:07 +0000180 elif type == TType.STRUCT:
Mark Slee4ac459f2006-10-25 21:39:01 +0000181 name = self.readStructBegin()
Mark Sleecde2b612006-09-03 21:13:07 +0000182 while True:
Mark Slee4ac459f2006-10-25 21:39:01 +0000183 (name, type, id) = self.readFieldBegin()
Mark Sleecde2b612006-09-03 21:13:07 +0000184 if type == TType.STOP:
185 break
Mark Slee4ac459f2006-10-25 21:39:01 +0000186 self.skip(type)
187 self.readFieldEnd()
188 self.readStructEnd()
Mark Sleecde2b612006-09-03 21:13:07 +0000189 elif type == TType.MAP:
Mark Slee4ac459f2006-10-25 21:39:01 +0000190 (ktype, vtype, size) = self.readMapBegin()
Mark Sleecde2b612006-09-03 21:13:07 +0000191 for i in range(size):
Mark Slee4ac459f2006-10-25 21:39:01 +0000192 self.skip(ktype)
193 self.skip(vtype)
194 self.readMapEnd()
Mark Sleecde2b612006-09-03 21:13:07 +0000195 elif type == TType.SET:
Mark Slee4ac459f2006-10-25 21:39:01 +0000196 (etype, size) = self.readSetBegin()
Mark Sleecde2b612006-09-03 21:13:07 +0000197 for i in range(size):
Mark Slee4ac459f2006-10-25 21:39:01 +0000198 self.skip(etype)
199 self.readSetEnd()
Mark Sleecde2b612006-09-03 21:13:07 +0000200 elif type == TType.LIST:
Mark Slee4ac459f2006-10-25 21:39:01 +0000201 (etype, size) = self.readListBegin()
Mark Sleecde2b612006-09-03 21:13:07 +0000202 for i in range(size):
Mark Slee4ac459f2006-10-25 21:39:01 +0000203 self.skip(etype)
204 self.readListEnd()
Mark Sleecde2b612006-09-03 21:13:07 +0000205
Mark Slee4ac459f2006-10-25 21:39:01 +0000206class TProtocolFactory:
Aditya Agarwal5c468192007-02-06 01:14:33 +0000207 def getProtocol(self, trans):
Mark Slee4ac459f2006-10-25 21:39:01 +0000208 pass