Boost logo

Boost :

Subject: Re: [boost] [Serialization] Query
From: Robert Ramey (ramey_at_[hidden])
Date: 2010-07-23 19:02:57


Alapkumar Sinha wrote:
> Hi,
>
> I am trying to use the serialization library in the following
> scenario.
>
>
> 1. I create one instance of an object in one process
>
> 2. Serialize it either with binary/text archive
>
> 3. Then send it through unix local socket to another process
> where the process deserializes
>
> Whatever examples available, it shows just archiving like below
>
> std::ofstream ofs("filename");
> // use it to build and archive
> boost::archive::text_oarchive oa(ofs);
> // write class instance being pointed to
> // to the archive
> oa << g;
> /************/
>
> But after this
>
> 1. I would like to copy the archived data to a buffer
>
> 2. Send the buffer throught a socket something like
>
> boost::asio::write(socket, boost::asio::buffer( buffer,
> sizeof(buffer));
>
>
>
> Can someone help on how I can get this done.
>

a) use a stringstream so no file is necessary
> std::sstream ofs()

b) serialize to binary_oarchive to save time
> // use it to build and archive
> boost::archive::binary_oarchive oa(ofs);

send ofs.get_string()? via your favorite method

> One more question: does the call boost::asio::write does
> serialization internally? If yes, still I would need how to get the
> buffer as mentioned in the query above a my transmission mechanism
> might change.

serialization uses any conforming stream you supply to it.
streams use streambuf objects. You can use the standard ones or make your
own.

Robert Ramey


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk