I use Boost.Serialization to serialize a std::map. The code looks like this
void Dictionary::serialize(std::string & buffer)
{
try {
std::stringstream ss;
boost::archive::binary_oarchive archive(ss);
archive << dict_;
buffer = ss.str();
} catch (const std::exception & ex) {
throw DictionaryException(ex.what());
}
}
void Dictionary::deserialize(const char * const data, int length)
{
try {
namespace io = boost::iostreams;
io::array_source source(data, length);
io::stream<io::array_source> in(source);
boost::archive::binary_iarchive archive(in);
archive >> dict_;
} catch (const std::exception & ex) {
throw DictionaryException(ex.what());
}
}
I compiled and tested the code on a Mac Snow Leopard and on Ubuntu Lucid 10.04. There is Boost 1.40 on both systems. On the Mac I built the code myself. On the Ubuntu box I got the binaries via aptitude.
Problem: When I serialize the map on the Mac I can't deserialize it on the Ubuntu box. I get an invalid signature exception if I try.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…