fpmas 1.6
Static Public Member Functions | List of all members
fpmas::io::datapack::BasicJsonSerializer< T, JsonType > Struct Template Reference

#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)
 

Detailed Description

template<typename T, typename JsonType>
struct fpmas::io::datapack::BasicJsonSerializer< T, JsonType >

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.

Template Parameters
Ttype to serialize
JsonTypejson type used for serialization (nlohmann::json or fpmas::io::json::light_json).

Member Function Documentation

◆ size()

template<typename T , typename JsonType >
template<typename PackType >
static std::size_t fpmas::io::datapack::BasicJsonSerializer< T, JsonType >::size ( const PackType &  ,
const T &   
)
inlinestatic

Returns 0: the pack will be expanded by to_datapack() to avoid JsonType serialization to be performed twice.

◆ to_datapack()

template<typename T , typename JsonType >
template<typename PackType >
static void fpmas::io::datapack::BasicJsonSerializer< T, JsonType >::to_datapack ( PackType &  pack,
const T &  item 
)
inlinestatic

Serializes data to pack.

An std::string instance is produced using JsonType(data).dump() and written to pack.

Parameters
packdestination pack
itemitem to serialize

◆ from_datapack()

template<typename T , typename JsonType >
template<typename PackType >
static T fpmas::io::datapack::BasicJsonSerializer< T, JsonType >::from_datapack ( const PackType &  pack)
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.

Parameters
packsource pack
Returns
unserialized data

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