I'm confused about sending serialized classes using boost. I currently have a socket class with a method send (which I coded following gafferongames tutorials):
bool send(const IpAddress& destination, const void* data, int size);
It's used for sending some arbitrary data to another machine (usually a packet class).
Currently I have this code for sending packets:
ofstream fs("text.txt");
boost::archive::text_oarchive toa(fs);
toa & packet;
//Send the packet
socket.send({127, 0, 0, 1, serverPort}, &fs, sizeof(fs));
and this code for receiving packets:
auto fs = *(ifstream*)socket.getBuffer();
boost::archive::text_iarchive tia(fs);
Packet<DataType> typedPacket;
tia & packet;
I think this code signals my intent: I want to serialize the variable 'packet', send it to localhost, read the received data, deserialize it into another variable 'packet' on the receiving machine.
socket.getBuffer() contains whatever was passed to the const void* data parameter in send().
There are some problems with this code.. I don't want to create a file "text.txt".. But I serialization step crashes if I create the fs as ofstream fs(nullptr);.
The main thing that I am confused about is, what should I pass as the data-parameter in send()? fs or toa or something else? Id love it if there were something such as toa.getPointerToContentOfThisArchive() and toa.getSizeOfContentInThisArchive()because those I could use to send over network.. hmm.. Any help or suggestions is welcome!