![]() |
fpmas 1.6
|
#include <json_datapack.h>
Static Public Member Functions | |
| template<typename PackType > | |
| static std::size_t | size (const PackType &, const T &) |
| template<typename PackType > | |
| static void | to_datapack (PackType &pack, const T &item) |
| template<typename PackType > | |
| static T | from_datapack (const PackType &pack) |
A Serializer implementation based on json serialization.
Objects of type T are serialized using the nlohmann::json library. Json strings are then written and read directly to DataPack buffers.
More particularly, the type T must be serializable into the provided JsonType, that is itself based on nlohmann::basic_json. For example, if JsonType is nlohmann::json, the classical nlohmann::json custom serialization rules must be provided as explained at https://github.com/nlohmann/json#arbitrary-types-conversions.
An fpmas::io::json::light_serializer must be provided for T when JsonType is fpmas::io::json::light_json. See fpmas::io::json for more information.
| T | type to serialize |
| JsonType | json type used for serialization (nlohmann::json or fpmas::io::json::light_json). |
|
inlinestatic |
Returns 0: the pack will be expanded by to_datapack() to avoid JsonType serialization to be performed twice.
|
inlinestatic |
Serializes data to pack.
An std::string instance is produced using JsonType(data).dump() and written to pack.
| pack | destination pack |
| item | item to serialize |
|
inlinestatic |
Unserializes data from pack.
A json std::string is retrieved from the pack and parsed using JsonType::parse(), and an instance of T is unserialized using the JsonType::get() method.
| pack | source pack |