From ba96174e7f8453c0e70c439c8c987458503fffa2 Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Sat, 23 Mar 2019 11:35:40 -0500 Subject: [PATCH] Support for BTS #1670: allow serializing shared_ptr --- include/fc/io/raw.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/fc/io/raw.hpp b/include/fc/io/raw.hpp index 2268e37..6b7bccb 100644 --- a/include/fc/io/raw.hpp +++ b/include/fc/io/raw.hpp @@ -143,6 +143,13 @@ namespace fc { fc::raw::pack( s, *v, _max_depth - 1 ); } + template + inline void pack( Stream& s, const std::shared_ptr& v, uint32_t _max_depth ) + { + FC_ASSERT( _max_depth > 0 ); + fc::raw::pack( s, *v, _max_depth - 1 ); + } + template inline void unpack( Stream& s, fc::array& v, uint32_t _max_depth ) { try { @@ -157,6 +164,15 @@ namespace fc { fc::raw::unpack( s, *v, _max_depth - 1 ); } FC_RETHROW_EXCEPTIONS( warn, "std::shared_ptr", ("type",fc::get_typename::name()) ) } + template + inline void unpack( Stream& s, std::shared_ptr& v, uint32_t _max_depth ) + { try { + FC_ASSERT( _max_depth > 0 ); + T tmp; + fc::raw::unpack( s, tmp, _max_depth - 1 ); + v = std::make_shared(tmp); + } FC_RETHROW_EXCEPTIONS( warn, "std::shared_ptr", ("type",fc::get_typename::name()) ) } + template inline void pack( Stream& s, const unsigned_int& v, uint32_t _max_depth ) { uint64_t val = v.value; do {