Monero
Classes | Namespaces | Macros | Functions
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 <boost/mpl/bool.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...
 

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 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 END_SERIALIZE()
 self-explanatory 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...
 
#define MAGIC_FIELD(m)
 
#define VERSION_FIELD(v)
 

Functions

template<class Archive , class T >
std::enable_if_t< is_blob_type< T >::type::value, booldo_serialize (Archive &ar, T &v)
 main function for dispatching serialization for a given pair of archive and value types More...
 
template<class Archive , class T >
std::enable_if_t< boost::is_integral< T >::value, booldo_serialize (Archive &ar, T &v)
 
template<class Archive , class T >
auto do_serialize (Archive &ar, T &v) -> decltype(v.member_do_serialize(ar), true)
 
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<class Archive >
bool serialization::detail::do_check_stream_state (Archive &ar, boost::mpl::bool_< true >, bool noeof)
 
template<class Archive >
bool serialization::detail::do_check_stream_state (Archive &ar, 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.

Macro Definition Documentation

◆ BEGIN_SERIALIZE

#define BEGIN_SERIALIZE ( )
Value:
template <bool W, template <bool> class Archive> \
bool member_do_serialize(Archive<W> &ar) {
binary_archive< false > ar
Definition: cold-outputs.cpp:54

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

BEGIN_SERIALIZE

◆ BEGIN_SERIALIZE_OBJECT

#define BEGIN_SERIALIZE_OBJECT ( )
Value:
template <bool W, template <bool> class Archive> \
bool member_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){
binary_archive< false > ar
Definition: cold-outputs.cpp:54
r
Definition: testupnpigd.py:61
int bool
Definition: stdbool.h:35

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

BEGIN_SERIALIZE_OBJECT

◆ BLOB_SERIALIZER

#define BLOB_SERIALIZER (   T)
Value:
template<> \
struct is_blob_type<T> { \
}
int type
Definition: superscalar.cpp:50
bool_constant< true > true_type
Definition: gtest-port.h:2210
a descriptor for dispatching serialize
Definition: serialization.h:58

makes the type have a blob serializer trait defined

BLOB_SERIALIZER

◆ END_SERIALIZE

#define END_SERIALIZE ( )
Value:
return ar.good(); \
}
binary_archive< false > ar
Definition: cold-outputs.cpp:54
bool good() const noexcept
Definition: binary_archive.h:99

self-explanatory

END_SERIALIZE

◆ FIELD

#define FIELD (   f)
Value:
do { \
ar.tag(#f); \
bool r = do_serialize(ar, f); \
if (!r || !ar.good()) return false; \
} while(0);
binary_archive< false > ar
Definition: cold-outputs.cpp:54
r
Definition: testupnpigd.py:61
std::enable_if_t< is_blob_type< T >::type::value, bool > do_serialize(Archive &ar, T &v)
main function for dispatching serialization for a given pair of archive and value types ...
Definition: serialization.h:69
bool good() const noexcept
Definition: binary_archive.h:99

tags the field with the variable name and then serializes it

FIELD(f)

◆ FIELD_N

#define FIELD_N (   t,
 
)
Value:
do { \
ar.tag(t); \
bool r = do_serialize(ar, f); \
if (!r || !ar.good()) return false; \
} while(0);
binary_archive< false > ar
Definition: cold-outputs.cpp:54
t
Definition: console.py:33
r
Definition: testupnpigd.py:61
std::enable_if_t< is_blob_type< T >::type::value, bool > do_serialize(Archive &ar, T &v)
main function for dispatching serialization for a given pair of archive and value types ...
Definition: serialization.h:69
bool good() const noexcept
Definition: binary_archive.h:99

serializes a field f tagged t

FIELD_N(t,f)

◆ FIELDS

#define FIELDS (   f)
Value:
do { \
bool r = do_serialize(ar, f); \
if (!r || !ar.good()) return false; \
} while(0);
binary_archive< false > ar
Definition: cold-outputs.cpp:54
r
Definition: testupnpigd.py:61
std::enable_if_t< is_blob_type< T >::type::value, bool > do_serialize(Archive &ar, T &v)
main function for dispatching serialization for a given pair of archive and value types ...
Definition: serialization.h:69
bool good() const noexcept
Definition: binary_archive.h:99

does not add a tag to the serialized value

FIELDS(f)

◆ MAGIC_FIELD

#define MAGIC_FIELD (   m)
Value:
std::string magic = m; \
do { \
ar.tag("magic"); \
ar.serialize_blob((void*)magic.data(), magic.size()); \
if (!ar.good()) return false; \
if (magic != m) return false; \
} while(0);
binary_archive< false > ar
Definition: cold-outputs.cpp:54
::std::string string
Definition: gtest-port.h:1097
bool good() const noexcept
Definition: binary_archive.h:99

MAGIC_FIELD(m)

◆ 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

◆ VARIANT_TAG

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

Adds the tag to the Archive of Type.

VARIANT_TAG

◆ VARINT_FIELD

#define VARINT_FIELD (   f)
Value:
do { \
ar.tag(#f); \
ar.serialize_varint(f); \
if (!ar.good()) return false; \
} while(0);
binary_archive< false > ar
Definition: cold-outputs.cpp:54
bool good() const noexcept
Definition: binary_archive.h:99

tags and serializes the varint f

VARINT_FIELD(f)

◆ VARINT_FIELD_N

#define VARINT_FIELD_N (   t,
 
)
Value:
do { \
ar.tag(t); \
ar.serialize_varint(f); \
if (!ar.good()) return false; \
} while(0);
binary_archive< false > ar
Definition: cold-outputs.cpp:54
t
Definition: console.py:33
bool good() const noexcept
Definition: binary_archive.h:99

tags (as t) and serializes the varint f

VARINT_FIELD_N(t, f)

◆ VERSION_FIELD

#define VERSION_FIELD (   v)
Value:
do { \
ar.tag("version"); \
ar.serialize_varint(version); \
if (!ar.good()) return false; \
} while(0);
binary_archive< false > ar
Definition: cold-outputs.cpp:54
unsigned int uint32_t
Definition: stdint.h:126
version
Supported socks variants.
Definition: socks.h:57
bool good() const noexcept
Definition: binary_archive.h:99

VERSION_FIELD(v)

Function Documentation

◆ do_serialize() [1/4]

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

main function for dispatching serialization for a given pair of archive and value types

Types marked true with is_blob_type<T> will be serialized as a blob, integral types will be serialized as integers, and types who have a member_do_serialize method will be serialized using that method. Booleans are serialized like blobs.

◆ do_serialize() [2/4]

template<class Archive , class T >
std::enable_if_t<boost::is_integral<T>::value, bool> do_serialize ( Archive &  ar,
T v 
)
inline

◆ do_serialize() [3/4]

template<class Archive , class T >
auto do_serialize ( Archive &  ar,
T v 
) -> decltype(v.member_do_serialize(ar), true)
inline

◆ do_serialize() [4/4]

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