我在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()
答案 0 :(得分:3)
您正在寻找md.ParseFromString(some_string_of_bytes)
。在Python 2.x中,“一些字节串”是str
。
https://developers.google.com/protocol-buffers/docs/pythontutorial