diff --git a/include/fc/container/flat.hpp b/include/fc/container/flat.hpp index 0b494f2..b323c25 100644 --- a/include/fc/container/flat.hpp +++ b/include/fc/container/flat.hpp @@ -10,36 +10,39 @@ namespace fc { template inline void pack( Stream& s, const flat_set& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - pack( s, unsigned_int((uint32_t)value.size()), _max_depth - 1 ); + --_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 - 1 ); + fc::raw::pack( s, *itr, _max_depth ); ++itr; } } template inline void unpack( Stream& s, flat_set& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - unsigned_int size; unpack( s, size, _max_depth - 1 ); + --_max_depth; + unsigned_int size; unpack( s, size, _max_depth ); value.clear(); FC_ASSERT( size.value*sizeof(T) < MAX_ARRAY_ALLOC_SIZE ); value.reserve(size.value); for( uint32_t i = 0; i < size.value; ++i ) { T tmp; - fc::raw::unpack( s, tmp, _max_depth - 1 ); + fc::raw::unpack( s, tmp, _max_depth ); value.insert( std::move(tmp) ); } } template inline void pack( Stream& s, const flat_map& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - pack( s, unsigned_int((uint32_t)value.size()), _max_depth - 1 ); + --_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 - 1 ); + fc::raw::pack( s, *itr, _max_depth ); ++itr; } } @@ -47,14 +50,15 @@ namespace fc { inline void unpack( Stream& s, flat_map& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - unsigned_int size; unpack( s, size, _max_depth - 1 ); + --_max_depth; + unsigned_int size; unpack( s, size, _max_depth ); value.clear(); FC_ASSERT( size.value*(sizeof(K)+sizeof(V)) < MAX_ARRAY_ALLOC_SIZE ); value.reserve(size.value); for( uint32_t i = 0; i < size.value; ++i ) { std::pair tmp; - fc::raw::unpack( s, tmp, _max_depth - 1 ); + fc::raw::unpack( s, tmp, _max_depth ); value.insert( std::move(tmp) ); } } @@ -62,12 +66,13 @@ namespace fc { template void pack( Stream& s, const bip::vector& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - pack( s, unsigned_int((uint32_t)value.size()), _max_depth - 1 ); + --_max_depth; + pack( s, unsigned_int((uint32_t)value.size()), _max_depth ); if( !std::is_fundamental::value ) { auto itr = value.begin(); auto end = value.end(); while( itr != end ) { - fc::raw::pack( s, *itr, _max_depth - 1 ); + fc::raw::pack( s, *itr, _max_depth ); ++itr; } } else { @@ -78,12 +83,13 @@ namespace fc { template void unpack( Stream& s, bip::vector& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); + --_max_depth; unsigned_int size; - unpack( s, size, _max_depth - 1 ); + unpack( s, size, _max_depth ); value.resize( size ); if( !std::is_fundamental::value ) { for( auto& item : value ) - unpack( s, item, _max_depth - 1 ); + unpack( s, item, _max_depth ); } else { s.read( (char*)value.data(), value.size() ); } diff --git a/include/fc/interprocess/container.hpp b/include/fc/interprocess/container.hpp index 6ed73f2..f61a68c 100644 --- a/include/fc/interprocess/container.hpp +++ b/include/fc/interprocess/container.hpp @@ -124,22 +124,24 @@ namespace fc { template inline void pack( Stream& s, const bip::vector& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ) { FC_ASSERT( _max_depth > 0 ); - pack( s, unsigned_int((uint32_t)value.size()), _max_depth - 1 ); + --_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 - 1 ); + 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 - 1 ); + unpack( s, size, _max_depth ); value.clear(); value.resize(size); for( auto& item : value ) - fc::raw::unpack( s, item, _max_depth - 1 ); + fc::raw::unpack( s, item, _max_depth ); } } } diff --git a/include/fc/io/raw.hpp b/include/fc/io/raw.hpp index 02873fc..d7e8bcd 100644 --- a/include/fc/io/raw.hpp +++ b/include/fc/io/raw.hpp @@ -21,31 +21,34 @@ namespace fc { template inline void pack( Stream& s, const Arg0& a0, Args... args, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - pack( s, a0, _max_depth - 1 ); - pack( s, args..., _max_depth - 1 ); + --_max_depth; + pack( s, a0, _max_depth ); + pack( s, args..., _max_depth ); } template inline void pack( Stream& s, const fc::exception& e, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - fc::raw::pack( s, e.code(), _max_depth - 1 ); - fc::raw::pack( s, std::string(e.name()), _max_depth - 1 ); - fc::raw::pack( s, std::string(e.what()), _max_depth - 1 ); - fc::raw::pack( s, e.get_log(), _max_depth - 1 ); + --_max_depth; + fc::raw::pack( s, e.code(), _max_depth ); + fc::raw::pack( s, std::string(e.name()), _max_depth ); + fc::raw::pack( s, std::string(e.what()), _max_depth ); + fc::raw::pack( s, e.get_log(), _max_depth ); } template inline void unpack( Stream& s, fc::exception& e, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); + --_max_depth; int64_t code; std::string name, what; log_messages msgs; - fc::raw::unpack( s, code, _max_depth - 1 ); - fc::raw::unpack( s, name, _max_depth - 1 ); - fc::raw::unpack( s, what, _max_depth - 1 ); - fc::raw::unpack( s, msgs, _max_depth - 1 ); + fc::raw::unpack( s, code, _max_depth ); + fc::raw::unpack( s, name, _max_depth ); + fc::raw::unpack( s, what, _max_depth ); + fc::raw::unpack( s, msgs, _max_depth ); e = fc::exception( fc::move(msgs), code, name, what ); } @@ -54,7 +57,7 @@ namespace fc { inline void pack( Stream& s, const fc::log_message& msg, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - fc::raw::pack( s, variant(msg), _max_depth - 1 ); + fc::raw::pack( s, variant(msg), _max_depth - 1 ); // TODO check variant depth? } template inline void unpack( Stream& s, fc::log_message& msg, uint32_t _max_depth ) @@ -62,7 +65,7 @@ namespace fc { FC_ASSERT( _max_depth > 0 ); fc::variant vmsg; fc::raw::unpack( s, vmsg, _max_depth - 1 ); - msg = vmsg.as(); + msg = vmsg.as(); // TODO check depth? } template @@ -250,16 +253,18 @@ namespace fc { template void pack( Stream& s, const fc::optional& v, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - fc::raw::pack( s, bool(!!v), _max_depth - 1 ); - if( !!v ) fc::raw::pack( s, *v, _max_depth - 1 ); + --_max_depth; + fc::raw::pack( s, bool(!!v), _max_depth ); + if( !!v ) fc::raw::pack( s, *v, _max_depth ); } template void unpack( Stream& s, fc::optional& v, uint32_t _max_depth ) { try { FC_ASSERT( _max_depth > 0 ); - bool b; fc::raw::unpack( s, b, _max_depth - 1 ); - if( b ) { v = T(); fc::raw::unpack( s, *v, _max_depth - 1 ); } + --_max_depth; + bool b; fc::raw::unpack( s, b, _max_depth ); + if( b ) { v = T(); fc::raw::unpack( s, *v, _max_depth ); } } FC_RETHROW_EXCEPTIONS( warn, "optional<${type}>", ("type",fc::get_typename::name() ) ) } // std::vector @@ -313,24 +318,24 @@ namespace fc { template struct pack_object_visitor { pack_object_visitor( const Class& _c, Stream& _s, uint32_t _max_depth ) - :c(_c),s(_s),max_depth(_max_depth) + :c(_c),s(_s),max_depth(_max_depth - 1) { FC_ASSERT( _max_depth > 0 ); } template void operator()( const char* name )const { - fc::raw::pack( s, c.*p, max_depth - 1 ); + fc::raw::pack( s, c.*p, max_depth ); } private: - const Class& c; - Stream& s; - uint32_t max_depth; + const Class& c; + Stream& s; + const uint32_t max_depth; }; template struct unpack_object_visitor { - unpack_object_visitor( Class& _c, Stream& _s, uint32_t _max_depth ) : c(_c),s(_s),max_depth(_max_depth) + unpack_object_visitor( Class& _c, Stream& _s, uint32_t _max_depth ) : c(_c),s(_s),max_depth(_max_depth - 1) { FC_ASSERT( _max_depth > 0 ); } @@ -338,12 +343,12 @@ namespace fc { template inline void operator()( const char* name )const { try { - fc::raw::unpack( s, c.*p, max_depth - 1 ); + fc::raw::unpack( s, c.*p, max_depth ); } FC_RETHROW_EXCEPTIONS( warn, "Error unpacking field ${field}", ("field",name) ) } private: Class& c; Stream& s; - uint32_t max_depth; + const uint32_t max_depth; }; template @@ -427,25 +432,27 @@ namespace fc { template inline void pack( Stream& s, const std::unordered_set& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth - 1 ); + --_max_depth; + fc::raw::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 - 1 ); + fc::raw::pack( s, *itr, _max_depth ); ++itr; } } template inline void unpack( Stream& s, std::unordered_set& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - unsigned_int size; fc::raw::unpack( s, size, _max_depth - 1 ); + --_max_depth; + unsigned_int size; fc::raw::unpack( s, size, _max_depth ); value.clear(); FC_ASSERT( size.value*sizeof(T) < MAX_ARRAY_ALLOC_SIZE ); value.reserve(size.value); for( uint32_t i = 0; i < size.value; ++i ) { T tmp; - fc::raw::unpack( s, tmp, _max_depth - 1 ); + fc::raw::unpack( s, tmp, _max_depth ); value.insert( std::move(tmp) ); } } @@ -454,25 +461,28 @@ namespace fc { template inline void pack( Stream& s, const std::pair& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - fc::raw::pack( s, value.first, _max_depth - 1 ); - fc::raw::pack( s, value.second, _max_depth - 1 ); + --_max_depth; + fc::raw::pack( s, value.first, _max_depth ); + fc::raw::pack( s, value.second, _max_depth ); } template inline void unpack( Stream& s, std::pair& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - fc::raw::unpack( s, value.first, _max_depth - 1 ); - fc::raw::unpack( s, value.second, _max_depth - 1 ); + --_max_depth; + fc::raw::unpack( s, value.first, _max_depth ); + fc::raw::unpack( s, value.second, _max_depth ); } template inline void pack( Stream& s, const std::unordered_map& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth - 1 ); + --_max_depth; + fc::raw::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 - 1 ); + fc::raw::pack( s, *itr, _max_depth ); ++itr; } } @@ -480,25 +490,27 @@ namespace fc { inline void unpack( Stream& s, std::unordered_map& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - unsigned_int size; fc::raw::unpack( s, size, _max_depth - 1 ); + --_max_depth; + unsigned_int size; fc::raw::unpack( s, size, _max_depth ); value.clear(); FC_ASSERT( size.value*(sizeof(K)+sizeof(V)) < MAX_ARRAY_ALLOC_SIZE ); value.reserve(size.value); for( uint32_t i = 0; i < size.value; ++i ) { std::pair tmp; - fc::raw::unpack( s, tmp, _max_depth - 1 ); + fc::raw::unpack( s, tmp, _max_depth ); value.insert( std::move(tmp) ); } } template inline void pack( Stream& s, const std::map& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth - 1 ); + --_max_depth; + fc::raw::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 - 1 ); + fc::raw::pack( s, *itr, _max_depth ); ++itr; } } @@ -506,13 +518,14 @@ namespace fc { inline void unpack( Stream& s, std::map& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - unsigned_int size; fc::raw::unpack( s, size, _max_depth - 1 ); + --_max_depth; + unsigned_int size; fc::raw::unpack( s, size, _max_depth ); value.clear(); FC_ASSERT( size.value*(sizeof(K)+sizeof(V)) < MAX_ARRAY_ALLOC_SIZE ); for( uint32_t i = 0; i < size.value; ++i ) { std::pair tmp; - fc::raw::unpack( s, tmp, _max_depth - 1 ); + fc::raw::unpack( s, tmp, _max_depth ); value.insert( std::move(tmp) ); } } @@ -520,11 +533,12 @@ namespace fc { template inline void pack( Stream& s, const std::deque& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth - 1 ); + --_max_depth; + fc::raw::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 - 1 ); + fc::raw::pack( s, *itr, _max_depth ); ++itr; } } @@ -532,13 +546,14 @@ namespace fc { template inline void unpack( Stream& s, std::deque& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - unsigned_int size; fc::raw::unpack( s, size, _max_depth - 1 ); + --_max_depth; + unsigned_int size; fc::raw::unpack( s, size, _max_depth ); FC_ASSERT( size.value*sizeof(T) < MAX_ARRAY_ALLOC_SIZE ); value.resize(size.value); auto itr = value.begin(); auto end = value.end(); while( itr != end ) { - fc::raw::unpack( s, *itr, _max_depth - 1 ); + fc::raw::unpack( s, *itr, _max_depth ); ++itr; } } @@ -546,11 +561,12 @@ namespace fc { template inline void pack( Stream& s, const std::vector& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth - 1 ); + --_max_depth; + fc::raw::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 - 1 ); + fc::raw::pack( s, *itr, _max_depth ); ++itr; } } @@ -558,13 +574,14 @@ namespace fc { template inline void unpack( Stream& s, std::vector& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - unsigned_int size; fc::raw::unpack( s, size, _max_depth - 1 ); + --_max_depth; + unsigned_int size; fc::raw::unpack( s, size, _max_depth ); FC_ASSERT( size.value*sizeof(T) < MAX_ARRAY_ALLOC_SIZE ); value.resize(size.value); auto itr = value.begin(); auto end = value.end(); while( itr != end ) { - fc::raw::unpack( s, *itr, _max_depth - 1 ); + fc::raw::unpack( s, *itr, _max_depth ); ++itr; } } @@ -572,11 +589,12 @@ namespace fc { template inline void pack( Stream& s, const std::set& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth - 1 ); + --_max_depth; + fc::raw::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 - 1 ); + fc::raw::pack( s, *itr, _max_depth ); ++itr; } } @@ -584,11 +602,12 @@ namespace fc { template inline void unpack( Stream& s, std::set& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - unsigned_int size; fc::raw::unpack( s, size, _max_depth - 1 ); + --_max_depth; + unsigned_int size; fc::raw::unpack( s, size, _max_depth ); for( uint64_t i = 0; i < size.value; ++i ) { T tmp; - fc::raw::unpack( s, tmp, _max_depth - 1 ); + fc::raw::unpack( s, tmp, _max_depth ); value.insert( std::move(tmp) ); } } @@ -618,13 +637,14 @@ namespace fc { template inline std::vector pack( const T& v, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); + --_max_depth; datastream ps; - fc::raw::pack( ps, v, _max_depth - 1 ); + fc::raw::pack( ps, v, _max_depth ); std::vector vec(ps.tellp()); if( vec.size() ) { datastream ds( vec.data(), size_t(vec.size()) ); - fc::raw::pack( ds, v, _max_depth - 1 ); + fc::raw::pack( ds, v, _max_depth ); } return vec; } @@ -632,13 +652,14 @@ namespace fc { template inline std::vector pack( const T& v, Next... next, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); + --_max_depth; datastream ps; - fc::raw::pack( ps, v, next..., _max_depth - 1 ); + fc::raw::pack( ps, v, next..., _max_depth ); std::vector vec(ps.tellp()); if( vec.size() ) { datastream ds( vec.data(), size_t(vec.size()) ); - fc::raw::pack( ds, v, next..., _max_depth - 1 ); + fc::raw::pack( ds, v, next..., _max_depth ); } return vec; } @@ -696,8 +717,8 @@ namespace fc { struct pack_static_variant { Stream& stream; - uint32_t max_depth; - pack_static_variant( Stream& s, uint32_t _max_depth ):stream(s),max_depth(_max_depth) + const uint32_t max_depth; + pack_static_variant( Stream& s, uint32_t _max_depth ):stream(s),max_depth(_max_depth - 1) { FC_ASSERT( _max_depth > 0 ); } @@ -705,7 +726,7 @@ namespace fc { typedef void result_type; template void operator()( const T& v )const { - fc::raw::pack( stream, v, max_depth - 1 ); + fc::raw::pack( stream, v, max_depth ); } }; @@ -713,8 +734,8 @@ namespace fc { struct unpack_static_variant { Stream& stream; - uint32_t max_depth; - unpack_static_variant( Stream& s, uint32_t _max_depth ) : stream(s),max_depth(_max_depth) + const uint32_t max_depth; + unpack_static_variant( Stream& s, uint32_t _max_depth ) : stream(s),max_depth(_max_depth - 1) { FC_ASSERT( _max_depth > 0 ); } @@ -722,7 +743,7 @@ namespace fc { typedef void result_type; template void operator()( T& v )const { - fc::raw::unpack( stream, v, max_depth - 1 ); + fc::raw::unpack( stream, v, max_depth ); } }; @@ -731,17 +752,19 @@ namespace fc { void pack( Stream& s, const static_variant& sv, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - fc::raw::pack( s, unsigned_int(sv.which()), _max_depth - 1 ); - sv.visit( pack_static_variant( s, _max_depth - 1 ) ); + --_max_depth; + fc::raw::pack( s, unsigned_int(sv.which()), _max_depth ); + sv.visit( pack_static_variant( s, _max_depth ) ); } template void unpack( Stream& s, static_variant& sv, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); + --_max_depth; unsigned_int w; - fc::raw::unpack( s, w, _max_depth - 1 ); + fc::raw::unpack( s, w, _max_depth ); sv.set_which(w.value); - sv.visit( unpack_static_variant( s, _max_depth - 1 ) ); + sv.visit( unpack_static_variant( s, _max_depth ) ); } } } // namespace fc::raw diff --git a/include/fc/io/raw_variant.hpp b/include/fc/io/raw_variant.hpp index 9df0118..b07fbaa 100644 --- a/include/fc/io/raw_variant.hpp +++ b/include/fc/io/raw_variant.hpp @@ -10,42 +10,42 @@ namespace fc { namespace raw { class variant_packer : public variant::visitor { public: - variant_packer( Stream& _s, uint32_t _max_depth ):s(_s),max_depth(_max_depth) + variant_packer( Stream& _s, uint32_t _max_depth ):s(_s),max_depth(_max_depth - 1) { FC_ASSERT( _max_depth > 0 ); } virtual void handle()const { } virtual void handle( const int64_t& v )const { - fc::raw::pack( s, v, max_depth - 1 ); + fc::raw::pack( s, v, max_depth ); } virtual void handle( const uint64_t& v )const { - fc::raw::pack( s, v, max_depth - 1 ); + fc::raw::pack( s, v, max_depth ); } virtual void handle( const double& v )const { - fc::raw::pack( s, v, max_depth - 1 ); + fc::raw::pack( s, v, max_depth ); } virtual void handle( const bool& v )const { - fc::raw::pack( s, v, max_depth - 1 ); + fc::raw::pack( s, v, max_depth ); } virtual void handle( const string& v )const { - fc::raw::pack( s, v, max_depth - 1 ); + fc::raw::pack( s, v, max_depth ); } virtual void handle( const variant_object& v)const { - fc::raw::pack( s, v, max_depth - 1 ); + fc::raw::pack( s, v, max_depth ); } virtual void handle( const variants& v)const { - fc::raw::pack( s, v, max_depth - 1 ); + fc::raw::pack( s, v, max_depth ); } Stream& s; - uint32_t max_depth; + const uint32_t max_depth; }; @@ -54,15 +54,17 @@ namespace fc { namespace raw { inline void pack( Stream& s, const variant& v, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - pack( s, uint8_t(v.get_type()), _max_depth - 1 ); - v.visit( variant_packer( s, _max_depth - 1 ) ); + --_max_depth; + pack( s, uint8_t(v.get_type()), _max_depth ); + v.visit( variant_packer( s, _max_depth ) ); } template inline void unpack( Stream& s, variant& v, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); + --_max_depth; uint8_t t; - unpack( s, t, _max_depth - 1 ); + unpack( s, t, _max_depth ); switch( t ) { case variant::null_type: @@ -70,49 +72,49 @@ namespace fc { namespace raw { case variant::int64_type: { int64_t val; - raw::unpack( s, val, _max_depth - 1 ); + raw::unpack( s, val, _max_depth ); v = val; return; } case variant::uint64_type: { uint64_t val; - raw::unpack( s, val, _max_depth - 1 ); + raw::unpack( s, val, _max_depth ); v = val; return; } case variant::double_type: { double val; - raw::unpack( s, val, _max_depth - 1 ); + raw::unpack( s, val, _max_depth ); v = val; return; } case variant::bool_type: { bool val; - raw::unpack( s, val, _max_depth - 1 ); + raw::unpack( s, val, _max_depth ); v = val; return; } case variant::string_type: { fc::string val; - raw::unpack( s, val, _max_depth - 1 ); + raw::unpack( s, val, _max_depth ); v = fc::move(val); return; } case variant::array_type: { variants val; - raw::unpack( s, val, _max_depth - 1 ); + raw::unpack( s, val, _max_depth ); v = fc::move(val); return; } case variant::object_type: { variant_object val; - raw::unpack( s, val, _max_depth - 1 ); + raw::unpack( s, val, _max_depth ); v = fc::move(val); return; } @@ -125,20 +127,22 @@ namespace fc { namespace raw { inline void pack( Stream& s, const variant_object& v, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); + --_max_depth; unsigned_int vs = (uint32_t)v.size(); - pack( s, vs, _max_depth - 1 ); + pack( s, vs, _max_depth ); for( auto itr = v.begin(); itr != v.end(); ++itr ) { - pack( s, itr->key(), _max_depth - 1 ); - pack( s, itr->value(), _max_depth - 1 ); + pack( s, itr->key(), _max_depth ); + pack( s, itr->value(), _max_depth ); } } template inline void unpack( Stream& s, variant_object& v, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); + --_max_depth; unsigned_int vs; - unpack( s, vs, _max_depth - 1 ); + unpack( s, vs, _max_depth ); mutable_variant_object mvo; mvo.reserve(vs.value); @@ -146,8 +150,8 @@ namespace fc { namespace raw { { fc::string key; fc::variant value; - fc::raw::unpack( s, key, _max_depth - 1 ); - fc::raw::unpack( s, value, _max_depth - 1 ); + fc::raw::unpack( s, key, _max_depth ); + fc::raw::unpack( s, value, _max_depth ); mvo.set( fc::move(key), fc::move(value) ); } v = fc::move(mvo); diff --git a/include/fc/network/ip.hpp b/include/fc/network/ip.hpp index 5292dbf..04c5030 100644 --- a/include/fc/network/ip.hpp +++ b/include/fc/network/ip.hpp @@ -101,17 +101,19 @@ namespace fc { inline void pack( Stream& s, const ip::endpoint& v, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); - fc::raw::pack( s, v.get_address(), _max_depth - 1 ); - fc::raw::pack( s, v.port(), _max_depth - 1 ); + --_max_depth; + fc::raw::pack( s, v.get_address(), _max_depth ); + fc::raw::pack( s, v.port(), _max_depth ); } template inline void unpack( Stream& s, ip::endpoint& v, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); + --_max_depth; ip::address a; uint16_t p; - fc::raw::unpack( s, a, _max_depth - 1 ); - fc::raw::unpack( s, p, _max_depth - 1 ); + fc::raw::unpack( s, a, _max_depth ); + fc::raw::unpack( s, p, _max_depth ); v = ip::endpoint(a,p); }