how to suppress the extra information in boost serialization::archive?

核能气质少年 提交于 2021-01-28 09:22:11

问题


In the example of Boost code of serialization bus schedule in its output file "demofile.txt" the first line is:

"22 serialization::archive 16 0 0 6 0 0 0 0 0 6 24 4"

what is this? Dll version number? Can we suppress this and store only the data itsself?


回答1:


That's not a Dll version. It's the archive header.

Suppress it by using archive flags it:

void save_schedule(const bus_schedule &s, const char * filename){
    // make an archive
    std::ofstream ofs(filename);
    boost::archive::text_oarchive oa(ofs, boost::archive::archive_flags::no_header);
    oa << s;
}

And remember to do the same on restoring, of course!

void restore_schedule(bus_schedule &s, const char * filename) {
    // open the archive
    std::ifstream ifs(filename);
    boost::archive::text_iarchive ia(ifs, boost::archive::archive_flags::no_header);

    // restore the schedule from the archive
    ia >> s;
}

See also

  • Boost binary archives - reducing size
  • Why does an non-intrusive serialization add a 5 byte zero prefix?
  • Boost C++ Serialization overhead


来源:https://stackoverflow.com/questions/49640567/how-to-suppress-the-extra-information-in-boost-serializationarchive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!