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, method) >>> msg = jt.pack_request(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(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.1.tar.gz
(5.1 kB
view hashes)
Built Distribution
Close
Hashes for jsonthrift-0.1.1-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6f2bab795f3ef546e4fa920ec9cb80c95adb32ecf8599758784996907de029e |
|
MD5 | b53a56b6e06326456232cf6ff951e770 |
|
BLAKE2b-256 | d7101013e833207c2ef01e1aad063c6fb2830762f76a7eb0668340054878b31e |