I am writing a client/server app in C++ and need to realize simple protocol to sent and receive data correctly. I have a class for server protocol which can convert the message to my format and then convert it again from this format.
That what is server-side protocol looks like:
class BaseProtocol {
protected:
int NumberOfBytesInPackOfText;
std::string serviceString;
public:
BaseProtocol(int SizeOfTextPack, const char* extraString):
NumberOfBytesInPackOfText(SizeOfTextPack),
serviceString(extraString) {}
virtual std::string& convertToSystemMessage(const char* message)=0;
virtual std::string& convertToNativeMessage(const char* message)=0;
virtual ~BaseProtocol() {
NumberOfBytesInPackOfText = 0;
serviceString = "";
}
};
class SimpleProtocol: public BaseProtocol { public: SimpleProtocol(int SizeOfTextPack, const char* service): BaseProtocol(SizeOfTextPack, service) {} std::string& convertToSystemMessage(const char* nativeMessage); std::string& convertToNativeMessage(const char* systemMessage); };
Now I can not decide what will be the better decision to make to implement that protocol on client application. A friend class to the server protocol? Or may be I need to extract subclass from server protocol and then the client protocol will be derived from this class?