8 #ifndef BOOSTDATASAVER_H
9 #define BOOSTDATASAVER_H
15 #include <type_traits>
20 namespace serialization {
24 #include <boost/archive/binary_iarchive.hpp>
25 #include <boost/archive/binary_oarchive.hpp>
26 #include <boost/serialization/vector.hpp>
29 #include <FairMQMessage.h>
31 template<
typename TPayload,
32 typename TArchiveIn = boost::archive::binary_iarchive,
33 typename TArchiveOut = TBoboost::archive::binary_oarchiveostOut>
42 void Write(std::ofstream& outfile, TPayload* objArr,
long sizeArr = 1)
44 std::vector<TPayload> dataVector(objArr, objArr + sizeArr);
45 TArchiveOut outArchive(outfile);
46 outArchive << dataVector;
49 void Write(std::ofstream& outfile, std::vector<TPayload> dataVector)
51 TArchiveOut outArchive(outfile);
52 outArchive << dataVector;
55 void Write(std::ofstream& outfile, FairMQMessage* msg)
57 std::vector<TPayload> objArr;
58 std::string msgStr(static_cast<char*>(msg->GetData()), msg->GetSize());
59 std::istringstream ibuffer(msgStr);
60 TArchiveIn inputArchive(ibuffer);
62 inputArchive >> objArr;
63 }
catch (boost::archive::archive_exception& e) {
64 LOG(error) << e.what();
66 TArchiveOut outArchive(outfile);
70 std::vector<std::vector<TPayload>>
Read(std::ifstream& infile)
72 std::vector<std::vector<TPayload>> dataContainer;
73 while (infile.peek() != EOF && !infile.eof()) {
74 TArchiveIn inArchive(infile);
75 std::vector<TPayload> temp;
77 dataContainer.push_back(temp);
std::vector< std::vector< TPayload > > Read(std::ifstream &infile)
void Write(std::ofstream &outfile, FairMQMessage *msg)
virtual ~BoostDataSaver()
virtual void InitOutputFile()
void Write(std::ofstream &outfile, TPayload *objArr, long sizeArr=1)
void Write(std::ofstream &outfile, std::vector< TPayload > dataVector)