#pragma once #include #include #include #include #include #include #include #include #include #include #include namespace fc { namespace bip = boost::interprocess; template void to_variant( const bip::deque< T... >& t, fc::variant& v, uint32_t max_depth ) { FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" ); --max_depth; std::vector vars(t.size()); for( size_t i = 0; i < t.size(); ++i ) { to_variant( t[i], vars[i], max_depth ); } v = std::move(vars); } template void from_variant( const fc::variant& v, bip::deque< T, A... >& d, uint32_t max_depth ) { FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" ); --max_depth; const variants& vars = v.get_array(); d.clear(); d.resize( vars.size() ); for( uint32_t i = 0; i < vars.size(); ++i ) { from_variant( vars[i], d[i], max_depth ); } } template void to_variant( const bip::map< K, V, T... >& var, fc::variant& vo, uint32_t max_depth ) { FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" ); --max_depth; std::vector< variant > vars(var.size()); size_t i = 0; for( auto itr = var.begin(); itr != var.end(); ++itr, ++i ) vars[i] = fc::variant( *itr, max_depth ); vo = vars; } template void to_variant( const bip::vector< T... >& t, fc::variant& v, uint32_t max_depth ) { FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" ); --max_depth; std::vector vars(t.size()); for( size_t i = 0; i < t.size(); ++i ) { to_variant( t[i], vars[i], max_depth ); } v = std::move(vars); } template void from_variant( const fc::variant& v, bip::vector< T, A... >& d, uint32_t max_depth ) { FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" ); --max_depth; const variants& vars = v.get_array(); d.clear(); d.resize( vars.size() ); for( uint32_t i = 0; i < vars.size(); ++i ) { from_variant( vars[i], d[i], max_depth ); } } template void to_variant( const bip::set< T... >& t, fc::variant& v, uint32_t max_depth ) { FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" ); --max_depth; std::vector vars; vars.reserve(t.size()); for( const auto& item : t ) { vars.emplace_back( variant( item, max_depth ) ); } v = std::move(vars); } template void to_variant( const bip::vector& t, fc::variant& v, uint32_t max_depth = 1 ) { if( t.size() ) v = variant(fc::to_hex(t.data(), t.size())); else v = ""; } template void from_variant( const fc::variant& v, bip::vector& d, uint32_t max_depth = 1 ) { auto str = v.as_string(); d.resize( str.size() / 2 ); if( d.size() ) { size_t r = fc::from_hex( str, d.data(), d.size() ); FC_ASSERT( r == d.size() ); } } namespace raw { namespace bip = boost::interprocess; template inline void pack( Stream& s, const bip::vector& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ) { FC_ASSERT( _max_depth > 0 ); --_max_depth; pack( s, unsigned_int((uint32_t)value.size()), _max_depth ); auto itr = value.begin(); auto end = value.end(); while( itr != end ) { fc::raw::pack( s, *itr, _max_depth ); ++itr; } } template inline void unpack( Stream& s, bip::vector& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ) { FC_ASSERT( _max_depth > 0 ); --_max_depth; unsigned_int size; unpack( s, size, _max_depth ); value.clear(); value.resize(size); for( auto& item : value ) fc::raw::unpack( s, item, _max_depth ); } } }