gpt4 book ai didi

c# - 在 C++ 中序列化然后在 C# 中反序列化?

转载 作者:可可西里 更新时间:2023-11-01 15:19:43 26 4
gpt4 key购买 nike

有没有简单的方法在 C++ 中序列化数据(XML 或二进制),然后在 C# 中反序列化数据?

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

客户端和服务器通过 tcp 连接进行通信,我真正想要的是序列化客户端内存中的数据,通过套接字将二进制数据传输到 c# 内存流,我可以将其反序列化为 c# 对象(消除文件创建、传输等),但我认为不存在类似的东西。不吝赐教。

编辑

我知道我可以在 C++ 应用程序中创建一个结构并在 C# 中定义它并以这种方式传输数据,但在我看来,这感觉就像我限制了可以发送的内容。我必须为对象等设置预定义的大小

最佳答案

Protocol Buffers可能对您有用。

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 .

关于c# - 在 C++ 中序列化然后在 C# 中反序列化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/726410/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com