Boost logo

Boost Users :

From: Gerd Ritter (gerd.ritter_at_[hidden])
Date: 2007-01-08 05:56:50


 Hi,

I have a more fundamental question/inquiry about the serialization library.

What I want to do is to use the serialization library to send classes over a
socket. Even though archives are not supposed to be used at streams I
figured that it should be possible to create a oarchive on the sender side,
create a iarchive on the receiver side, and use these for multiple,
successive write / read operations in block mode.
In order to test that assumption I created a test program to see if it would
be possible. Here the pseudo code:

void sync_streams(stringstream &os, stringstream& os)
{
  // write data from one sting stream to the other
  // this emulates sending the data on a socket

   int rd_avail = os.tellp() - os.tellg();
  os.read(buffer, rd_avail);
  is.write(buffer, rd_avail);
}

stringstream os, is;

boost::archive::text_oarchive oa(os);
sync_streams(os, is); // sync preamble
boost::archive::text_iarchive ia(is);

 oa << object1;
sync_streams(os, is); // sync object block
ia >> rdObject1;

 oa << object2;
sync_streams(os, is); // sync object block
ia >> rdObject2;

While I made this work, I wonder if it is a hack or if this is a valid use
case for the serialization library. I looked at the asio projects
example/source, there it was done by using a full archive for each object to
be transmitted. Sending an archive every time seems a bit expensive too me,
since a full preamble is sent everytime and I would loose all the pointer
tracking and other great features from the serialization library.

Regards,

Gerd



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net