31 #ifndef LEDGER_CORE_SERIALIZATION_HPP 32 #define LEDGER_CORE_SERIALIZATION_HPP 35 #include <boost/iostreams/device/array.hpp> 36 #include <boost/iostreams/stream.hpp> 37 #include <cereal/archives/binary.hpp> 38 #include <cereal/external/base64.hpp> 43 namespace serialization {
46 void load(
const std::vector<uint8_t>& src, T& dest) {
47 boost::iostreams::array_source my_vec_source(reinterpret_cast<const char*>(&src[0]), src.size());
48 boost::iostreams::stream<boost::iostreams::array_source> is(my_vec_source);
49 ::cereal::BinaryInputArchive archive(is);
54 void save(T& src, std::vector<uint8_t>& dest) {
56 ::cereal::BinaryOutputArchive archive(is);
59 dest.assign((
const uint8_t *)raw.data(), (
const uint8_t *)raw.data() + raw.size());
63 void loadBase64(
const std::string& str, T& dest) {
64 auto decoded = cereal::base64::decode(str);
65 std::vector<uint8_t> data;
66 data.reserve(decoded.size());
67 for (
auto& c : decoded) {
68 data.push_back((uint8_t) c);
74 void saveBase64(T& src, std::string& dest) {
75 std::vector<uint8_t> data;
77 dest = cereal::base64::encode((
const unsigned char *)data.data(), data.size());
85 #endif //LEDGER_CORE_SERIALIZATION_HPP Definition: Account.cpp:8