Ideologically, the serialization method should not affect the data type, so I better do something like this:
void serializeNullTerminated(char* bytes, const std::string& msg); void deserializeNullTerminated(const char* bytes, std::string& msg); void serializeWithSize(char* bytes, const std::string& msg); void deserializeWithSize(const char* bytes, std::string& msg);
Or pass an additional parameter to the functions:
void serialize(SerializationType st, char* bytes, const std::string& msg); void deserialize(SerializationType st, const char* bytes, std::string& msg);
Or you can make them a template:
template<SerializationType st> void serialize(char* bytes, const std::string& msg); template<SerializationType st> void deserialize(const char* bytes, std::string& msg);
The fact is that the user does not have to deal with various types of lines, in their code they must choose the method of serialization / deserialization.
source share