On 2019-12-08 16:48, Vinnie Falco wrote:
Consider a simple struct with members a, b, and c. We might archive it this way:
a & BOOST_SERIALIZATION_NVP("a", a); b & BOOST_SERIALIZATION_NVP("b", b); c & BOOST_SERIALIZATION_NVP("c", c);
The resulting JSON might look like this:
{ "a" : 1, "b" : 2, "c" : 3 }
You are specifying the order of the entries in the serialization code, so I would expect this to be serialized into a JSON Array: [ ["a", 1], ["b", 2], ["c", 3] ] However, I acknowledge your point about reading "tagged" data from a JSON Object. This is fairly easy to do, but does involve a bit of boilerplate because the current serialization wrappers assume that classes are encoded as JSON Array, so we need to use non-intrusive serialization in order to by-pass this default behaviour. Assuming we have a "struct alphabet" with the a, b, c variables, then the following wrapper will read the variables in any user-modified order. No changes to the any of the APIs are needed: namespace trial { namespace protocol { namespace serialization { template <typename CharT> struct load_overloader<json::basic_iarchive<CharT>, alphabet> { static void load(json::basic_iarchive<CharT>& archive, alphabet& data, const unsigned int protocol_version) { archive.template load<json::token::begin_object>(); while (!archive.template at<json::token::end_object>()) { std::string key; archive.load_override(key, protocol_version); if (key == "a") { archive.load_override(data.a, protocol_version); } else if (key == "b") { archive.load_override(data.b, protocol_version); } else if (key == "c") { archive.load_override(data.c, protocol_version); } else { throw json::error(json::invalid_key); } } archive.template load<json::token::end_object>(); } }; }}}
I was referring to stackless coroutines. That type of coroutine still has stack variables. It just doesn't save the entire stack at a suspend point. The compiler can turn any function which has statically bounded stack requirements into a "stackless coroutine."
Do you have a reference to how these stackless-with-bounded-stack coroutines works?