I need to serialize different objects (to messages) and send via tcp connection to server (both clients and server are c++) and I cannot use protobuf (only boost library is available). Is there already algorithm or example, or tutorial how one wood do this ( I need to consider that messages are going to change, new version with additional fields).
class Message {
public:
char type;
char version;
};
class Register : public Message {
public:
// version 1 of Register message
string first_name;
string last_name;
};
class Register : public Message {
public:
// version 2 of Register message
string first_name;
string last_name;
long salary;
};
class ChangeName : public Message {
public:
// version 1 of ChangeName message
string first_name;
};
// this is going to be transmitted ower tcp (length + type + version + data) like array of bytes
class TransmissionMessage {
public:
uint32_t length;
char type;
char version;
char data[length];
};
At the moment I have class for transmission which has fixed header which contains message type, message version and length and body /body is char array which contains serialized fields from message classes, same implementation on client and server/), but I ma not sure this is the best way to do, is there better way to do.