I am using the following design for sending message between 2 application.
class InternalMessage
{
public:
InternalMessage(unsigned int messageId, unsigned int messageSize, INTERNAL_MESSAGE_TYPE messageType)
: messageId_(messageId), messageSize_(messageSize), messageType_(messageType) {}
virtual ~InternalMessage() {}
protected:
unsigned int messageId_;
unsigned int messageSize_;
INTERNAL_MESSAGE_TYPE messageType_;
};
And then there are several other messages which use inheritance:
class KeyPressMessage : public InternalMessage
{
public:
KeyPressMessage () : InternalMessage(RADIO_KEY_PRESS_MESSAGE_ID, sizeof(KeyPressMessage ), EVENT_MESSAGE_TYPE),
key_(INVALID_KEY) {}
virtual ~KeyPressMessage () {}
}
private:
KEY key_;
};
On recieving message we use base class pointer:
MsgHandler(InternalMessage* )
On sending message we use the derived class sizeof inorder to calculate the number of bytes to send:
sizeof(KeyPressMessage )
It seems that using such design is bad because sizeof derived class is includes virtual table (which can change between 32-bit and 64-bit OS). I would like to ask if there is some better way for ICD implementation of messeges handler and sender/receiever ? Do I need some serialize/de-serialize ?