Question

Is it possible to Serialize a class in C++ and deserialize it to a similar class in C# using protocol buffer? I have tried Json serialization to overcome this serialization issue in different platforms but it has issues on some data types such as array list, etc. So any advice on using google's protocol buffer?

Was it helpful?

Solution

Protocol Buffers will allow you to describe a data structure, and serialize/deserialize that to objects in C++, Java, C# and other platforms. You don't (generally, anyway) get to serialize instances of your own classes - you serialize instances of the generated classes. (I know that protobuf-net allows you to decorate your own classes with attributes describing how to serialize them to protocol buffers, rather than having to use generated classes. I don't know if that has been done in C++.)

It's not clear whether that really meets your requirements, but protobufs certainly allow for cross-platform data exchange. It does have limitations in terms of what data can be serialized - it's all reasonably primitive, and you build up more complex structures from the primitive ones. That can be frustrating if you've already got your data model in code, and then have to reimplement it in protocol buffers, but it does work...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top