fpmas 1.6
Static Public Member Functions | List of all members
fpmas::io::json::basic_datapack_serializer< T, PackType > Struct Template Reference

#include <json_datapack.h>

Static Public Member Functions

template<typename JsonType >
static void to_json (JsonType &json, const T &data)
 
template<typename JsonType >
static T from_json (const JsonType &json)
 

Detailed Description

template<typename T, typename PackType>
struct fpmas::io::json::basic_datapack_serializer< T, PackType >

An nlohmann serializer implementation based on object pack serialization.

Objects of type T are serialized using the fpmas::io::datapack library. ObjectPacks are then written and read directly to json as strings.

More particularly, the type T must be serializable into the provided PackType, that is itself based on fpmas::io::datapack::BasicObjectPack. For example, if PackType is fpmas::io::datapack::ObjectPack, the classical fpmas::io::datapack::Serializer custom serialization rules must be provided.

An fpmas::io::datapack::LightSerializer specialization must be provided for T when PackType is fpmas::io::datapack::LightObjectPack. See fpmas::io::datapack for more information.

Template Parameters
Ttype to serialize
PackTypeobject pack type used for serialization (fpmas::io::datapack::ObjectPack, fpmas::io::datapack::LightObjectPack,...)

Member Function Documentation

◆ to_json()

template<typename T , typename PackType >
template<typename JsonType >
static void fpmas::io::json::basic_datapack_serializer< T, PackType >::to_json ( JsonType &  json,
const T &  data 
)
inlinestatic

Serializes data to json.

An std::string instance is produced from the DataPack generated by PackType(data) and written to json.

Parameters
jsondestination json
datadata to serialize

◆ from_json()

template<typename T , typename PackType >
template<typename JsonType >
static T fpmas::io::json::basic_datapack_serializer< T, PackType >::from_json ( const JsonType &  json)
inlinestatic

Unserializes data from json.

A raw DataPack is retrieved from the pack and parsed using PackType::parse(), and an instance of T is unserialized using the PackType::get() method.

Parameters
jsonsource json
Returns
unserialized data

The documentation for this struct was generated from the following file: