序列化在C + +然后反序列化在C#? [英] Serialize in C++ then deserialize in C#?

查看:159
本文介绍了序列化在C + +然后反序列化在C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个简单的方法来序列化数据在c ++(到xml或二进制),然后反序列化数据在C#?

Is there an easy way to serialize data in c++ (either to xml or binary), and then deserialize the data in C#?

我正在使用一些不运行.Net的远程WINNT计算机。我的服务器应用程序完全用C#编写,所以我想要一个简单的方法来共享简单的数据(键值对,大多数,也许一些SQL结果集的表示)。我认为最好的方法是在客户端上以某种预定义格式将数据写入xml,将xml文件传输到我的服务器,并有一个C#包装器将xml读入可用的c#对象。

I'm working with some remote WINNT machines that won't run .Net. My server app is written entirely in C#, so I want an easy way to share simple data (key value pairs mostly, and maybe some representation of a SQL result set). I figure the best way is going to be to write the data to xml in some predefined format on the client, transfer the xml file to my server, and have a C# wrapper read the xml into a usable c# object.

客户端和服务器通过tcp连接进行通信,我真正想要的是将客户端内存中的数据序列化,通过套接字将二进制数据传输到ac#内存流我可以反序列化为ac#对象(消除文件创建,传输等),但我不认为这样的存在。随意地启发我。

The client and server are communicating over a tcp connection, and what I really want is to serialize the data in memory on the client, transfer the binary data over the socket to a c# memory stream that I can deserialize into a c# object (eliminating file creation, transfer, etc), but I don't think anything like that exists. Feel free to enlighten me.

我知道我可以在c ++应用程序中创建一个结构体并在c#这样,但在我的头,这感觉像我限制可以发送。我必须为对象等设置预定义的大小。

I know I can create a struct in the c++ app and define it in c# and transfer data that way, but in my head, that feels like I'm limiting what can be sent. I'd have to set predefined sizes for objects, etc

推荐答案

协议缓冲区可能对您有用。


Google的语言中立,平台中立,可扩展的结构化数据序列化机制 - 认为XML,但更小,更快,更简单。您可以定义如何将数据结构化一次,然后您可以使用特殊生成的源代码,轻松地向各种数据流写入和读取结构化数据,并使用各种语言(Java,C ++或Python)。

Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler. You define how you want your data to be structured once, then you can use special generated source code to easily write and read your structured data to and from a variety of data streams and using a variety of languages – Java, C++, or Python.

.NET端口可从 Marc Gravell Jon Skeet

.NET ports are available from Marc Gravell and Jon Skeet.

这篇关于序列化在C + +然后反序列化在C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆