blob: be3cb1403c891f3923089dde1fc652e7514286f0 [file] [log] [blame]
Gavin McDonald0b75e1a2010-10-28 02:12:01 +00001#
2# Licensed to the Apache Software Foundation (ASF) under one
3# or more contributor license agreements. See the NOTICE file
4# distributed with this work for additional information
5# regarding copyright ownership. The ASF licenses this file
6# to you under the Apache License, Version 2.0 (the
7# "License"); you may not use this file except in compliance
8# with the License. You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing,
13# software distributed under the License is distributed on an
14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15# KIND, either express or implied. See the License for the
16# specific language governing permissions and limitations
17# under the License.
18#
19
20from thrift.Thrift import *
21
22class TProtocolException(TException):
23
24 """Custom Protocol Exception class"""
25
26 UNKNOWN = 0
27 INVALID_DATA = 1
28 NEGATIVE_SIZE = 2
29 SIZE_LIMIT = 3
30 BAD_VERSION = 4
31
32 def __init__(self, type=UNKNOWN, message=None):
33 TException.__init__(self, message)
34 self.type = type
35
36class TProtocolBase:
37
38 """Base class for Thrift protocol driver."""
39
40 def __init__(self, trans):
41 self.trans = trans
42
43 def writeMessageBegin(self, name, type, seqid):
44 pass
45
46 def writeMessageEnd(self):
47 pass
48
49 def writeStructBegin(self, name):
50 pass
51
52 def writeStructEnd(self):
53 pass
54
55 def writeFieldBegin(self, name, type, id):
56 pass
57
58 def writeFieldEnd(self):
59 pass
60
61 def writeFieldStop(self):
62 pass
63
64 def writeMapBegin(self, ktype, vtype, size):
65 pass
66
67 def writeMapEnd(self):
68 pass
69
70 def writeListBegin(self, etype, size):
71 pass
72
73 def writeListEnd(self):
74 pass
75
76 def writeSetBegin(self, etype, size):
77 pass
78
79 def writeSetEnd(self):
80 pass
81
82 def writeBool(self, bool):
83 pass
84
85 def writeByte(self, byte):
86 pass
87
88 def writeI16(self, i16):
89 pass
90
91 def writeI32(self, i32):
92 pass
93
94 def writeI64(self, i64):
95 pass
96
97 def writeDouble(self, dub):
98 pass
99
100 def writeString(self, str):
101 pass
102
103 def readMessageBegin(self):
104 pass
105
106 def readMessageEnd(self):
107 pass
108
109 def readStructBegin(self):
110 pass
111
112 def readStructEnd(self):
113 pass
114
115 def readFieldBegin(self):
116 pass
117
118 def readFieldEnd(self):
119 pass
120
121 def readMapBegin(self):
122 pass
123
124 def readMapEnd(self):
125 pass
126
127 def readListBegin(self):
128 pass
129
130 def readListEnd(self):
131 pass
132
133 def readSetBegin(self):
134 pass
135
136 def readSetEnd(self):
137 pass
138
139 def readBool(self):
140 pass
141
142 def readByte(self):
143 pass
144
145 def readI16(self):
146 pass
147
148 def readI32(self):
149 pass
150
151 def readI64(self):
152 pass
153
154 def readDouble(self):
155 pass
156
157 def readString(self):
158 pass
159
160 def skip(self, type):
161 if type == TType.STOP:
162 return
163 elif type == TType.BOOL:
164 self.readBool()
165 elif type == TType.BYTE:
166 self.readByte()
167 elif type == TType.I16:
168 self.readI16()
169 elif type == TType.I32:
170 self.readI32()
171 elif type == TType.I64:
172 self.readI64()
173 elif type == TType.DOUBLE:
174 self.readDouble()
175 elif type == TType.STRING:
176 self.readString()
177 elif type == TType.STRUCT:
178 name = self.readStructBegin()
179 while True:
180 (name, type, id) = self.readFieldBegin()
181 if type == TType.STOP:
182 break
183 self.skip(type)
184 self.readFieldEnd()
185 self.readStructEnd()
186 elif type == TType.MAP:
187 (ktype, vtype, size) = self.readMapBegin()
188 for i in range(size):
189 self.skip(ktype)
190 self.skip(vtype)
191 self.readMapEnd()
192 elif type == TType.SET:
193 (etype, size) = self.readSetBegin()
194 for i in range(size):
195 self.skip(etype)
196 self.readSetEnd()
197 elif type == TType.LIST:
198 (etype, size) = self.readListBegin()
199 for i in range(size):
200 self.skip(etype)
201 self.readListEnd()
202
203class TProtocolFactory:
204 def getProtocol(self, trans):
205 pass