diff --git a/src/serialization/serialization.h b/src/serialization/serialization.h index ee367f630..7ee92131b 100644 --- a/src/serialization/serialization.h +++ b/src/serialization/serialization.h @@ -50,6 +50,8 @@ #include #include +#include "common/va_args.h" + /*! \struct is_blob_type / is_blob_forced * * \brief descriptors for dispatching serialize: whether to take byte-wise copy/store to type @@ -93,6 +95,15 @@ inline bool do_serialize(Archive &ar, bool &v) ar.serialize_blob(&v, sizeof(v)); return true; } +template +inline auto do_serialize(Archive &ar, T &v, Args&&... args) + -> decltype(do_serialize_object(ar, v, args...), true) +{ + ar.begin_object(); + const bool r = do_serialize_object(ar, v, args...); + ar.end_object(); + return r && ar.good(); +} /* the following add a trait to a set and define the serialization DSL*/ @@ -180,18 +191,9 @@ inline bool do_serialize(Archive &ar, bool &v) * VARINT_FIELD_F(). Otherwise, this macro is similar to * BEGIN_SERIALIZE_OBJECT(), as you should list only field serializations. */ -#define BEGIN_SERIALIZE_OBJECT_FN(stype) \ - template class Archive> \ - bool do_serialize_object(Archive &ar, stype &v); \ - template class Archive> \ - bool do_serialize(Archive &ar, stype &v) { \ - ar.begin_object(); \ - bool r = do_serialize_object(ar, v); \ - ar.end_object(); \ - return r; \ - } \ - template class Archive> \ - bool do_serialize_object(Archive &ar, stype &v) { \ +#define BEGIN_SERIALIZE_OBJECT_FN(stype, ...) \ + template class Archive> \ + bool do_serialize_object(Archive &ar, stype &v VA_ARGS_COMMAPREFIX(__VA_ARGS__)) { /*! \macro PREPARE_CUSTOM_VECTOR_SERIALIZATION */ @@ -209,10 +211,10 @@ inline bool do_serialize(Archive &ar, bool &v) * * \brief serializes a field \a f tagged \a t */ -#define FIELD_N(t, f) \ +#define FIELD_N(t, f, ...) \ do { \ ar.tag(t); \ - bool r = do_serialize(ar, f); \ + bool r = do_serialize(ar, f VA_ARGS_COMMAPREFIX(__VA_ARGS__)); \ if (!r || !ar.good()) return false; \ } while(0); @@ -231,7 +233,7 @@ inline bool do_serialize(Archive &ar, bool &v) * * \brief tags the field with the variable name and then serializes it (for use in a free function) */ -#define FIELD_F(f) FIELD_N(#f, v.f) +#define FIELD_F(f, ...) FIELD_N(#f, v.f VA_ARGS_COMMAPREFIX(__VA_ARGS__)) /*! \macro FIELDS(f) *