mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-11-06 03:35:10 +01:00
17 lines
398 B
Python
17 lines
398 B
Python
|
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
|