[iostreams] [archive] [serialization] lexical_cast<string> with binary_archive vs. text_archive
Consider the following serialization archive. I can serialize a collection of variables (floats, ints, etc) through the series: numerics --> text_oarchive --> gzip --> output_file The text_archive step is essentially a stringstream filter. This filter gives the serialization the portability I (sometimes) need. namespace io = boost::iostreams; namespace ar = boost::archive; io::filtering_ostream fos; fis.push(io::gzip_compressor()); fis.push(io::file_sink("output.txt.gz")); ar::text_oarchive oa(fos); OK. Now what I wish to do is to create a binary_archive and to push the stringstream filter to the filtering_ostream: numerics -> binary_archive -> lexical_cast<string> -> gzip -> out_file This way I could turn this part (and the gzip) on or off at will (the ol' speed vs portability thing): io::filtering_ostream fos; fis.push(/*stringstream_filter*/); fis.push(io::gzip_compressor()); fis.push(io::file_sink("output.txt.gz")); ar::binary_oarchive oa(fos); I am not sure how to create such a filter, but I'm guessing such a filter already exists. Perhaps the answer lies in lexical_cast<string>? any help with this would be greatly appreciated, thanks! Johann.
I don't see what lexical cast is doing in there. What's the matter with:
numerics -> binary_archive -> gzip -> out_file
io::filtering_ostream fos; fos.push(io::gzip_compressor()); fos.push(io::file_sink("output.txt.gz", ios::binary)); ar::binary_oarchive oa(fos);
? Robert Ramey Johann Goetz wrote:
Consider the following serialization archive. I can serialize a collection of variables (floats, ints, etc) through the series: numerics --> text_oarchive --> gzip --> output_file The text_archive step is essentially a stringstream filter. This filter gives the serialization the portability I (sometimes) need.
namespace io = boost::iostreams; namespace ar = boost::archive;
io::filtering_ostream fos; fis.push(io::gzip_compressor()); fis.push(io::file_sink("output.txt.gz")); ar::text_oarchive oa(fos);
OK. Now what I wish to do is to create a binary_archive and to push the stringstream filter to the filtering_ostream: numerics -> binary_archive -> lexical_cast<string> -> gzip -> out_file This way I could turn this part (and the gzip) on or off at will (the ol' speed vs portability thing):
io::filtering_ostream fos; fis.push(/*stringstream_filter*/); fis.push(io::gzip_compressor()); fis.push(io::file_sink("output.txt.gz")); ar::binary_oarchive oa(fos);
I am not sure how to create such a filter, but I'm guessing such a filter already exists. Perhaps the answer lies in lexical_cast<string>? any help with this would be greatly appreciated, thanks! Johann.
participants (2)
-
Johann Goetz
-
Robert Ramey