feat: finishing the ex00

This commit is contained in:
Raphael 2025-03-25 14:12:13 +01:00
parent 647c777037
commit 089d6bff84
5 changed files with 292 additions and 0 deletions

38
cpp06/ex01/main.cpp Normal file
View file

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/24 15:54:05 by rparodi #+# #+# */
/* Updated: 2025/03/25 13:59:15 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "Serializer.hpp"
void is_worked(int integer, std::string string, std::string name)
{
Data data;
data.integer = integer;
data.string = string;
uintptr_t serialized = Serializer::serialize(&data);
Data* deserialized;
try {
deserialized = Serializer::deserialize(serialized);
} catch (std::exception &e) {
std::cout << CLR_RED << e.what() << CLR_RESET << std::endl;
return;
}
std::cout << CLR_YELLOW << "\t[ Testing " << name << " ]" << CLR_RESET << CLR_RESET << std::endl;
std::cout << CLR_BLUE << "Serialized:" << std::endl << "\t" << CLR_GOLD << serialized << CLR_RESET << std::endl;
std::cout << CLR_BLUE << "Deserialized:" << std::endl << "\t" << CLR_GOLD << deserialized->string << std::endl << "\t" << deserialized->integer << std::endl << CLR_RESET << std::endl;
}
int main(void) {
is_worked(42, "Student at", "42 / Student at");
is_worked(1337, "Leet code", "1337 / leet code");
is_worked(0, "", "NULL");
return 0;
}