diff options
| -rw-r--r-- | README | 22 | ||||
| -rw-r--r-- | libnvxx/tests/nvxx_serialize.cc | 6 |
2 files changed, 23 insertions, 5 deletions
@@ -34,6 +34,28 @@ iterator interface: // do something with value... } +serialization interface: + + struct object { + std::uint64_t int_value{}; + std::string string_value{}; + std::vector<std::uint64_t> array_value; + }; + + template<> struct bsd::nv_schema<object> { + auto get() { + return bsd::nv_field("int value", &object::int_value) + >> bsd::nv_field("string value", &object::string_value) + >> bsd::nv_field("array value", &object::array_value); + } + }; + + // ... + + object obj{}; + nv_list nvl = bsd::nv_serialize(obj); + object obj2 = bsd::nv_deserialize<object>(nvl); + infrequently asked questions: Q: what version of FreeBSD does libnvxx require? diff --git a/libnvxx/tests/nvxx_serialize.cc b/libnvxx/tests/nvxx_serialize.cc index e3fbd5b..8ce5a21 100644 --- a/libnvxx/tests/nvxx_serialize.cc +++ b/libnvxx/tests/nvxx_serialize.cc @@ -202,10 +202,8 @@ struct object { std::vector<std::uint64_t> array_value; }; -namespace bsd { - template<> -struct nv_schema<::object> { +struct bsd::nv_schema<::object> { auto get() { return bsd::nv_field("int value", &object::int_value) >> bsd::nv_field("string value", &object::string_value) @@ -213,8 +211,6 @@ struct nv_schema<::object> { } }; -} // namespace bsd - TEST_CASE(nv_serialize) { auto obj = object{42, "quux", {42, 666, 1024}}; |
