[在Web开发中,难免遇到需要跨语言甚至跨平台进行通信的场景,不论是PHP到C还是PHP到Java,或者C到Java,都需要双方有一个约定的协议来打包和解包所传输的数据。双方自定义
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)
[java把对象放入memcached的时候需要序列化和反序列化才能确认类型,那python也应该有序列化的过程。google了一下,python是通过pickle来序列化的。 在了解pickle之前