diff --git a/include/fc/crypto/aes.hpp b/include/fc/crypto/aes.hpp index f0c7616..e9f26af 100644 --- a/include/fc/crypto/aes.hpp +++ b/include/fc/crypto/aes.hpp @@ -1,4 +1,5 @@ #pragma once +#include #include #include #include diff --git a/include/fc/crypto/ripemd160.hpp b/include/fc/crypto/ripemd160.hpp index 912c392..de8d04e 100644 --- a/include/fc/crypto/ripemd160.hpp +++ b/include/fc/crypto/ripemd160.hpp @@ -71,6 +71,20 @@ class ripemd160 uint32_t _hash[5]; }; +namespace raw { + + template + inline void pack( T& ds, const ripemd160& ep, uint32_t _max_depth ) { + ds << ep; + } + + template + inline void unpack( T& ds, ripemd160& ep, uint32_t _max_depth ) { + ds >> ep; + } + +} + class variant; void to_variant( const ripemd160& bi, variant& v ); void from_variant( const variant& v, ripemd160& bi ); diff --git a/include/fc/crypto/sha224.hpp b/include/fc/crypto/sha224.hpp index a621208..6f2a156 100644 --- a/include/fc/crypto/sha224.hpp +++ b/include/fc/crypto/sha224.hpp @@ -70,6 +70,20 @@ class sha224 uint32_t _hash[7]; }; +namespace raw { + + template + inline void pack( T& ds, const sha224& ep, uint32_t _max_depth ) { + ds << ep; + } + + template + inline void unpack( T& ds, sha224& ep, uint32_t _max_depth ) { + ds >> ep; + } + +} + class variant; void to_variant( const sha224& bi, variant& v ); void from_variant( const variant& v, sha224& bi ); diff --git a/include/fc/crypto/sha256.hpp b/include/fc/crypto/sha256.hpp index 58bba9e..0954fc7 100644 --- a/include/fc/crypto/sha256.hpp +++ b/include/fc/crypto/sha256.hpp @@ -98,6 +98,20 @@ class sha256 uint64_t _hash[4]; }; +namespace raw { + + template + inline void pack( T& ds, const sha256& ep, uint32_t _max_depth ) { + ds << ep; + } + + template + inline void unpack( T& ds, sha256& ep, uint32_t _max_depth ) { + ds >> ep; + } + +} + typedef sha256 uint256; class variant; diff --git a/include/fc/crypto/sha512.hpp b/include/fc/crypto/sha512.hpp index ef10887..a4406c0 100644 --- a/include/fc/crypto/sha512.hpp +++ b/include/fc/crypto/sha512.hpp @@ -66,6 +66,20 @@ class sha512 uint64_t _hash[8]; }; +namespace raw { + + template + inline void pack( T& ds, const sha512& ep, uint32_t _max_depth ) { + ds << ep; + } + + template + inline void unpack( T& ds, sha512& ep, uint32_t _max_depth ) { + ds >> ep; + } + +} + typedef fc::sha512 uint512; class variant; diff --git a/include/fc/io/raw.hpp b/include/fc/io/raw.hpp index d7e8bcd..bea77a8 100644 --- a/include/fc/io/raw.hpp +++ b/include/fc/io/raw.hpp @@ -351,13 +351,10 @@ namespace fc { const uint32_t max_depth; }; + // Default pack/unpack functions for classes (if_class) are removed due to recursion issue. + // Classes should implement pack/unpack functions explicitly. template - struct if_class{ - template - static inline void pack( Stream& s, const T& v, uint32_t _max_depth ) { s << v; } - template - static inline void unpack( Stream& s, T& v, uint32_t _max_depth ) { s >> v; } - }; + struct if_class; template<> struct if_class { diff --git a/include/fc/io/raw_fwd.hpp b/include/fc/io/raw_fwd.hpp index 42e955a..157a745 100644 --- a/include/fc/io/raw_fwd.hpp +++ b/include/fc/io/raw_fwd.hpp @@ -22,6 +22,11 @@ namespace fc { class path; template class static_variant; + class sha224; + class sha256; + class sha512; + class ripemd160; + template class enum_type; namespace ip { class endpoint; } @@ -96,6 +101,15 @@ namespace fc { template void unpack( Stream& s, fc::ecc::private_key&, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); template void pack( Stream& s, const fc::ecc::private_key&, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); + template inline void unpack( Stream& s, fc::sha224&, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); + template inline void pack( Stream& s, const fc::sha224&, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); + template inline void unpack( Stream& s, fc::sha256&, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); + template inline void pack( Stream& s, const fc::sha256&, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); + template inline void unpack( Stream& s, fc::sha512&, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); + template inline void pack( Stream& s, const fc::sha512&, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); + template inline void unpack( Stream& s, fc::ripemd160&, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); + template inline void pack( Stream& s, const fc::ripemd160&, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); + template inline void pack( Stream& s, const T& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); template inline void unpack( Stream& s, T& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); diff --git a/tests/serialization_test.cpp b/tests/serialization_test.cpp index 1e35f86..e1e9a54 100644 --- a/tests/serialization_test.cpp +++ b/tests/serialization_test.cpp @@ -7,8 +7,8 @@ namespace fc { namespace test { struct item; - inline bool operator < ( const item& a, const item& b ); inline bool operator == ( const item& a, const item& b ); + inline bool operator < ( const item& a, const item& b ); struct item_wrapper { @@ -16,8 +16,11 @@ namespace fc { namespace test { item_wrapper(item&& it) { v.reserve(1); v.insert( it ); } boost::container::flat_set v; }; - inline bool operator < ( const item_wrapper& a, const item_wrapper& b ); - inline bool operator == ( const item_wrapper& a, const item_wrapper& b ); + + inline bool operator == ( const item_wrapper& a, const item_wrapper& b ) + { return ( std::tie( a.v ) == std::tie( b.v ) ); } + inline bool operator < ( const item_wrapper& a, const item_wrapper& b ) + { return ( std::tie( a.v ) < std::tie( b.v ) ); } struct item { @@ -29,17 +32,11 @@ namespace fc { namespace test { inline bool operator == ( const item& a, const item& b ) { return ( std::tie( a.level, a.w ) == std::tie( b.level, b.w ) ); } - inline bool operator < ( const item& a, const item& b ) { return ( std::tie( a.level, a.w ) < std::tie( b.level, b.w ) ); } - inline bool operator == ( const item_wrapper& a, const item_wrapper& b ) - { return ( std::tie( a.v ) == std::tie( b.v ) ); } - inline bool operator < ( const item_wrapper& a, const item_wrapper& b ) - { return ( std::tie( a.v ) < std::tie( b.v ) ); } - -} } +} } // namespace fc::test FC_REFLECT( fc::test::item_wrapper, (v) ); FC_REFLECT( fc::test::item, (level)(w) );