
Hello When I serialize (archive) my class I get string which looks something like: 4422 serialization::archive 3 0 1 2 15 message_request 1 0 0 1 0 1 2 1 Is there any way to hide serialization::archive and message_request, which is a name of a class that was serialized? Thanks for help Regards

On Monday, April 9, 2007 at 12:14:09 (+0200) Aljaz writes:
Hello
When I serialize (archive) my class I get string which looks something like:
4422 serialization::archive 3 0 1 2 15 message_request 1 0 0 1 0 1 2 1
Is there any way to hide serialization::archive and message_request, which is a name of a class that was serialized?
There is, though not sure it suits your needs, as you don't detail them. You can hide the name, and everything else, by compressing the stream, or by encrypting it. Here is how you can do the former, when saving: std::ofstream ofs(file_name); boost::iostreams::filtering_ostream out; boost::iostreams::zlib_params zp(boost::iostreams::zlib::best_speed); out.push(boost::iostreams::zlib_compressor(zp)); out.push(ofs); Archive oa(out); oa << BOOST_SERIALIZATION_NVP(message_request); Bill

Hey Bill Thanks for help What does BOOST_SERIALIZATION_NVP do? I couldnt find answer anywhere.. Thanks again Regards

On Tuesday, April 10, 2007 at 14:29:25 (+0200) Aljaz writes:
Hey Bill
Thanks for help
What does BOOST_SERIALIZATION_NVP do? I couldnt find answer anywhere..
It's a macro wrapper --- "NVP" means "Name Value Pair". It is only useful when you use XML archives, as XML needs a "name" for the value serialized. When used with a non-XML archive, it simply defaults to outputting the value, with no name. It is good practice to use the wrapper, as that way, you can switch archive types and not have to recode your serialization routines. Bill

http://www.boost.org/libs/serialization/doc/wrappers.html Aljaz wrote:
Hey Bill
Thanks for help
What does BOOST_SERIALIZATION_NVP do? I couldnt find answer anywhere..
Thanks again Regards

Here is how you can do the former, when saving:
std::ofstream ofs(file_name); boost::iostreams::filtering_ostream out; boost::iostreams::zlib_params zp(boost::iostreams::zlib::best_speed); out.push(boost::iostreams::zlib_compressor(zp)); out.push(ofs); Archive oa(out); oa << BOOST_SERIALIZATION_NVP(message_request);
Hey I tried doing std::stringstream ofs; boost::iostreams::filtering_ostream out; boost::iostreams::zlib_params zp(boost::iostreams::zlib::best_speed); out.push(boost::iostreams::zlib_compressor(zp)); out.push(ofs); ofs << "some test"; but it seems like it doesnt work when I run the program the size of ofs.str().size() is 0. What am I doing wrong? Thanks for help Regards

On Saturday, April 14, 2007 at 02:44:38 (+0200) Aljaz writes:
Here is how you can do the former, when saving:
std::ofstream ofs(file_name); boost::iostreams::filtering_ostream out; boost::iostreams::zlib_params zp(boost::iostreams::zlib::best_speed); out.push(boost::iostreams::zlib_compressor(zp)); out.push(ofs); Archive oa(out); oa << BOOST_SERIALIZATION_NVP(message_request);
Hey
I tried doing
std::stringstream ofs; boost::iostreams::filtering_ostream out; boost::iostreams::zlib_params zp(boost::iostreams::zlib::best_speed); out.push(boost::iostreams::zlib_compressor(zp)); out.push(ofs); ofs << "some test";
but it seems like it doesnt work when I run the program the size of ofs.str().size() is 0.
What am I doing wrong?
Well, for one, using a broken c++ library, apparently. If you do stringstream ofs; ofs << "some test"; then, none of the other stuff you did makes any difference. If you can't get the above to work, you're in big trouble. Here is a program that works: #include <sstream> #include <iostream> using namespace std; int main() { stringstream ofs; ofs << "some test"; cout << ofs.str().size() << endl; } Bill

If I use the code you used, everything works just fine.. - using iostream When I want to use stringstream instead - it doesnt work (but theres nothing wrong with stringstream library). What should I do?
participants (3)
-
Aljaz
-
Bill Lear
-
Robert Ramey