use*_*605 5 c++ python linux protocol-buffers
我有一个C ++应用程序,可以像这样使用Google Protobuf序列化结构
int len = mdd.ByteSize();
char* buf = (char *)malloc(len);
mdd.SerializeToArray(buf, len);
Run Code Online (Sandbox Code Playgroud)
我想从python反序列化:
import marketdata_pb2
...
md = marketdata_pb2.MarketDataDepth()
#what goes here? I don't see a marketdata_pb2.parsefromarray()
Run Code Online (Sandbox Code Playgroud)
您正在寻找md.ParseFromString(some_string_of_bytes)
。在 Python 2.x 中,“某些字节字符串”是一个str
.
https://developers.google.com/protocol-buffers/docs/pythontutorial