From 213fd5168fd1f9b851c8585322021824e32f0e6b Mon Sep 17 00:00:00 2001 From: Nathaniel Date: Wed, 16 Mar 2022 18:59:36 -0500 Subject: [PATCH] Cleanup and organization Delete a useless and unused overload of raw::unpack Also, make the new custom serialization bit work for unreflected types (they still need typename reflection) --- include/fc/io/raw.hpp | 68 ++++++++++++++++++++------------------- include/fc/io/raw_fwd.hpp | 1 - 2 files changed, 35 insertions(+), 34 deletions(-) diff --git a/include/fc/io/raw.hpp b/include/fc/io/raw.hpp index 3a5a8da..e4d375f 100755 --- a/include/fc/io/raw.hpp +++ b/include/fc/io/raw.hpp @@ -199,14 +199,6 @@ namespace fc { vi.value = static_cast(v); } - template inline void unpack( Stream& s, const T& vi, uint32_t _max_depth ) - { - FC_ASSERT( _max_depth > 0 ); - T tmp; - fc::raw::unpack( s, tmp, _max_depth - 1 ); - FC_ASSERT( vi == tmp ); - } - template inline void pack( Stream& s, const char* v, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); @@ -418,40 +410,50 @@ namespace fc { }; template<> struct if_reflected { - private: - template using void_t = void; - - template - struct has_custom_packing : std::false_type {}; - template - struct has_custom_packing().fc_pack(std::declval&>(), 1)), - decltype(std::declval().fc_unpack(std::declval&>(), 1))>> - : std::true_type {}; - public: - template::value, bool> = true> - static inline void pack( Stream& s, const T& v, uint32_t _max_depth ) { - FC_ASSERT( _max_depth > 0 ); - v.fc_pack( s, _max_depth - 1 ); - } - template::value, bool> = true> + template static inline void pack( Stream& s, const T& v, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); if_enum< typename fc::reflector::is_enum >::pack( s, v, _max_depth - 1 ); } - template::value, bool> = true> - static inline void unpack( Stream& s, T& v, uint32_t _max_depth ) { - FC_ASSERT( _max_depth > 0 ); - v.fc_unpack( s, _max_depth - 1 ); - } - template::value, bool> = true> + template static inline void unpack( Stream& s, T& v, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); if_enum< typename fc::reflector::is_enum >::unpack( s, v, _max_depth - 1 ); } }; + template using void_t = void; + + template + struct has_custom_packing : std::false_type {}; + template + struct has_custom_packing().fc_pack(std::declval&>(), 1)), + decltype(std::declval().fc_unpack(std::declval&>(), 1))>> + : std::true_type {}; + + template::value, bool> = true> + static inline void pack( Stream& s, const T& v, uint32_t _max_depth ) { + FC_ASSERT( _max_depth > 0 ); + v.fc_pack( s, _max_depth - 1 ); + } + template::value, bool> = true> + static inline void pack( Stream& s, const T& v, uint32_t _max_depth ) { + FC_ASSERT( _max_depth > 0 ); + if_reflected< typename fc::reflector::is_defined >::pack( s, v, _max_depth - 1 ); + } + + template::value, bool> = true> + static inline void unpack( Stream& s, T& v, uint32_t _max_depth ) { + FC_ASSERT( _max_depth > 0 ); + v.fc_unpack( s, _max_depth - 1 ); + } + template::value, bool> = true> + static inline void unpack( Stream& s, T& v, uint32_t _max_depth ) { + FC_ASSERT( _max_depth > 0 ); + if_reflected< typename fc::reflector::is_defined >::unpack( s, v, _max_depth - 1 ); + } } // namesapce detail template @@ -642,13 +644,13 @@ namespace fc { template void pack( Stream& s, const T& v, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - fc::raw::detail::if_reflected< typename fc::reflector::is_defined >::pack( s, v, _max_depth - 1 ); + fc::raw::detail::pack(s, v, _max_depth); } template void unpack( Stream& s, T& v, uint32_t _max_depth ) { try { FC_ASSERT( _max_depth > 0 ); - fc::raw::detail::if_reflected< typename fc::reflector::is_defined >::unpack( s, v, _max_depth - 1 ); + fc::raw::detail::unpack(s, v, _max_depth); } FC_RETHROW_EXCEPTIONS( warn, "error unpacking ${type}", ("type",fc::get_typename::name() ) ) } template diff --git a/include/fc/io/raw_fwd.hpp b/include/fc/io/raw_fwd.hpp index 42e955a..8a60eaf 100755 --- a/include/fc/io/raw_fwd.hpp +++ b/include/fc/io/raw_fwd.hpp @@ -80,7 +80,6 @@ namespace fc { template void unpack( Stream& s, fc::optional& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); - template void unpack( Stream& s, const T& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); template void pack( Stream& s, const fc::optional& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); template void pack( Stream& s, const safe& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); template void unpack( Stream& s, fc::safe& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );