file
JsonAllTypes.hInclude file for all helper functions for serializing types to rapidjson.
These helpers are designed so that every builtin type and user type can be serialized/deserialized with esp::io::addMember/readMember. The leads to uniform and readable serialization code. To achieve this, every user type defines toJsonValue/fromJsonValue, and then template versions of addMember/readMember will automatically use these.
toJsonValue/fromJsonValue for all types should go in the headers below. If the implementation is short, prefer an inline definition (for brevity). If the implementation is long, prefer a separate definition in the corresponding cpp.
See IOTest.cpp for example usage.
Namespaces
Functions
-
template<typename T>auto toJsonArrayHelper(const T* objects, int count, JsonAllocator& allocator) -> JsonGenericValue
- Helper to convert an array of objects to a json array object.
-
template<typename T>void addMember(rapidjson::
Value& value, rapidjson::GenericStringRef<char> name, const T& obj, JsonAllocator& allocator) -
template<typename T>auto readMember(const rapidjson::
Value& value, const char* tag, T& x) -> bool
Function documentation
template<typename T>
JsonGenericValue toJsonArrayHelper(const T* objects,
int count,
JsonAllocator& allocator)
Helper to convert an array of objects to a json array object.
Parameters | |
---|---|
objects | pointer to objects |
count | |
allocator | |
Returns | serialized json value |
Don't use this directly to serialize stl vectors; use addMember(d, "myvec", myvec, allocator) instead.
Note there is no corresponding "from" helper because that operation requires more error-handling and must be done case-by-case.