Electroneum
serialization.h File Reference

Simple DSL AAPI based on. More...

#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <string>
#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/integral_constant.hpp>
Include dependency graph for serialization.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  is_blob_type< T >
 a descriptor for dispatching serialize More...
 
struct  has_free_serializer< T >
 a descriptor for dispatching serialize More...
 
struct  is_basic_type< T >
 a descriptor for dispatching serialize More...
 
struct  is_basic_type< std::pair< F, S > >
 
struct  is_basic_type< std::string >
 
struct  serializer< Archive, T >
 ... wouldn't a class be better? More...
 

Namespaces

 serialization
 
 detail
 declaration and default definition for the functions used the API
 
 serialization::detail
 

Macros

#define BLOB_SERIALIZER(T)
 makes the type have a blob serializer trait defined More...
 
#define FREE_SERIALIZER(T)
 adds the has_free_serializer to the type More...
 
#define VARIANT_TAG(Archive, Type, Tag)
 Adds the tag to the Archive of Type. More...
 
#define BEGIN_SERIALIZE()
 Begins the environment of the DSL for describing how to serialize an of an archive type. More...
 
#define BEGIN_SERIALIZE_OBJECT()
 begins the environment of the DSL for described the serialization of an object More...
 
#define PREPARE_CUSTOM_VECTOR_SERIALIZATION(size, vec)   ::serialization::detail::prepare_custom_vector_serialization(size, vec, typename Archive<W>::is_saving())
 
#define PREPARE_CUSTOM_DEQUE_SERIALIZATION(size, vec)   ::serialization::detail::prepare_custom_deque_serialization(size, vec, typename Archive<W>::is_saving())
 
#define END_SERIALIZE()
 self-explanatory More...
 
#define VALUE(f)
 the same as FIELD(f) More...
 
#define FIELD_N(t, f)
 serializes a field f tagged t More...
 
#define FIELD(f)
 tags the field with the variable name and then serializes it More...
 
#define FIELDS(f)
 does not add a tag to the serialized value More...
 
#define VARINT_FIELD(f)
 tags and serializes the varint f More...
 
#define VARINT_FIELD_N(t, f)
 tags (as t) and serializes the varint f More...
 

Functions

template<class Archive , class T >
bool do_serialize (Archive &ar, T &v)
 just calls the serialize function defined for ar and v... More...
 
template<class Archive >
bool do_serialize (Archive &ar, bool &v)
 
template<typename T >
void serialization::detail::prepare_custom_vector_serialization (size_t size, std::vector< T > &vec, const boost::mpl::bool_< true > &)
 
template<typename T >
void serialization::detail::prepare_custom_vector_serialization (size_t size, std::vector< T > &vec, const boost::mpl::bool_< false > &)
 
template<typename T >
void serialization::detail::prepare_custom_deque_serialization (size_t size, std::deque< T > &vec, const boost::mpl::bool_< true > &)
 
template<typename T >
void serialization::detail::prepare_custom_deque_serialization (size_t size, std::deque< T > &vec, const boost::mpl::bool_< false > &)
 
template<class Stream >
bool serialization::detail::do_check_stream_state (Stream &s, boost::mpl::bool_< true >, bool noeof)
 
template<class Stream >
bool serialization::detail::do_check_stream_state (Stream &s, boost::mpl::bool_< false >, bool noeof)
 
template<class Archive >
bool serialization::check_stream_state (Archive &ar, bool noeof=false)
 
template<class Archive , class T >
bool serialization::serialize (Archive &ar, T &v)
 
template<class Archive , class T >
bool serialization::serialize_noeof (Archive &ar, T &v)
 

Detailed Description

Simple DSL AAPI based on.

is_blob_type and has_free_serializer are both descriptors for dispatching on to the serialize function.

The API itself defines a domain specific language via dirty macro hacks. Greenspun's tenth rule is very much in action throughout this entire code base.

Definition in file serialization.h.

Macro Definition Documentation

◆ BEGIN_SERIALIZE

#define BEGIN_SERIALIZE ( )
Value:
template <bool W, template <bool> class Archive> \
bool do_serialize(Archive<W> &ar) {
bool do_serialize(Archive &ar, T &v)
just calls the serialize function defined for ar and v...

Begins the environment of the DSL for describing how to serialize an of an archive type.

BEGIN_SERIALIZE

Definition at line 181 of file serialization.h.

◆ BEGIN_SERIALIZE_OBJECT

#define BEGIN_SERIALIZE_OBJECT ( )
Value:
template <bool W, template <bool> class Archive> \
bool do_serialize(Archive<W> &ar) { \
ar.begin_object(); \
bool r = do_serialize_object(ar); \
ar.end_object(); \
return r; \
} \
template <bool W, template <bool> class Archive> \
bool do_serialize_object(Archive<W> &ar){
int bool
Definition: stdbool.h:36
bool do_serialize(Archive &ar, T &v)
just calls the serialize function defined for ar and v...

begins the environment of the DSL for described the serialization of an object

BEGIN_SERIALIZE_OBJECT

Definition at line 190 of file serialization.h.

◆ BLOB_SERIALIZER

#define BLOB_SERIALIZER (   T)
Value:
template<> \
struct is_blob_type<T> { \
typedef boost::true_type type; \
}
bool_constant< true > true_type
Definition: gtest-port.h:2210
a descriptor for dispatching serialize
Definition: serialization.h:57

makes the type have a blob serializer trait defined

BLOB_SERIALIZER

Definition at line 147 of file serialization.h.

◆ END_SERIALIZE

#define END_SERIALIZE ( )
Value:
return ar.stream().good(); \
}

self-explanatory

END_SERIALIZE

Definition at line 214 of file serialization.h.

◆ FIELD

#define FIELD (   f)
Value:
do { \
ar.tag(#f); \
bool r = ::do_serialize(ar, f); \
if (!r || !ar.stream().good()) return false; \
} while(0);
bool do_serialize(Archive &ar, T &v)
just calls the serialize function defined for ar and v...

tags the field with the variable name and then serializes it

FIELD(f)

Definition at line 243 of file serialization.h.

◆ FIELD_N

#define FIELD_N (   t,
 
)
Value:
do { \
ar.tag(t); \
bool r = ::do_serialize(ar, f); \
if (!r || !ar.stream().good()) return false; \
} while(0);
bool do_serialize(Archive &ar, T &v)
just calls the serialize function defined for ar and v...

serializes a field f tagged t

FIELD_N(t,f)

Definition at line 232 of file serialization.h.

◆ FIELDS

#define FIELDS (   f)
Value:
do { \
bool r = ::do_serialize(ar, f); \
if (!r || !ar.stream().good()) return false; \
} while(0);
bool do_serialize(Archive &ar, T &v)
just calls the serialize function defined for ar and v...

does not add a tag to the serialized value

FIELDS(f)

Definition at line 254 of file serialization.h.

◆ FREE_SERIALIZER

#define FREE_SERIALIZER (   T)
Value:
template<> \
typedef boost::true_type type; \
}
bool_constant< true > true_type
Definition: gtest-port.h:2210
a descriptor for dispatching serialize
Definition: serialization.h:64

adds the has_free_serializer to the type

FREE_SERIALIZER

Definition at line 157 of file serialization.h.

◆ PREPARE_CUSTOM_DEQUE_SERIALIZATION

#define PREPARE_CUSTOM_DEQUE_SERIALIZATION (   size,
  vec 
)    ::serialization::detail::prepare_custom_deque_serialization(size, vec, typename Archive<W>::is_saving())

PREPARE_CUSTOM_DEQUE_SERIALIZATION

Definition at line 208 of file serialization.h.

◆ PREPARE_CUSTOM_VECTOR_SERIALIZATION

#define PREPARE_CUSTOM_VECTOR_SERIALIZATION (   size,
  vec 
)    ::serialization::detail::prepare_custom_vector_serialization(size, vec, typename Archive<W>::is_saving())

PREPARE_CUSTOM_VECTOR_SERIALIZATION

Definition at line 203 of file serialization.h.

◆ VALUE

#define VALUE (   f)
Value:
do { \
ar.tag(#f); \
bool r = ::do_serialize(ar, f); \
if (!r || !ar.stream().good()) return false; \
} while(0);
bool do_serialize(Archive &ar, T &v)
just calls the serialize function defined for ar and v...

the same as FIELD(f)

VALUE(f)

Definition at line 221 of file serialization.h.

◆ VARIANT_TAG

#define VARIANT_TAG (   Archive,
  Type,
  Tag 
)
Value:
template <bool W> \
static inline typename Archive<W>::variant_tag_type get_tag() { \
return Tag; \
} \
}
Type
Type of JSON value.
Definition: rapidjson.h:620

Adds the tag to the Archive of Type.

VARIANT_TAG

Definition at line 167 of file serialization.h.

◆ VARINT_FIELD

#define VARINT_FIELD (   f)
Value:
do { \
ar.tag(#f); \
ar.serialize_varint(f); \
if (!ar.stream().good()) return false; \
} while(0);

tags and serializes the varint f

VARINT_FIELD(f)

Definition at line 263 of file serialization.h.

◆ VARINT_FIELD_N

#define VARINT_FIELD_N (   t,
 
)
Value:
do { \
ar.tag(t); \
ar.serialize_varint(f); \
if (!ar.stream().good()) return false; \
} while(0);

tags (as t) and serializes the varint f

VARINT_FIELD_N(t, f)

Definition at line 274 of file serialization.h.

Function Documentation

◆ do_serialize() [1/2]

template<class Archive , class T >
do_serialize ( Archive &  ar,
T v 
)
inline

just calls the serialize function defined for ar and v...

Definition at line 123 of file serialization.h.

124 {
126 }
void serialize(Archive &a, unsigned_tx_set &x, const boost::serialization::version_type ver)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_serialize() [2/2]

template<class Archive >
bool do_serialize ( Archive &  ar,
bool v 
)
inline

Definition at line 128 of file serialization.h.

129 {
130  ar.serialize_blob(&v, sizeof(v));
131  return true;
132 }