[serialization] appending to an archive
I am trying to append one or more records to the existing archive file, using something like this; void Logger::save(const std::string& fileName) { assert(fileName != "logger.dmp"); bp::time_duration endRecordTime = getCurrentTime(); ofs.flush(); path dst = complete(path(fileName, native)); path src = complete(path("logger.dmp", native)); remove(dst); copy_file(src, dst); ofstream saveFile(dst,std::ios::app); ArchiveType archive(saveFile,boost::archive::no_header); *mArchive << endRecordTime } although i specify no_header flag, it inserts a '0' as a preamble, how can i turn it off? have you guys ever needed to use serialization like this? what was your solution Thanks in advance Hurcan
Hello Hurcan, an archive writes a preamble when it's created and possibly an end-tag when destroyed (xml). Your options are: either keep the archive (on the heap) instead of creating/destroying it, or organize your stream into multiple archives. We did it the latter way and it works fine. I wonder why you would need boost serialization at all if all you do is appending a string to a file. There are simpler ways to do that :-) Good luck, -- Christian Pfligersdorffer Software Engineering http://www.eos.info Hurcan wrote:
I am trying to append one or more records to the existing archive file, using something like this;
void Logger::save(const std::string& fileName) { assert(fileName != "logger.dmp"); bp::time_duration endRecordTime = getCurrentTime();
ofs.flush(); path dst = complete(path(fileName, native)); path src = complete(path("logger.dmp", native)); remove(dst); copy_file(src, dst);
ofstream saveFile(dst,std::ios::app); ArchiveType archive(saveFile,boost::archive::no_header); *mArchive << endRecordTime }
although i specify no_header flag, it inserts a '0' as a preamble, how can i turn it off? have you guys ever needed to use serialization like this? what was your solution
Thanks in advance Hurcan
participants (2)
-
hurcan solter
-
Pfligersdorffer, Christian