C-Plus-Plus icon indicating copy to clipboard operation
C-Plus-Plus copied to clipboard

feat: added serializers

Open SharonIV0x86 opened this issue 1 year ago • 1 comments

Pull Request Title: Add Serializer and Deserializer Classes for Binary Serialization of Primitives and Strings

Description:

This pull request introduces a Serializer and Deserializer class for the serialization and deserialization of fundamental types such as int, double, char, and std::string in binary format. The feature supports both serialization of primitive types and strings, ensuring safe handling of binary data.

For primitives like int, float, and double, serialization is straightforward. However, serializing or deserializing std::string is more challenging due to its dynamic size and the absence of a delimiter (like null termination in C-style strings), which means we wouldn’t know how much to read or write.

To address this, the following approach is used:

Serializing:

  • Writing the size of the string immediately before the string data.
  • Adding a delimiter | at the end of the string to signify its boundary.

Deserializing:

  • Reading the size of the string before reading the actual string data to know how much to read.
  • Reading the string until the delimiter | is encountered.

Note: You can replace | with any other delimiter of your choice if needed.

Checklist:

  • [x] Added a description of the change.
  • [x] File name matches File Name Guidelines.
  • [x] Added tests and example; tests must pass.
  • [x] Added documentation to make the program self-explanatory and educational, following Doxygen guidelines.
  • [x] Relevant documentation/comments are changed or added.
  • [x] PR title follows semantic commit guidelines.
  • [x] Searched for previous suggestions before making a new one to avoid duplication.
  • [x] I acknowledge that all my contributions will be made under the project's license.

SharonIV0x86 avatar Oct 04 '24 19:10 SharonIV0x86