the-algorithm/twml/twml_common/serialize.py

17 lines
398 B
Python
Raw Normal View History

2023-04-11 15:04:51 +02:00
from thrift.protocol import TBinaryProtocol
from thrift.transport import TTransport
def serialize(obj):
tbuf = TTransport.TMemoryBuffer()
iproto = TBinaryProtocol.TBinaryProtocol(tbuf)
obj.write(iproto)
return tbuf.getvalue()
def deserialize(record, bytes):
tbuf = TTransport.TMemoryBuffer(bytes)
iproto = TBinaryProtocol.TBinaryProtocol(tbuf)
record.read(iproto)
return record