blob: 726189028eaf71d8c2065e0b9ed1366ab5c2d6a1 [file] [log] [blame]
Mark Sleee74306a2007-02-21 05:38:12 +00001class TType:
2 STOP = 0
3 VOID = 1
4 BOOL = 2
5 BYTE = 3
6 I08 = 3
7 DOUBLE = 4
8 I16 = 6
9 I32 = 8
10 I64 = 10
11 STRING = 11
12 UTF7 = 11
13 STRUCT = 12
14 MAP = 13
15 SET = 14
16 LIST = 15
17 UTF8 = 16
18 UTF16 = 17
19
20class TMessageType:
21 CALL = 1
22 REPLY = 2
23 EXCEPTION = 3
24
Mark Sleec9676562006-09-05 17:34:52 +000025class TProcessor:
26
27 """Base class for procsessor, which works on two streams."""
28
Mark Slee4ac459f2006-10-25 21:39:01 +000029 def process(iprot, oprot):
Mark Sleec9676562006-09-05 17:34:52 +000030 pass
Mark Slee92195ae2007-02-21 05:16:30 +000031
32class TException(Exception):
33
34 """Base class for all thrift exceptions."""
35
36 def __init__(self, message=None):
37 Exception.__init__(self, message)
38
39class TApplicationException(TException):
40
41 """Application level thrift exceptions."""
42
43 UNKNOWN = 0
44 UNKNOWN_METHOD = 1
45 INVALID_MESSAGE_TYPE = 2
46 WRONG_METHOD_NAME = 3
47 BAD_SEQUENCE_ID = 4
48 MISSING_RESULT = 5
49
50 def __init__(self, type=UNKNOWN, message=None):
51 TException.__init__(self, message)
52 self.type = type
53
54 def read(self, iprot):
55 iprot.readStructBegin()
56 while True:
57 (fname, ftype, fid) = iprot.readFieldBegin()
58 if ftype == TType.STOP:
59 break
60 if fid == 1:
61 if ftype == TType.STRING:
62 self.message = iprot.readString();
63 else:
64 iprot.skip(ftype)
65 elif fid == 2:
66 if ftype == TType.I32:
67 self.type = iprot.readI32();
68 else:
69 iprot.skip(ftype)
70 else:
71 iprot.skip(ftype)
72 iprot.readFieldEnd()
73 iprot.readStructEnd()
74
75 def write(self, oprot):
76 oprot.writeStructBegin('TApplicationException')
77 if self.message != None:
78 oprot.writeFieldBegin('message', TType.STRING, 1)
79 oprot.writeString(self.message)
80 oprot.writeFieldEnd()
81 if self.type != None:
82 oprot.writeFieldBegin('type', TType.I32, 2)
83 oprot.writeI32(self.type)
84 oprot.writeFieldEnd()
85 oprot.writeFieldStop()
86 oprot.writeStructEnd()