diff --git a/projects/serialization/public/SIREN/serialization/ByteString.h b/projects/serialization/public/SIREN/serialization/ByteString.h index ac2a21cd..59aed029 100644 --- a/projects/serialization/public/SIREN/serialization/ByteString.h +++ b/projects/serialization/public/SIREN/serialization/ByteString.h @@ -17,7 +17,7 @@ namespace siren { namespace serialization { template -std::vector to_byte_string(T const & obj) { +std::vector to_byte_string(std::shared_ptr obj) { std::ostringstream oss(std::ios::binary); { cereal::BinaryOutputArchive oarchive(oss); @@ -48,20 +48,20 @@ std::string bytes_to_hex_string(std::vector const & bytes) { } template -T from_byte_string(std::vector const & byte_string) { +std::shared_ptr from_byte_string(std::vector const & byte_string) { std::string str(byte_string.begin(), byte_string.end()); if(not (str.size() == byte_string.size())) throw std::runtime_error("str.size() != byte_string.size()"); std::istringstream iss(str, std::ios::binary); - std::shared_ptr obj(cereal::access::construct()); + std::shared_ptr obj; { cereal::BinaryInputArchive iarchive(iss); - iarchive(*obj); + iarchive(obj); } size_t n_bytes = iss.tellg(); if(not (n_bytes == str.size())) throw std::runtime_error("n_bytes != str.size()"); - return *obj; + return obj; } std::vector hex_string_to_bytes(std::string const & hex_string) { @@ -77,20 +77,20 @@ std::vector hex_string_to_bytes(std::string const & hex_string) { } template -pybind11::tuple pickle_save(T const & cpp_obj) { +pybind11::tuple pickle_save(std::shared_ptr cpp_obj) { std::vector byte_string = to_byte_string(cpp_obj); std::string hex_string = bytes_to_hex_string(byte_string); return pybind11::make_tuple(hex_string); } template -T pickle_load(pybind11::tuple t) { +std::shared_ptr pickle_load(pybind11::tuple t) { if (t.size() != 1) { throw std::runtime_error("Invalid state!"); } std::string hex_string = t[0].cast(); std::vector byte_string = hex_string_to_bytes(hex_string); - T res = from_byte_string(byte_string); + std::shared_ptr res = from_byte_string(byte_string); return res; }