Use ReflectiveRapidJSON for serialization
This commit is contained in:
parent
155c2c36dd
commit
84e2e9ceea
|
@ -1,18 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <iostream>
|
|
||||||
#include "lmdb-safe.hh"
|
#include "lmdb-safe.hh"
|
||||||
#include <boost/archive/binary_oarchive.hpp>
|
|
||||||
#include <boost/archive/binary_iarchive.hpp>
|
#include <reflective-rapidjson/lib/binary/reflector.h>
|
||||||
#include <boost/serialization/vector.hpp>
|
|
||||||
#include <boost/serialization/string.hpp>
|
|
||||||
#include <boost/serialization/utility.hpp>
|
|
||||||
#include <boost/iostreams/stream.hpp>
|
#include <boost/iostreams/stream.hpp>
|
||||||
#include <boost/iostreams/stream_buffer.hpp>
|
#include <boost/iostreams/stream_buffer.hpp>
|
||||||
#include <boost/iostreams/device/back_inserter.hpp>
|
#include <boost/iostreams/device/back_inserter.hpp>
|
||||||
#include <sstream>
|
|
||||||
// using std::cout;
|
|
||||||
// using std::endl;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Open issues:
|
Open issues:
|
||||||
|
@ -41,30 +34,22 @@ unsigned int MDBGetMaxID(MDBRWTransaction& txn, MDBDbi& dbi);
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::string serToString(const T& t)
|
std::string serToString(const T& t)
|
||||||
{
|
{
|
||||||
std::string serial_str;
|
auto ret = std::string();
|
||||||
boost::iostreams::back_insert_device<std::string> inserter(serial_str);
|
auto inserter = boost::iostreams::back_insert_device<std::string>(ret);
|
||||||
boost::iostreams::stream<boost::iostreams::back_insert_device<std::string> > s(inserter);
|
auto stream = boost::iostreams::stream<boost::iostreams::back_insert_device<std::string>>(inserter);
|
||||||
boost::archive::binary_oarchive oa(s, boost::archive::no_header | boost::archive::no_codecvt);
|
auto deserializer = ReflectiveRapidJSON::BinaryReflector::BinarySerializer(&stream);
|
||||||
|
deserializer.write(t);
|
||||||
oa << t;
|
return ret;
|
||||||
return serial_str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void serFromString(const string_view& str, T& ret)
|
void serFromString(const string_view& str, T& ret)
|
||||||
{
|
{
|
||||||
|
auto source = boost::iostreams::array_source(str.data(), str.size());
|
||||||
|
auto stream = boost::iostreams::stream<boost::iostreams::array_source>(source);
|
||||||
|
auto serializer = ReflectiveRapidJSON::BinaryReflector::BinaryDeserializer(&stream);
|
||||||
ret = T();
|
ret = T();
|
||||||
|
serializer.read(ret);
|
||||||
boost::iostreams::array_source source(&str[0], str.size());
|
|
||||||
boost::iostreams::stream<boost::iostreams::array_source> stream(source);
|
|
||||||
boost::archive::binary_iarchive in_archive(stream, boost::archive::no_header|boost::archive::no_codecvt);
|
|
||||||
in_archive >> ret;
|
|
||||||
|
|
||||||
/*
|
|
||||||
std::istringstream istr{str};
|
|
||||||
boost::archive::binary_iarchive oi(istr,boost::archive::no_header|boost::archive::no_codecvt );
|
|
||||||
oi >> ret;
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue