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

#include <json.h>

Static Public Member Functions

static void to_json (light_json &j, const T &data)
 
static void from_json (const light_json &j, T &data)
 

Detailed Description

template<typename T, typename Enable = void>
struct fpmas::io::json::light_serializer< T, Enable >

Default light_serializer implementation, that automatically falls back to the classic nlohmann::adl_serializer. In consequence, the light_serializer is effective only when explicit specialization are provided (see for example light_serializer<NodePtrWrapper<T>>).

The definition of a custom json type, light_json, and the associated serializer, json_serializer, allows to easily reuse classic adl_serializer implementations when required.

For example, the serialization of a DistributedId is the same for a classic nlohmann::json or for a light_json, so we shall not need to provide two implementations with the same serialization rules. This is indeed not required, since nlohmann::adl_serializer<DistributedId> serialization rules are provided using templated to_json and from_json methods:

namespace nlohmann {
template<>
struct adl_serializer<DistributedId> {
template<typename JsonType>
static void to_json(JsonType& j, const DistributedId& id) {
...
}
template<typename JsonType>
static void from_json(const JsonType& j, DistributedId& id) {
...
}
};
}
static void from_json(const light_json &j, T &data)
Definition: json.h:123
static void to_json(light_json &j, const T &data)
Definition: json.h:107

So, when it is required to serialize a DistributedId in the light_json serialization process, the method above are automatically instantiated so that the same serialization rules are used for any JsonType.

An other interesting use case occurs with DistributedEdges, where we typically want to use a light_json, so that source and target nodes are transmitted using a light_json: there is no need to serialize and transmit node data to instantiate a DistributedEdge.

However, the DistributedEdge serialization rules defined in adl_serializer<EdgePtrWrapper<T>> are the same for any JsonType, but that's not the case for the DistributedNode, where two serializer implementations are provided:

So even if the implementation of the DistributedEdge is unique, the proper DistributedNode serialization rules are automatically selected at compile time according to the provided JsonType.

Concretely, DistributedEdges can be serialized more efficiently using a light_json: see TypedMpi<DistributedEdge<T>>.

Template Parameters
Ttype to serialize
EnableSFINAE condition

Member Function Documentation

◆ to_json()

template<typename T , typename Enable = void>
static void fpmas::io::json::light_serializer< T, Enable >::to_json ( light_json j,
const T &  data 
)
inlinestatic

Serializes data into j using the regular nlohmann::adl_serializer implementation for T.

Equivalent to:

nlohmann::adl_serializer<T>::to_json(j, data);
Parameters
jjson output
datadata to serialize

◆ from_json()

template<typename T , typename Enable = void>
static void fpmas::io::json::light_serializer< T, Enable >::from_json ( const light_json j,
T &  data 
)
inlinestatic

Unserializes data from j using the regular nlohmann::adl_serializer implementation for T.

Equivalent to:

nlohmann::adl_serializer<T>::from_json(j, data);
Parameters
jjson input
datadata output

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