Cereal works pretty well so I may use it, but there's one more library I want to try first called tser.
This commit is contained in:
parent
ddf1ba955c
commit
713d400d17
9 changed files with 95 additions and 21 deletions
|
@ -4,6 +4,7 @@
|
|||
#include "config.hpp"
|
||||
#include <any>
|
||||
#include "dinkyecs.hpp"
|
||||
#include "components.hpp"
|
||||
|
||||
using namespace fmt;
|
||||
using std::string;
|
||||
|
@ -60,3 +61,46 @@ TEST_CASE("can go into a world", "[config]") {
|
|||
Config &cfg = world.get_the<Config>();
|
||||
REQUIRE(cfg["types"]["NUMBER"] == 1234);
|
||||
}
|
||||
|
||||
#include <cereal/types/unordered_map.hpp>
|
||||
#include <cereal/types/memory.hpp>
|
||||
#include <cereal/archives/json.hpp>
|
||||
#include <cereal/archives/binary.hpp>
|
||||
#include <cereal/archives/portable_binary.hpp>
|
||||
#include <fstream>
|
||||
|
||||
struct MyData
|
||||
{
|
||||
int x, y, z;
|
||||
std::string tiles;
|
||||
|
||||
template<class Archive>
|
||||
serialize(Archive &ar) { ar(x, y, z, tiles); }
|
||||
};
|
||||
|
||||
|
||||
TEST_CASE("test using serialization", "[config]") {
|
||||
{
|
||||
std::ofstream os("cereal.json", std::ios::binary);
|
||||
cereal::JSONOutputArchive oarchive(os);
|
||||
|
||||
MyData m1{1,2,3, "\u2849█Ω♣"};
|
||||
MyData m2{5,6,7, "\u2849█Ω♣"};
|
||||
MyData m3{8,9,10, "\u2849█Ω♣"};
|
||||
|
||||
oarchive(m1, m2, m3);
|
||||
}
|
||||
|
||||
{
|
||||
std::ifstream is("cereal.json", std::ios::binary);
|
||||
cereal::JSONInputArchive iarchive(is);
|
||||
|
||||
MyData m1, m2, m3;
|
||||
|
||||
iarchive(m1, m2, m3);
|
||||
|
||||
REQUIRE(m1.tiles == "\u2849█Ω♣");
|
||||
REQUIRE(m2.tiles == "\u2849█Ω♣");
|
||||
REQUIRE(m3.tiles == "\u2849█Ω♣");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue