Thrift serialization sniplet for Double Type

I am thinking that this code may be usable in the future for something like IOT solutions


#!/bin/env python

import base64

from thrift.protocol import TCompactProtocol
from thrift.TSerialization import deserialize

from foo.ttypes import FooObj

def main():

protocol_factory = TCompactProtocol.TCompactProtocolFactory
base64_string = ‘F9nO91PjpQtAAA==’

print ‘base64 string: ‘, base64_string

# deserialize the string back into an object
foo_blob = base64.urlsafe_b64decode(base64_string)
foo_obj = FooObj()
deserialize(foo_obj, foo_blob, protocol_factory=protocol_factory())
print ‘foo_obj.bar: ‘, foo_obj.bar

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s