Yet Another Serialization
-
The easiest way to save and load some object or vars is to use the yas::save() and yas::load() functions like this:
#include <yas/serialize.hpp>
#include <yas/std_types.hpp>
int main() {
int a = 3, aa{};
short b = 4, bb{};
float c = 3.14, cc{};
constexpr std::size_t flags =
yas::mem // IO type
|yas::json; // IO format
auto buf = yas::save<flags>(
YAS_OBJECT("myobject", a, b, c)
);
// buf = {"a":3,"b":4,"c":3.14}
yas::load<flags>(buf,
YAS_OBJECT_NVP("myobject"
,("a", aa)
,("b", bb)
,("c", cc)
)
);
// a == aa && b == bb && c == cc;
}
The IO type can be one of yas::mem or yas::file.
The IO format can be one of yas::binary or yas::text or yas::json.
The YAS_OBJECT()/YAS_OBJECT_NVP()/YAS_OBJECT_STRUCT()/YAS_OBJECT_STRUCT_NVP() macro are declared here, example use is here.
More examples you can see here.
You can support the YAS project by donating:
231 followers · starred Dec 2016
251 followers · starred Mar 2014
1,949 followers · starred May 2021
267 followers · starred Feb 2021
Yet Another Serialization
-
The easiest way to save and load some object or vars is to use the yas::save() and yas::load() functions like this:
#include <yas/serialize.hpp>
#include <yas/std_types.hpp>
int main() {
int a = 3, aa{};
short b = 4, bb{};
float c = 3.14, cc{};
constexpr std::size_t flags =
yas::mem // IO type
|yas::json; // IO format
auto buf = yas::save<flags>(
YAS_OBJECT("myobject", a, b, c)
);
// buf = {"a":3,"b":4,"c":3.14}
yas::load<flags>(buf,
YAS_OBJECT_NVP("myobject"
,("a", aa)
,("b", bb)
,("c", cc)
)
);
// a == aa && b == bb && c == cc;
}
The IO type can be one of yas::mem or yas::file.
The IO format can be one of yas::binary or yas::text or yas::json.
The YAS_OBJECT()/YAS_OBJECT_NVP()/YAS_OBJECT_STRUCT()/YAS_OBJECT_STRUCT_NVP() macro are declared here, example use is here.
More examples you can see here.
You can support the YAS project by donating:
231 followers · starred Dec 2016
251 followers · starred Mar 2014
1,949 followers · starred May 2021
267 followers · starred Feb 2021