2022-01-30 00:05:02 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "./lmdb-safe.hh"
|
|
|
|
|
|
|
|
#include <boost/archive/binary_iarchive.hpp>
|
2022-01-30 21:14:43 +01:00
|
|
|
#include <boost/archive/binary_oarchive.hpp>
|
2022-01-30 00:05:02 +01:00
|
|
|
|
|
|
|
#include <boost/serialization/string.hpp>
|
|
|
|
#include <boost/serialization/utility.hpp>
|
2022-01-30 21:14:43 +01:00
|
|
|
#include <boost/serialization/vector.hpp>
|
2022-01-30 00:05:02 +01:00
|
|
|
|
2022-01-30 21:14:43 +01:00
|
|
|
#include <boost/iostreams/device/back_inserter.hpp>
|
2022-01-30 00:05:02 +01:00
|
|
|
#include <boost/iostreams/stream.hpp>
|
|
|
|
#include <boost/iostreams/stream_buffer.hpp>
|
|
|
|
|
|
|
|
namespace LMDBSafe {
|
|
|
|
|
2022-01-30 21:14:43 +01:00
|
|
|
template <typename T> std::string serToString(const T &t)
|
2022-01-30 00:05:02 +01:00
|
|
|
{
|
2022-01-30 21:14:43 +01:00
|
|
|
auto ret = std::string();
|
|
|
|
auto inserter = boost::iostreams::back_insert_device<std::string>(ret);
|
|
|
|
auto stream = boost::iostreams::stream<boost::iostreams::back_insert_device<std::string>>(inserter);
|
|
|
|
auto oa = boost::archive::binary_oarchive(stream, boost::archive::no_header | boost::archive::no_codecvt);
|
|
|
|
oa << t;
|
|
|
|
return ret;
|
2022-01-30 00:05:02 +01:00
|
|
|
}
|
|
|
|
|
2022-01-30 21:14:43 +01:00
|
|
|
template <typename T> void serFromString(string_view str, T &ret)
|
2022-01-30 00:05:02 +01:00
|
|
|
{
|
2022-01-30 21:14:43 +01:00
|
|
|
auto source = boost::iostreams::array_source(str.data(), str.size());
|
|
|
|
auto stream = boost::iostreams::stream<boost::iostreams::array_source>(source);
|
|
|
|
auto ia = boost::archive::binary_iarchive(stream, boost::archive::no_header | boost::archive::no_codecvt);
|
|
|
|
ia >> ret;
|
2022-01-30 00:05:02 +01:00
|
|
|
}
|
|
|
|
|
2022-01-30 21:14:43 +01:00
|
|
|
} // namespace LMDBSafe
|