简单的匿名管道 - 您使用什么包装模型? (WinAPI、C++)

发布于 2024-07-10 02:32:36 字数 287 浏览 4 评论 0 原文

我在 Windows 中有两个正在运行的进程,每个进程都有一个到另一个进程的管道。

我想序列化一个复杂的类并将其从一个进程传输到另一个进程。 我已经制定了序列化过程,并且我知道管道正在发送二进制流。 我应该如何发送序列化数据? 我正在使用 WinAPI 和 C++。

我应该开发自定义协议吗? 如果是这样,它对于这个特定的类应该是通用的还是唯一的? 发送序列化类时可以保留虚拟表吗?

在这种情况下有没有常用的模型或设计模式? 如果有一点示例代码,我们将不胜感激。 谢谢你!

I have two running processes in Windows, and each process has a pipe to the other.

I want to serialize a complicated class and transmit it from one process to the other. I already have the serialization procedure worked out, and I understand that the pipes are sending binary streams. How should I go about sending my serialized data? I'm using WinAPI and C++.

Should I develop a custom protocol? If so, should it be generic or unique to this particular class? Can I preserve virtual tables when sending the serialized class?

Are there any models or design patterns that are commonly used in this case? A little bit of sample code would be greatly appreciated. Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

悲念泪 2024-07-17 02:32:36

这是 boost::serialization 的教程。 我可以想象它可以很好地通过管道发送数据并在另一端反序列化: http://www.boost.org/doc/libs/1_37_0/libs/serialization/doc/tutorial.html

Here is the tutorial for boost::serialization. I could imagine it would work fine sending the data over the pipe and deserializing on the other side: http://www.boost.org/doc/libs/1_37_0/libs/serialization/doc/tutorial.html

压抑⊿情绪 2024-07-17 02:32:36

您可能需要查看协议缓冲区

You might want to check out protocol buffer.

作妖 2024-07-17 02:32:36

您可以使用 boost::asio::windows::stream_handle 来像 io 一样组织 iostream,并异步执行。

You can use boost::asio::windows::stream_handle to organize iostream like io, and do it asynchronously.

寄离 2024-07-17 02:32:36

您不必担心 vtable,因为 boost serialize 会担心类型。 您唯一要做的就是确保序列化任何类型,然后在反序列化时在另一端使用完全相同的类型

You don't have to worry about vtables since boost serialize is going to worry about types. The only thing you have to do is make sure that what ever type is serialize, then you use the EXACT SAME TYPE on the other side when de-serializing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文