Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from __future__ import absolute_import
- import sys, glob
- sys.path.insert(0, glob.glob('lib/py/build/lib.*')[0]) # run make and stay in trunk/ dir
- import thrift.protocol.TCompactProtocol as TCP
- import thrift.transport.TTransport as TTrans
- def test(x, dtype):
- transport = TTrans.TMemoryBuffer()
- tcp = TCP.TCompactProtocol(transport)
- tcp.state = TCP.VALUE_WRITE
- writer = getattr(tcp, 'write' + dtype)
- writer(x)
- tcp2 = TCP.TCompactProtocol(TTrans.TMemoryBuffer(transport.getvalue()))
- tcp2.state = TCP.VALUE_READ
- reader = getattr(tcp2, 'read' + dtype)
- y = reader()
- return y
- vals = {
- 'I64': [(1 << 63) - 1, (1 << 63)],
- 'I32': [2147483647, 2147483648, 3000000000],
- 'I16': [32767, 32768]
- }
- for dtype, vals in vals.iteritems():
- for x in vals:
- try:
- y = test(x, dtype)
- except Exception as exc:
- print 'FAILED %r %r (Due to: %r)' % (x, dtype, exc)
- continue
- if not x == y:
- print 'Decoded value %13r is different from input value %r' % (y, x)
- else:
- print 'Decoded value %13r OK' % y
Advertisement
Add Comment
Please, Sign In to add comment