serialization as generialized I/O

Looking again at mersenne_twister, one of the objections that has been raised to adding serialization support, is that there is already iostream I/O support. It is in principle possible to leverage iostream to do serialization. Unfortunately, that approach is hardly efficient and rather ugly IMHO. But, what about the other way around? If we have generic archive support, can we use it to eliminate the need for iostream? I think so. In fact, consider this code (assuming serialization suport added to mersenne_twister): typedef boost::mt19937 rng_t; int main() { rng_t rng1; std::ostringstream os; boost::archive::text_oarchive oa(os, boost::archive::no_header); oa << const_cast<const rng_t&>(rng1); std::string st (os.str()); std::cout << rng1 << '\n'; std::cout << st << '\n'; } As it is, the 2 outputs are almost identical. There is only one difference: the text_oarchive (,no_header) output prints 2 leading '0' characters. Is there some way to suppress this preamble? If so, then we have a more elegant solution. All we need to do is put in the serialization support and remove the iostream support, since serialization is just a generalization of i/o.

Neal Becker wrote:
Looking again at mersenne_twister, one of the objections that has been raised to adding serialization support, is that there is already iostream I/O support. It is in principle possible to leverage iostream to do serialization.
Unfortunately, that approach is hardly efficient and rather ugly IMHO.
But, what about the other way around? If we have generic archive support, can we use it to eliminate the need for iostream? I think so.
In fact, consider this code (assuming serialization suport added to mersenne_twister): typedef boost::mt19937 rng_t;
int main() { rng_t rng1;
std::ostringstream os; boost::archive::text_oarchive oa(os, boost::archive::no_header); oa << const_cast<const rng_t&>(rng1);
std::string st (os.str());
std::cout << rng1 << '\n'; std::cout << st << '\n'; }
As it is, the 2 outputs are almost identical. There is only one difference: the text_oarchive (,no_header) output prints 2 leading '0' characters.
Is there some way to suppress this preamble?
If so, then we have a more elegant solution. All we need to do is put in the serialization support and remove the iostream support, since serialization is just a generalization of i/o.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Neal Becker wrote:
As it is, the 2 outputs are almost identical. There is only one difference: the text_oarchive (,no_header) output prints 2 leading '0' characters.
Is there some way to suppress this preamble?
Off hand I don't remember what these two integers represent in this example. The easiest way to find out is to use an xml archive and examine it. However, I do know that in a text archive there is no information which is not essential to reconstituting the archive. So I wouldn't expect you coul elminate it. Robert Ramey
participants (2)
-
Neal Becker
-
Robert Ramey