菜鸟笔记
提升您的技术认知

python 使用thrift序列化与反序列化对象-ag真人游戏

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)
网站地图