Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

serialize in .NET, deserialize in C++

I have a .NET application which serializes an object in binary format. this object is a struct consisting of a few fields.

I must deserialize and use this object in a C++ application. I have no idea if there are any serialization libraries for C++, a google search hasn't turned up much.

What is the quickest way to accomplish this?

Thanks in advance. Roey.

Update : I have serialized using Protobuf-net , in my .NET application, with relative ease. I also get the .proto file that protobuf-net generated, using GetProto() command. In the .proto file, my GUID fields get a type of "bcl.guid", but C++ protoc.exe compiler does not know how to interpret them! What do I do with this?

like image 226
Roey Avatar asked Mar 02 '10 15:03

Roey


2 Answers

Can you edit the .NET app? If so why not use XML Serialization to output the data in a easy to import format?

like image 186
jamone Avatar answered Sep 17 '22 12:09

jamone


If you are using BinaryFormatter, then it will be virtually impossible. Don't go there...

Protocol buffers is designed to be portable, cross platform and version-tolerant (so it won't explode when you add new fields etc). Google provide the C++ version, and there are several C# versions freely available (including my own) - see here for the full list.

Small, fast, easy.

Note that the v1 of protobuf-net won't handle structs directly (you'll need a DTO class), but v2 (very soon) does have tested struct support.

like image 35
Marc Gravell Avatar answered Sep 21 '22 12:09

Marc Gravell