- I have a client and a server
- I want to send objects from client to server
- The objects must be send bundled together in a "big packet" containing many objects
- The objects could be in a random order
- The number of objects is not fixed
- There could be objects in the packet which are unknown to the server (so he needs to dump them)
I haven't got much experience with Serialization.
I would prefer Boosts Serialization-framework (if thats possible with it)
I thought of the following concept
(incomplete Pseudocode, inspired by C++, no specific Boost::Serialization-code):
class SerializableObject
{
virtual int getIdentifier() =0;
virtual Archive serialize() =0;
}
class SubclassA : public SerializableObject
{
int getIdentifier() { return 1; }
Archive serialize() { ... }
...
}
class SubclassB : public SerializableObject
{
int getIdentifier() { return 2; }
Archive serialize() { ... }
...
}
Now on Clientside:
void packAndSendData()
{
archive << objectA.getIdentifier();
archive << objectA;
archive << objectB.getIdentifier();
archive << objectB;
myNetworkObject.sendData(archive);
}
On Serverside:
void receiveAndUnpackData()
{
archive = myNetworkObject.receiveData();
while(archive.containsObjects()) //possible?
{
int type = archive.deserializeNextObject();
if(type == 1)
SubclassA objectA = archive.deserializeNextObject();
if(type == 2)
SubclassB objectB = archive.deserializeNextObject();
else
archive.dropNextObject(); //How to do this? Possible?
}
}
So the questions are:
- Is this a good concept or are there other possibilities?
- Is such a concept possible with Boost::Serialization
- If not: Are there other libs which could help implementing the concept?
I've tried to compress the problem as much as possible and to give as much info as I could. Hope it is understandable what I meant and what I try to achieve. If anyone has a better title for this question please fix the existing one, I had no idea of how describing this question with all of its aspects.