我在 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!
发布评论
评论(4)
这是
boost::serialization
的教程。 我可以想象它可以很好地通过管道发送数据并在另一端反序列化: http://www.boost.org/doc/libs/1_37_0/libs/serialization/doc/tutorial.htmlHere 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您可能需要查看协议缓冲区。
You might want to check out protocol buffer.
您可以使用 boost::asio::windows::stream_handle 来像 io 一样组织 iostream,并异步执行。
You can use boost::asio::windows::stream_handle to organize iostream like io, and do it asynchronously.
您不必担心 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.