您的位置:首页 > 编程语言 > Python开发

python 使用thrift序列化与反序列化对象

2016-01-20 10:03 351 查看
print('=============== thrift 对象序列化成二进制 ===============')
a = MessageHead(appId=1, functionId=1, tag=1, tokenId='adasge', direction=1, serverTokenId='asef')
from thrift_pojo.ttypes import *
from thrift.protocol.TBinaryProtocol import TBinaryProtocol
from thrift.transport.TTransport import TMemoryBuffer

tMemory_b = TMemoryBuffer()
tBinaryProtocol_b = TBinaryProtocol(tMemory_b)

a.write(tBinaryProtocol_b)
memory_buffer = tMemory_b.getvalue()
print('序列化成二进制:{}'.format(memory_buffer))
 print('=============== thrift 二进制反序列化成对象 ===============')
b = MessageHead()
tMemory_o = TMemoryBuffer(memory_buffer)
tBinaryProtocol_o = TBinaryProtocol(tMemory_o)

b.read(tBinaryProtocol_o)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: