-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
feat: added serializers #2756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: added serializers #2756
Conversation
Hey, thank you for the contribution question is this for hacktoberfest? |
others/serialization.cpp
Outdated
} | ||
|
||
/** | ||
* Serializes a string to a binary file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Serializes a string to a binary file. | |
* @brief Serializes a string to a binary file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still needs to be resolved
others/serialization.cpp
Outdated
* @param out The output stream (std::ofstream). | ||
* @param data The string to be serialized. | ||
* | ||
* The string is serialized by first storing its length, followed by the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* The string is serialized by first storing its length, followed by the | |
* @note The string is serialized by first storing its length, followed by the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still needs to be resolved
others/serialization.cpp
Outdated
|
||
if (!outFile || !inFile) { | ||
std::cerr << "Error opening files.\n"; | ||
return 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
main function should have nothing except
a call to the test function
and a return 0;
thus move all the tests from here to the test function
others/serialization.cpp
Outdated
* Deserializer. | ||
*/ | ||
|
||
void runTests() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void runTests() { | |
void tests() { |
others/serialization.cpp
Outdated
/** | ||
* @brief A test suite to perform extensive testing on the Serializer and | ||
* Deserializer. | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** | |
* @brief A test suite to perform extensive testing on the Serializer and | |
* Deserializer. | |
*/ | |
/** | |
* @brief self test implementation | |
* @return void | |
*/ |
others/serialization.cpp
Outdated
} | ||
}; | ||
|
||
void runTests(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests dont really need to be forward declared just move the definition from the tests at the bottom to here
Yes. |
others/serialization.cpp
Outdated
/** | ||
* @file | ||
* @brief A simple Serializer and Deserializer utility for fundamental data | ||
* types and strings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should add more details via a @detail
tag and your name with @author
tag
others/serialization.cpp
Outdated
} | ||
|
||
/** | ||
* Serializes a string to a binary file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still needs to be resolved
others/serialization.cpp
Outdated
* @param out The output stream (std::ofstream). | ||
* @param data The string to be serialized. | ||
* | ||
* The string is serialized by first storing its length, followed by the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still needs to be resolved
others/serialization.cpp
Outdated
|
||
int intResult; | ||
// Deserialize expecting binary data, this should fail | ||
Deserializer::deserialize(inFile, intResult); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the failure here?
others/serialization.cpp
Outdated
try { | ||
std::ifstream inFile("non_existent_file.bin", std::ios::binary); | ||
if (!inFile) { | ||
throw std::runtime_error("Error opening non-existent file."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we checking the errors on the user end the only failures to be checked are the ones raised by the class itself.
others/serialization.cpp
Outdated
* @return void | ||
*/ | ||
void tests() { | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this shouldnt be wrapped in a try catch loop. Tests should never fail.
others/serialization.cpp
Outdated
/** \namespace ciphers | ||
* \brief Classes for binary Serialization and Deserialization | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** \namespace ciphers | |
* \brief Classes for binary Serialization and Deserialization | |
*/ | |
/** | |
* @namespace serialization | |
* @brief Classes for binary Serialization and Deserialization | |
*/ |
others/serialization.cpp
Outdated
/** \namespace ciphers | ||
* \brief Classes for binary Serialization and Deserialization | ||
*/ | ||
namespace Serialization { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespace Serialization { | |
namespace serialization { |
This pull request has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Please ping one of the maintainers once you commit the changes requested or make improvements on the code. If this is not the case and you need some help, feel free to ask for help in our Gitter channel or our Discord server. Thank you for your contributions! |
Pull Request Title: Add Serializer and Deserializer Classes for Binary Serialization of Primitives and Strings
Description:
This pull request introduces a
Serializer
andDeserializer
class for the serialization and deserialization of fundamental types such asint
,double
,char
, andstd::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
, anddouble
, serialization is straightforward. However, serializing or deserializingstd::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:
|
at the end of the string to signify its boundary.Deserializing:
|
is encountered.Note: You can replace
|
with any other delimiter of your choice if needed.Checklist: