Skip to content

WKPlus/jsonthrift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jsonthrift Travis PyPI

jsonthrift is implemented for serializing and deserializing json to/from thrift.

Installation

   pip install jsonthrift

Usage

You can use it like this:

    >>> from jsonthrift.jsonthrift import JsonThrift
    >>> 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

Note

Only TBufferedTransport/TFramedTransport and TBinaryProtocol supported now.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published