Stripped tser.hpp down to the essentials so I can study it. No base64 encoding, less than comparison (wtf is that for), and I may even remove the 'json' output.

This commit is contained in:
Zed A. Shaw 2024-11-04 09:10:27 -05:00
parent 713d400d17
commit bf57713416
3 changed files with 317 additions and 1 deletions

View file

@ -75,7 +75,9 @@ struct MyData
std::string tiles;
template<class Archive>
serialize(Archive &ar) { ar(x, y, z, tiles); }
void serialize(Archive &ar) {
ar(x, y, z, tiles);
}
};
@ -104,3 +106,40 @@ TEST_CASE("test using serialization", "[config]") {
REQUIRE(m3.tiles == "\u2849█Ω♣");
}
}
#include <optional>
#include <iostream>
#include "tser.hpp"
enum class Item : char {
RADAR = 'R',
TRAP = 'T',
ORE = 'O'
};
struct Pixel {
int x = 0;
int y = 0;
DEFINE_SERIALIZABLE(Pixel, x, y);
};
struct Robot {
Pixel point;
std::optional<Item> item;
DEFINE_SERIALIZABLE(Robot, point, item);
};
TEST_CASE("test using tser for serialization", "[config]") {
auto robot = Robot{ Pixel{3,4}, Item::RADAR};
std::cout << robot << '\n';
std::cout << Robot() << '\n';
tser::BinaryArchive archive;
archive.save(robot);
std::string_view archive_view = archive.get_buffer();
auto loadedRobot = tser::load<Robot>(archive_view);
REQUIRE(loadedRobot == robot);
}