Yet Another Serialization
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
#include
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(
YAS_OBJECT("myobject", a, b, c)
);
// buf = {"a":3,"b":4,"c":3.14}
yas::load(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:
No open issues yet, or sync has not completed.