Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serialize in c++, deserialze in python?

I have an application in C++ that serializes a structure using Google Protobuf like this

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

I want to unserialize this from python:

import  marketdata_pb2
...
md = marketdata_pb2.MarketDataDepth()
#what goes here? I don't see a marketdata_pb2.parsefromarray()
like image 934
user1676605 Avatar asked Oct 07 '22 15:10

user1676605


1 Answers

You're looking for md.ParseFromString(some_string_of_bytes). In Python 2.x "some string of bytes" is a str.

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

like image 195
Amber Avatar answered Oct 10 '22 02:10

Amber