blob: 8314cf69df86425717498dbd342740119797ff82 [file] [log] [blame]
Mark Slee89e2bb82007-03-01 00:20:36 +00001#
David Reissea2cba82009-03-30 21:35:00 +00002# 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#
Mark Slee89e2bb82007-03-01 00:20:36 +000019
Nobuaki Sukegawae841b3d2015-11-17 11:01:17 +090020from thrift.Thrift import TException, TType, TFrozenDict
Nobuaki Sukegawa7b545b52016-01-11 13:46:04 +090021from thrift.transport.TTransport import TTransportException
Nobuaki Sukegawa760511f2015-11-06 21:24:16 +090022from ..compat import binary_to_str, str_to_binary
Mark Sleecde2b612006-09-03 21:13:07 +000023
Nobuaki Sukegawa299255a2016-01-06 14:52:50 +090024import six
25import sys
26from itertools import islice
27from six.moves import zip
28
Mark Slee92195ae2007-02-21 05:16:30 +000029
Bryan Duxbury69720412012-01-03 17:32:30 +000030class TProtocolException(TException):
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090031 """Custom Protocol Exception class"""
Mark Slee92195ae2007-02-21 05:16:30 +000032
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090033 UNKNOWN = 0
34 INVALID_DATA = 1
35 NEGATIVE_SIZE = 2
36 SIZE_LIMIT = 3
37 BAD_VERSION = 4
38 NOT_IMPLEMENTED = 5
39 DEPTH_LIMIT = 6
Neil Williams66a44c52018-08-13 16:12:24 -070040 INVALID_PROTOCOL = 7
Mark Slee92195ae2007-02-21 05:16:30 +000041
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090042 def __init__(self, type=UNKNOWN, message=None):
43 TException.__init__(self, message)
44 self.type = type
Mark Slee92195ae2007-02-21 05:16:30 +000045
Mark Sleecde2b612006-09-03 21:13:07 +000046
Nobuaki Sukegawab9c859a2015-12-21 01:10:25 +090047class TProtocolBase(object):
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090048 """Base class for Thrift protocol driver."""
Mark Sleecde2b612006-09-03 21:13:07 +000049
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090050 def __init__(self, trans):
51 self.trans = trans
Nobuaki Sukegawa6525f6a2016-02-11 13:58:39 +090052 self._fast_decode = None
53 self._fast_encode = None
Mark Slee4ac459f2006-10-25 21:39:01 +000054
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090055 @staticmethod
56 def _check_length(limit, length):
57 if length < 0:
58 raise TTransportException(TTransportException.NEGATIVE_SIZE,
59 'Negative length: %d' % length)
60 if limit is not None and length > limit:
61 raise TTransportException(TTransportException.SIZE_LIMIT,
62 'Length exceeded max allowed: %d' % limit)
Nobuaki Sukegawa7b545b52016-01-11 13:46:04 +090063
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090064 def writeMessageBegin(self, name, ttype, seqid):
65 pass
Mark Sleecde2b612006-09-03 21:13:07 +000066
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090067 def writeMessageEnd(self):
68 pass
Mark Sleecde2b612006-09-03 21:13:07 +000069
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090070 def writeStructBegin(self, name):
71 pass
Mark Sleecde2b612006-09-03 21:13:07 +000072
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090073 def writeStructEnd(self):
74 pass
Mark Sleecde2b612006-09-03 21:13:07 +000075
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090076 def writeFieldBegin(self, name, ttype, fid):
77 pass
Mark Sleecde2b612006-09-03 21:13:07 +000078
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090079 def writeFieldEnd(self):
80 pass
Mark Sleecde2b612006-09-03 21:13:07 +000081
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090082 def writeFieldStop(self):
83 pass
Mark Sleecde2b612006-09-03 21:13:07 +000084
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090085 def writeMapBegin(self, ktype, vtype, size):
86 pass
Mark Sleecde2b612006-09-03 21:13:07 +000087
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090088 def writeMapEnd(self):
89 pass
Mark Sleecde2b612006-09-03 21:13:07 +000090
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090091 def writeListBegin(self, etype, size):
92 pass
Mark Sleecde2b612006-09-03 21:13:07 +000093
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090094 def writeListEnd(self):
95 pass
Mark Sleecde2b612006-09-03 21:13:07 +000096
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090097 def writeSetBegin(self, etype, size):
98 pass
Mark Sleecde2b612006-09-03 21:13:07 +000099
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900100 def writeSetEnd(self):
101 pass
Mark Sleecde2b612006-09-03 21:13:07 +0000102
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900103 def writeBool(self, bool_val):
104 pass
Mark Sleecde2b612006-09-03 21:13:07 +0000105
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900106 def writeByte(self, byte):
107 pass
Mark Sleecde2b612006-09-03 21:13:07 +0000108
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900109 def writeI16(self, i16):
110 pass
Mark Sleecde2b612006-09-03 21:13:07 +0000111
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900112 def writeI32(self, i32):
113 pass
Mark Sleecde2b612006-09-03 21:13:07 +0000114
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900115 def writeI64(self, i64):
116 pass
Mark Sleecde2b612006-09-03 21:13:07 +0000117
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900118 def writeDouble(self, dub):
119 pass
Mark Sleec98d0502006-09-06 02:42:25 +0000120
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900121 def writeString(self, str_val):
122 self.writeBinary(str_to_binary(str_val))
Nobuaki Sukegawa760511f2015-11-06 21:24:16 +0900123
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900124 def writeBinary(self, str_val):
125 pass
Mark Sleecde2b612006-09-03 21:13:07 +0000126
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900127 def writeUtf8(self, str_val):
128 self.writeString(str_val.encode('utf8'))
Nobuaki Sukegawa397bd512016-01-06 14:43:15 +0900129
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900130 def readMessageBegin(self):
131 pass
Mark Sleecde2b612006-09-03 21:13:07 +0000132
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900133 def readMessageEnd(self):
134 pass
Mark Sleecde2b612006-09-03 21:13:07 +0000135
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900136 def readStructBegin(self):
137 pass
Mark Sleecde2b612006-09-03 21:13:07 +0000138
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900139 def readStructEnd(self):
140 pass
Mark Sleecde2b612006-09-03 21:13:07 +0000141
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900142 def readFieldBegin(self):
143 pass
Mark Sleecde2b612006-09-03 21:13:07 +0000144
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900145 def readFieldEnd(self):
146 pass
Mark Sleecde2b612006-09-03 21:13:07 +0000147
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900148 def readMapBegin(self):
149 pass
Mark Sleecde2b612006-09-03 21:13:07 +0000150
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900151 def readMapEnd(self):
152 pass
Mark Sleecde2b612006-09-03 21:13:07 +0000153
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900154 def readListBegin(self):
155 pass
Mark Sleecde2b612006-09-03 21:13:07 +0000156
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900157 def readListEnd(self):
158 pass
Mark Sleecde2b612006-09-03 21:13:07 +0000159
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900160 def readSetBegin(self):
161 pass
Mark Sleecde2b612006-09-03 21:13:07 +0000162
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900163 def readSetEnd(self):
164 pass
Mark Sleecde2b612006-09-03 21:13:07 +0000165
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900166 def readBool(self):
167 pass
Mark Sleecde2b612006-09-03 21:13:07 +0000168
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900169 def readByte(self):
170 pass
Mark Sleecde2b612006-09-03 21:13:07 +0000171
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900172 def readI16(self):
173 pass
Mark Sleecde2b612006-09-03 21:13:07 +0000174
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900175 def readI32(self):
176 pass
Mark Sleecde2b612006-09-03 21:13:07 +0000177
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900178 def readI64(self):
179 pass
Mark Sleecde2b612006-09-03 21:13:07 +0000180
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900181 def readDouble(self):
182 pass
Mark Sleec98d0502006-09-06 02:42:25 +0000183
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900184 def readString(self):
185 return binary_to_str(self.readBinary())
Nobuaki Sukegawa760511f2015-11-06 21:24:16 +0900186
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900187 def readBinary(self):
188 pass
Mark Sleecde2b612006-09-03 21:13:07 +0000189
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900190 def readUtf8(self):
191 return self.readString().decode('utf8')
Nobuaki Sukegawa397bd512016-01-06 14:43:15 +0900192
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900193 def skip(self, ttype):
Roger Meierad8154a2012-12-18 21:02:16 +0100194 if ttype == TType.STOP:
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900195 return
196 elif ttype == TType.BOOL:
197 self.readBool()
198 elif ttype == TType.BYTE:
199 self.readByte()
200 elif ttype == TType.I16:
201 self.readI16()
202 elif ttype == TType.I32:
203 self.readI32()
204 elif ttype == TType.I64:
205 self.readI64()
206 elif ttype == TType.DOUBLE:
207 self.readDouble()
208 elif ttype == TType.STRING:
209 self.readString()
210 elif ttype == TType.STRUCT:
211 name = self.readStructBegin()
212 while True:
213 (name, ttype, id) = self.readFieldBegin()
214 if ttype == TType.STOP:
215 break
216 self.skip(ttype)
217 self.readFieldEnd()
218 self.readStructEnd()
219 elif ttype == TType.MAP:
220 (ktype, vtype, size) = self.readMapBegin()
221 for i in range(size):
222 self.skip(ktype)
223 self.skip(vtype)
224 self.readMapEnd()
225 elif ttype == TType.SET:
226 (etype, size) = self.readSetBegin()
227 for i in range(size):
228 self.skip(etype)
229 self.readSetEnd()
230 elif ttype == TType.LIST:
231 (etype, size) = self.readListBegin()
232 for i in range(size):
233 self.skip(etype)
234 self.readListEnd()
Mark Sleecde2b612006-09-03 21:13:07 +0000235
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900236 # tuple of: ( 'reader method' name, is_container bool, 'writer_method' name )
237 _TTYPE_HANDLERS = (
238 (None, None, False), # 0 TType.STOP
239 (None, None, False), # 1 TType.VOID # TODO: handle void?
240 ('readBool', 'writeBool', False), # 2 TType.BOOL
241 ('readByte', 'writeByte', False), # 3 TType.BYTE and I08
242 ('readDouble', 'writeDouble', False), # 4 TType.DOUBLE
243 (None, None, False), # 5 undefined
244 ('readI16', 'writeI16', False), # 6 TType.I16
245 (None, None, False), # 7 undefined
246 ('readI32', 'writeI32', False), # 8 TType.I32
247 (None, None, False), # 9 undefined
248 ('readI64', 'writeI64', False), # 10 TType.I64
249 ('readString', 'writeString', False), # 11 TType.STRING and UTF7
250 ('readContainerStruct', 'writeContainerStruct', True), # 12 *.STRUCT
251 ('readContainerMap', 'writeContainerMap', True), # 13 TType.MAP
252 ('readContainerSet', 'writeContainerSet', True), # 14 TType.SET
253 ('readContainerList', 'writeContainerList', True), # 15 TType.LIST
254 (None, None, False), # 16 TType.UTF8 # TODO: handle utf8 types?
255 (None, None, False) # 17 TType.UTF16 # TODO: handle utf16 types?
256 )
Roger Meierf4eec7a2011-09-11 18:16:21 +0000257
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900258 def _ttype_handlers(self, ttype, spec):
259 if spec == 'BINARY':
260 if ttype != TType.STRING:
261 raise TProtocolException(type=TProtocolException.INVALID_DATA,
262 message='Invalid binary field type %d' % ttype)
263 return ('readBinary', 'writeBinary', False)
264 if sys.version_info[0] == 2 and spec == 'UTF8':
265 if ttype != TType.STRING:
266 raise TProtocolException(type=TProtocolException.INVALID_DATA,
267 message='Invalid string field type %d' % ttype)
268 return ('readUtf8', 'writeUtf8', False)
269 return self._TTYPE_HANDLERS[ttype] if ttype < len(self._TTYPE_HANDLERS) else (None, None, False)
Nobuaki Sukegawa299255a2016-01-06 14:52:50 +0900270
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900271 def _read_by_ttype(self, ttype, spec, espec):
Elvis Pranskevichus2d1fe882017-05-23 11:36:23 -0400272 reader_name, _, is_container = self._ttype_handlers(ttype, espec)
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900273 if reader_name is None:
274 raise TProtocolException(type=TProtocolException.INVALID_DATA,
275 message='Invalid type %d' % (ttype))
276 reader_func = getattr(self, reader_name)
277 read = (lambda: reader_func(espec)) if is_container else reader_func
278 while True:
279 yield read()
Nobuaki Sukegawabc7e4802015-11-14 19:23:27 +0900280
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900281 def readFieldByTType(self, ttype, spec):
Nobuaki Sukegawa6525f6a2016-02-11 13:58:39 +0900282 return next(self._read_by_ttype(ttype, spec, spec))
Roger Meierf4eec7a2011-09-11 18:16:21 +0000283
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900284 def readContainerList(self, spec):
285 ttype, tspec, is_immutable = spec
286 (list_type, list_len) = self.readListBegin()
287 # TODO: compare types we just decoded with thrift_spec
288 elems = islice(self._read_by_ttype(ttype, spec, tspec), list_len)
289 results = (tuple if is_immutable else list)(elems)
290 self.readListEnd()
291 return results
Roger Meierf4eec7a2011-09-11 18:16:21 +0000292
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900293 def readContainerSet(self, spec):
294 ttype, tspec, is_immutable = spec
295 (set_type, set_len) = self.readSetBegin()
296 # TODO: compare types we just decoded with thrift_spec
297 elems = islice(self._read_by_ttype(ttype, spec, tspec), set_len)
298 results = (frozenset if is_immutable else set)(elems)
299 self.readSetEnd()
300 return results
Roger Meierf4eec7a2011-09-11 18:16:21 +0000301
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900302 def readContainerStruct(self, spec):
303 (obj_class, obj_spec) = spec
304 obj = obj_class()
305 obj.read(self)
306 return obj
Bryan Duxbury69720412012-01-03 17:32:30 +0000307
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900308 def readContainerMap(self, spec):
309 ktype, kspec, vtype, vspec, is_immutable = spec
310 (map_ktype, map_vtype, map_len) = self.readMapBegin()
311 # TODO: compare types we just decoded with thrift_spec and
312 # abort/skip if types disagree
313 keys = self._read_by_ttype(ktype, spec, kspec)
314 vals = self._read_by_ttype(vtype, spec, vspec)
315 keyvals = islice(zip(keys, vals), map_len)
316 results = (TFrozenDict if is_immutable else dict)(keyvals)
317 self.readMapEnd()
318 return results
Roger Meierf4eec7a2011-09-11 18:16:21 +0000319
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900320 def readStruct(self, obj, thrift_spec, is_immutable=False):
321 if is_immutable:
322 fields = {}
323 self.readStructBegin()
324 while True:
325 (fname, ftype, fid) = self.readFieldBegin()
326 if ftype == TType.STOP:
327 break
328 try:
329 field = thrift_spec[fid]
330 except IndexError:
331 self.skip(ftype)
332 else:
333 if field is not None and ftype == field[1]:
334 fname = field[2]
335 fspec = field[3]
336 val = self.readFieldByTType(ftype, fspec)
337 if is_immutable:
338 fields[fname] = val
339 else:
340 setattr(obj, fname, val)
341 else:
342 self.skip(ftype)
343 self.readFieldEnd()
344 self.readStructEnd()
345 if is_immutable:
346 return obj(**fields)
Roger Meierf4eec7a2011-09-11 18:16:21 +0000347
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900348 def writeContainerStruct(self, val, spec):
349 val.write(self)
Roger Meierf4eec7a2011-09-11 18:16:21 +0000350
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900351 def writeContainerList(self, val, spec):
352 ttype, tspec, _ = spec
353 self.writeListBegin(ttype, len(val))
354 for _ in self._write_by_ttype(ttype, val, spec, tspec):
355 pass
356 self.writeListEnd()
Roger Meierf4eec7a2011-09-11 18:16:21 +0000357
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900358 def writeContainerSet(self, val, spec):
359 ttype, tspec, _ = spec
360 self.writeSetBegin(ttype, len(val))
361 for _ in self._write_by_ttype(ttype, val, spec, tspec):
362 pass
363 self.writeSetEnd()
Roger Meierf4eec7a2011-09-11 18:16:21 +0000364
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900365 def writeContainerMap(self, val, spec):
366 ktype, kspec, vtype, vspec, _ = spec
367 self.writeMapBegin(ktype, vtype, len(val))
368 for _ in zip(self._write_by_ttype(ktype, six.iterkeys(val), spec, kspec),
369 self._write_by_ttype(vtype, six.itervalues(val), spec, vspec)):
370 pass
371 self.writeMapEnd()
Roger Meierf4eec7a2011-09-11 18:16:21 +0000372
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900373 def writeStruct(self, obj, thrift_spec):
374 self.writeStructBegin(obj.__class__.__name__)
375 for field in thrift_spec:
376 if field is None:
377 continue
378 fname = field[2]
379 val = getattr(obj, fname)
380 if val is None:
381 # skip writing out unset fields
382 continue
383 fid = field[0]
384 ftype = field[1]
385 fspec = field[3]
386 self.writeFieldBegin(fname, ftype, fid)
387 self.writeFieldByTType(ftype, val, fspec)
388 self.writeFieldEnd()
389 self.writeFieldStop()
390 self.writeStructEnd()
Roger Meierf4eec7a2011-09-11 18:16:21 +0000391
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900392 def _write_by_ttype(self, ttype, vals, spec, espec):
Elvis Pranskevichus2d1fe882017-05-23 11:36:23 -0400393 _, writer_name, is_container = self._ttype_handlers(ttype, espec)
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900394 writer_func = getattr(self, writer_name)
395 write = (lambda v: writer_func(v, espec)) if is_container else writer_func
396 for v in vals:
397 yield write(v)
Nobuaki Sukegawa299255a2016-01-06 14:52:50 +0900398
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900399 def writeFieldByTType(self, ttype, val, spec):
Nobuaki Sukegawa6525f6a2016-02-11 13:58:39 +0900400 next(self._write_by_ttype(ttype, [val], spec, spec))
Roger Meierf4eec7a2011-09-11 18:16:21 +0000401
Nobuaki Sukegawa760511f2015-11-06 21:24:16 +0900402
Konrad Grochowski93fea152014-10-02 16:29:14 +0200403def checkIntegerLimits(i, bits):
Konrad Grochowski07218672014-10-09 12:18:25 +0200404 if bits == 8 and (i < -128 or i > 127):
Konrad Grochowski93fea152014-10-02 16:29:14 +0200405 raise TProtocolException(TProtocolException.INVALID_DATA,
Konrad Grochowskid5f3be52014-10-08 15:32:21 +0200406 "i8 requires -128 <= number <= 127")
Konrad Grochowski07218672014-10-09 12:18:25 +0200407 elif bits == 16 and (i < -32768 or i > 32767):
Konrad Grochowskid5f3be52014-10-08 15:32:21 +0200408 raise TProtocolException(TProtocolException.INVALID_DATA,
409 "i16 requires -32768 <= number <= 32767")
Konrad Grochowski07218672014-10-09 12:18:25 +0200410 elif bits == 32 and (i < -2147483648 or i > 2147483647):
Konrad Grochowskid5f3be52014-10-08 15:32:21 +0200411 raise TProtocolException(TProtocolException.INVALID_DATA,
412 "i32 requires -2147483648 <= number <= 2147483647")
Konrad Grochowski07218672014-10-09 12:18:25 +0200413 elif bits == 64 and (i < -9223372036854775808 or i > 9223372036854775807):
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900414 raise TProtocolException(TProtocolException.INVALID_DATA,
415 "i64 requires -9223372036854775808 <= number <= 9223372036854775807")
Bryan Duxbury69720412012-01-03 17:32:30 +0000416
Nobuaki Sukegawa760511f2015-11-06 21:24:16 +0900417
Nobuaki Sukegawab9c859a2015-12-21 01:10:25 +0900418class TProtocolFactory(object):
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900419 def getProtocol(self, trans):
420 pass