nixos/packages/biu/test/serialize.cpp

30 lines
680 B
C++
Raw Permalink Normal View History

2024-06-19 20:06:12 +08:00
# include <biu.hpp>
int main()
{
using namespace biu::literals;
2024-06-19 20:06:12 +08:00
struct student
{
int number;
std::string name;
std::vector<std::optional<double>> grade;
using serialize = zpp::bits::members<3>;
auto operator<=>(const student&) const = default;
};
student bob{ 123, "Bob", { 3.5, std::nullopt, 4.0 } };
auto serialized_bob = biu::serialize(bob);
auto bob2 = biu::deserialize<student>(serialized_bob);
assert(bob == bob2);
2024-09-12 02:21:20 +08:00
struct A
{
int x;
std::string y;
std::complex<double> z;
2024-09-12 02:21:20 +08:00
};
A a{ 123, "abc", 3i };
2024-09-12 02:21:20 +08:00
auto b = biu::deserialize<A>(biu::serialize(a));
assert(a.x == b.x);
assert(a.y == b.y);
assert(a.z == b.z);
2024-06-19 20:06:12 +08:00
}