diff options
| author | Lexi Winter <lexi@hemlock.eden.le-fay.org> | 2025-03-26 00:15:07 +0000 |
|---|---|---|
| committer | Lexi Winter <lexi@hemlock.eden.le-fay.org> | 2025-03-26 00:15:07 +0000 |
| commit | 7b73fa68155fb997b7a7dbad9f1a0e4441ccec50 (patch) | |
| tree | 9649a852febd087d5eed9bfa0074c607eb7b1a9c | |
| parent | e1009551ac01e0ab6768855cc45cd18de98ca802 (diff) | |
| download | libnvxx-7b73fa68155fb997b7a7dbad9f1a0e4441ccec50.tar.gz libnvxx-7b73fa68155fb997b7a7dbad9f1a0e4441ccec50.tar.bz2 | |
README: briefly document the serialization interface
| -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}}; |
