繁体   English   中英

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

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

我正在尝试使用Boost库对来自命令行应用程序的一些EEG数据进行序列化以进行序列化,并通过命名管道将该序列化的数据发送到Visual Studio C ++ 2010中内置的用户界面Form。

从boost库教程中,我可以序列化我的数据结构,并且http://www.boost.org/doc/libs/1_48_0/libs/serialization/doc/tutorial.html#simplecase

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

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
}

我想知道要通过命名管道发送数据结构需要序列化什么? IOstream c ++库似乎总是需要一个文件来流传输? http://www.cplusplus.com/reference/iostream/

我不想o序列化到文件,并且不确定要序列化到什么? 如果您能告诉我需要序列化的内容,我将不胜感激,如果您可以告诉我是否需要除boost :: archive :: text_oarchive之外的其他boost命令,那将是很棒的 ,因为我一直找不到替代。

感谢您的时间! 真的很感激!

(此问题之前曾被问过: 使用Boost?序列化并发送数据结构 ,但是该人员被告知不要使用boost,因为他的简单数据结构boost将有太多开销,因此它实际上仍在浮动。)

感谢ForEveR,非常简单,不知道我是怎么想念它的! :)与上面发布的两个教程结合使用的解决方案:

    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