61 objectType_(Serialization::NO_OBJECT), format_(Serialization::BINARY), roseVersion_(ROSE_PACKAGE_VERSION) {}
64 FrameRecord(Serialization::Savable objectType, Serialization::Format format) :
65 objectType_(objectType), format_(format), roseVersion_(ROSE_PACKAGE_VERSION) {}
69 objectType_(record.header.objectType), format_(record.header.format), roseVersion_(record.header.roseVersion),
75 record.header.objectType = objectType_;
76 record.header.format = format_;
77 record.header.roseVersion = roseVersion_;
78 record.header.payloadSize = payload_.size();
79 record.payload = payload_;
84 const std::vector<char>&
payload()
const {
return payload_; }
87 Serialization::Savable objectType()
const {
return objectType_; }
88 void objectType(Serialization::Savable type) { objectType_ = type; }
90 Serialization::Format format()
const {
return format_; }
91 void format(Serialization::Format fmt) { format_ = fmt; }
93 std::string roseVersion()
const {
return roseVersion_; }
94 void roseVersion(
const std::string& ver) { roseVersion_ = ver; }
101 std::ostringstream oss;
102 boost::archive::binary_oarchive oa(oss);
104 std::string serialized = oss.str();
107 payload_.resize(serialized.size());
108 std::memcpy(payload_.data(), serialized.data(), serialized.size());
113 std::string serialized(
reinterpret_cast<const char*
>(payload_.data()), payload_.size());
114 std::istringstream iss(serialized);
115 boost::archive::binary_iarchive ia(iss);
120 template <
class Archive>
void serialize(Archive& ar,
const unsigned ) {
128 Serialization::Savable objectType_;
129 Serialization::Format format_;
130 std::string roseVersion_;
131 std::vector<char> payload_;
146 void openForWrite(
const boost::filesystem::path& fileName, ProgressCallback saveCB);
147 void openForRead(
const boost::filesystem::path& fileName, ProgressCallback loadCB);
155 void open(
const boost::filesystem::path& fileName);
159 void writeFileHeader();
160 void readAndVerifyFileHeader();
163 void writeRecord(
const RecordHeader& header,
const std::vector<char>& payload);
167 void writeFrameRecord(
const FrameRecord& frameRecord);
171 enum class Mode { Closed, Reading, Writing };
177 boost::iostreams::file_descriptor_source inDevice_;
178 boost::iostreams::stream<boost::iostreams::file_descriptor_source> inStream_;
179 std::unique_ptr<boost::archive::binary_iarchive> inArchive_;
182 boost::iostreams::file_descriptor_sink outDevice_;
183 boost::iostreams::stream<boost::iostreams::file_descriptor_sink> outStream_;
184 std::unique_ptr<boost::archive::binary_oarchive> outArchive_;
187 ProgressCallback progress_;
191 void ensureWriting()
const;
192 void ensureReading()
const;
195 void writeBlob(
const std::vector<char>& data);
196 std::vector<char> readBlob();
198 static void startWriteWorker(
SerialFrame* saver,
const std::vector<char>& data);
199 void writeWorker(
const std::vector<char>& data);