用c ++序列化,在python中反序列化?

时间:2012-09-17 04:23:44

标签: c++ python linux protocol-buffers

我在C ++中有一个应用程序,它使用Google Protobuf像这样序列化一个结构

int len = mdd.ByteSize();
char* buf = (char *)malloc(len);
mdd.SerializeToArray(buf, len);

我想从python中反序列化:

import  marketdata_pb2
...
md = marketdata_pb2.MarketDataDepth()
#what goes here? I don't see a marketdata_pb2.parsefromarray()

1 个答案:

答案 0 :(得分:3)

您正在寻找md.ParseFromString(some_string_of_bytes)。在Python 2.x中,“一些字节串”是str

https://developers.google.com/protocol-buffers/docs/pythontutorial