a package for serializing json to/from thrift
Project description
jsonthrift is implemented for serializing and deserializing json to/from thrift.
Usage
>>> transport = 'TBufferedTransport' >>> protocol = 'TBinaryProtocol' >>> thrift_file = 'tutorial.thrift' >>> service = 'Calculator' >>> method = 'add' >>> params = {'num1': 1, 'num2': 3}>>> jt = JsonThrift(transport, protocol, thrift_file, service) >>> msg = jt.pack_request(method, params, 1) >>> response = send_and_recv(msg) # send msg to server, receive response >>> result = jt.unpack_response(response)[4] >>> print result {'success': 4}>>> method = 'calculate' >>> params = {'logid': 1, 'w':{'op': 4, 'num1': 1, 'num2': 0}} >>> msg = jt.pack_request(method, params, 2) >>> response = send_and_recv(msg) # send msg to server, receive response >>> result = jt.unpack_response(response)[4] >>> print result {'ouch': {'whatOp': 4, 'why': 'Cannot divide by 0'}}>>> # unpack_response returns a tuple, which contains: >>> # message size(TFramedTransport)/None(TBufferedTransport), >>> # message type, will be 2 for thrift REPLY message >>> # method >>> # sequence id >>> # return value
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
jsonthrift-0.1.4.tar.gz
(5.5 kB
view hashes)
Built Distribution
Close
Hashes for jsonthrift-0.1.4-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9ce499e95a3297cd64e38680099fed7c4bbcf838838d8dc277b9404b1c9b210 |
|
MD5 | be29920d9422c3ce16d32e5bdf1c4535 |
|
BLAKE2b-256 | d74578913142b055d84e5f0ee9889d16a0804aa6299eb3bacade2aba1f4e9229 |