Skip to main content

libraries/eosiolib/core/eosio/serialize.hpp

Defines

Name
EOSLIB_REFLECT_MEMBER_OP(r, OP, elem)
EOSLIB_SERIALIZE(TYPE, MEMBERS)
EOSLIB_SERIALIZE_DERIVED(TYPE, BASE, MEMBERS)

Macros Documentation

define EOSLIB_REFLECT_MEMBER_OP

#define EOSLIB_REFLECT_MEMBER_OP(
r,
OP,
elem
)
OP t.elem

define EOSLIB_SERIALIZE

#define EOSLIB_SERIALIZE(
TYPE,
MEMBERS
)
template<typename DataStream> \
friend DataStream& operator << ( DataStream& ds, const TYPE& t ){ \
return ds BOOST_PP_SEQ_FOR_EACH( EOSLIB_REFLECT_MEMBER_OP, <<, MEMBERS );\
}\
template<typename DataStream> \
friend DataStream& operator >> ( DataStream& ds, TYPE& t ){ \
return ds BOOST_PP_SEQ_FOR_EACH( EOSLIB_REFLECT_MEMBER_OP, >>, MEMBERS );\
}

Parameters:

  • TYPE - the class to have its serialization and deserialization defined
  • MEMBERS - a sequence of member names. (field1)(field2)(field3)

Defines serialization and deserialization for a class

define EOSLIB_SERIALIZE_DERIVED

#define EOSLIB_SERIALIZE_DERIVED(
TYPE,
BASE,
MEMBERS
)
template<typename DataStream> \
friend DataStream& operator << ( DataStream& ds, const TYPE& t ){ \
ds << static_cast<const BASE&>(t); \
return ds BOOST_PP_SEQ_FOR_EACH( EOSLIB_REFLECT_MEMBER_OP, <<, MEMBERS );\
}\
template<typename DataStream> \
friend DataStream& operator >> ( DataStream& ds, TYPE& t ){ \
ds >> static_cast<BASE&>(t); \
return ds BOOST_PP_SEQ_FOR_EACH( EOSLIB_REFLECT_MEMBER_OP, >>, MEMBERS );\
}

Parameters:

  • TYPE - the class to have its serialization and deserialization defined
  • BASE - a sequence of base class names (basea)(baseb)(basec)
  • MEMBERS - a sequence of member names. (field1)(field2)(field3)

Defines serialization and deserialization for a class which inherits from other classes that have their serialization and deserialization defined

Source code

#include <boost/preprocessor/seq/for_each.hpp>
#include <boost/preprocessor/seq/enum.hpp>
#include <boost/preprocessor/seq/size.hpp>
#include <boost/preprocessor/seq/seq.hpp>
#include <boost/preprocessor/stringize.hpp>

#define EOSLIB_REFLECT_MEMBER_OP( r, OP, elem ) \
OP t.elem

#define EOSLIB_SERIALIZE( TYPE, MEMBERS ) \
template<typename DataStream> \
friend DataStream& operator << ( DataStream& ds, const TYPE& t ){ \
return ds BOOST_PP_SEQ_FOR_EACH( EOSLIB_REFLECT_MEMBER_OP, <<, MEMBERS );\
}\
template<typename DataStream> \
friend DataStream& operator >> ( DataStream& ds, TYPE& t ){ \
return ds BOOST_PP_SEQ_FOR_EACH( EOSLIB_REFLECT_MEMBER_OP, >>, MEMBERS );\
}

#define EOSLIB_SERIALIZE_DERIVED( TYPE, BASE, MEMBERS ) \
template<typename DataStream> \
friend DataStream& operator << ( DataStream& ds, const TYPE& t ){ \
ds << static_cast<const BASE&>(t); \
return ds BOOST_PP_SEQ_FOR_EACH( EOSLIB_REFLECT_MEMBER_OP, <<, MEMBERS );\
}\
template<typename DataStream> \
friend DataStream& operator >> ( DataStream& ds, TYPE& t ){ \
ds >> static_cast<BASE&>(t); \
return ds BOOST_PP_SEQ_FOR_EACH( EOSLIB_REFLECT_MEMBER_OP, >>, MEMBERS );\
}

Updated on 2022-12-05 at 15:38:08 +0000