简体   繁体   English

在C ++中使用Boost的命名管道序列化对象

[英]Serializing an object with Boost for Named Pipes in c++

I am attempting to serialize some EEG data from a command line application using the Boost library for the serialization and sending that serialized data over a named pipe to a user interface Form built in Visual Studio C++ 2010. 我正在尝试使用Boost库对来自命令行应用程序的一些EEG数据进行序列化以进行序列化,并通过命名管道将该序列化的数据发送到Visual Studio C ++ 2010中内置的用户界面Form。

From the boost library tutorial I am able to serialize my data structure, and, http://www.boost.org/doc/libs/1_48_0/libs/serialization/doc/tutorial.html#simplecase 从boost库教程中,我可以序列化我的数据结构,并且http://www.boost.org/doc/libs/1_48_0/libs/serialization/doc/tutorial.html#simplecase

from this tutorial on Win32 named pipes, I can construct pipes and send text between applications. 从Win32命名管道上的本教程中,我可以构造管道并在应用程序之间发送文本。 http://avid-insight.co.uk/joomla/component/k2/item/589-introduction-to-win32-named-pipes-cpp?tmpl=component&print=1 http://avid-insight.co.uk/joomla/component/k2/item/589-introduction-to-win32-named-pipes-cpp?tmpl=component&print=1

The boost library tutorial serializes for a text file: boost库教程序列化一个文本文件:

std::ofstream ofs("filename");

// create class instance
const gps_position g(35, 59, 24.567f);

// save data to archive
{
    boost::archive::text_oarchive oa(ofs);
    // write class instance to archive
    oa << g;
    // archive and stream closed when destructors are called
}

I want to know what do I need to serialize to in order to send my data structure over a named pipe? 我想知道要通过命名管道发送数据结构需要序列化什么? The IOstream c++ library seems to always need a file to stream to/from? IOstream c ++库似乎总是需要一个文件来流传输? http://www.cplusplus.com/reference/iostream/ http://www.cplusplus.com/reference/iostream/

I don't want o serialize to a file and I am not sure what to serialize to? 我不想o序列化到文件,并且不确定要序列化到什么? I would really appreciate it if you could tell me what I need to serialize to and it would be great if you could tell me whether another boost command will be required other than boost::archive:: text_oarchive , as I have been unable to find an alternative. 如果您能告诉我需要序列化的内容,我将不胜感激,如果您可以告诉我是否需要除boost :: archive :: text_oarchive之外的其他boost命令,那将是很棒的 ,因为我一直找不到替代。

Thank you for your time! 感谢您的时间! It is really appreciated! 真的很感激!

(This question has been asked before: Serialize and send a data structure using Boost? , but the person was told not to use boost as for his simple data structure boost would have too much overhead, so it really is still floating.) (此问题之前曾被问过: 使用Boost?序列化并发送数据结构 ,但是该人员被告知不要使用boost,因为他的简单数据结构boost将有太多开销,因此它实际上仍在浮动。)

Thanks ForEveR, very simple, don't know how I missed it! 感谢ForEveR,非常简单,不知道我是怎么想念它的! :) The solution in context with the two tutorials posted above: :)与上面发布的两个教程结合使用的解决方案:

    const EEG_Info g(35, 59, 24.567f);
std::stringstream MyStringStream ;
boost::archive::text_oarchive oa(MyStringStream);
    // write class instance to archive
    oa << g;
// This call blocks until a client process reads all the data

string strData;
strData = MyStringStream.str(); 


DWORD numBytesWritten = 0;
result = WriteFile(
    pipe, // handle to our outbound pipe
    strData.c_str(), // data to send
    strData.length(), // length of data to send (bytes)
    &numBytesWritten, // will store actual amount of data sent
    NULL // not using overlapped IO
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM