reading in C++ a serialized object from .net

B

bidou

Hello World,

Using (unmanaged) C++ only, I'd like to be able to read a binary
stream coming from a .net object standard serialization. For example,
let's assume I have a .net client which serializes some "POD" objects
using the standard .net serialization mechanism, then writes them to a
network stream, and finally a C++ server receives this stream, reads
it and "interprets/deserializes" it, creating the corresponding C++
objects.

So, is there:
- any kind of specification of the .net binary format used when
serializing objects ?
- an existing implementation dealing with this issue ?


Ex:
=== Client side ===

[Serializable]
public class MyObject {
public int n1 = 0;
public int n2 = 0;
public String str = null;
}

/* ... */

MyObject obj = new MyObject();
obj.n1 = 1;
obj.n2 = 24;
obj.str = "Some String";
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream("MyFile.bin", FileMode.Create,
FileAccess.Write, FileShare.None);
formatter.Serialize(stream, obj);
stream.Close();

=== Server side (C++) ===

How do I read and interpret the "MyFile.bin" file ?

Thanks in advance.
 
Y

Yuancai \(Charlie\) Ye

Hi,
I wrote an article entitled as A simple but handy utility for
serializing and de-serializing various data at the site
http://www.codeproject.com/csharp/uqueue.asp. It shows how to interop native
data types with managed data types. However, it doesn't work exactly like
the way you wanted. Wish it is helpful to you.


--
Yuancai (Charlie) Ye

Fast and securely accessing all of remote data sources anywhere with
SocketPro using batch/queue, asynchrony and parallel computation with online
compressing

See 30 well-tested and real OLEDB examples

www.udaparts.com
 
S

Sunny

Hi,

you can take a look at mono project sources to see how serialization
works. Their implementation is compatible with .net's one in most areas.

Sunny
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top