Boost::serialization. Serialize in VS. Unserialize in Qt.
-
I serialize data in application compiled in VS 2012.
[code]
class OByteStream
{
public:
explicit OByteStream(std::string &s)
: _backInsertDevice(s)
, _stream(_backInsertDevice)
, _oArchive(_stream)
{
}void flush() { _stream.flush(); } template<class T> OByteStream &operator<<(const T &data) { _oArchive << data; return *this; } private: typedef boost::iostreams::back_insert_device<std::string> BackInsertDevice; typedef boost::iostreams::stream<BackInsertDevice> Stream; typedef boost::archive::binary_oarchive BinaryOArchive; BackInsertDevice _backInsertDevice; Stream _stream; BinaryOArchive _oArchive; }; class IByteStream { public: explicit IByteStream(const std::string &s) : _basicArraySource(s.data(), s.size()) , _stream(_basicArraySource) , _iArchive(_stream) { } template<class T> IByteStream &operator>>(T &data) { _iArchive >> data; return *this; } private: typedef boost::iostreams::basic_array_source<char> BasicArraySource; typedef boost::iostreams::stream<BasicArraySource> Stream; typedef boost::archive::binary_iarchive BinaryIArchive; BasicArraySource _basicArraySource; Stream _stream; BinaryIArchive _iArchive; };
[/code]
[code]
template<class Archive> void serialize(Archive & ar, Data & data, const unsigned int version) { ar & data.a; ar & data.b; ar & data.c; } std::string serial; OByteStream obs(serial); obs << data; obs.flush(); IByteStream ibs(serial); ibs >> data;
[/code]
Then I send it to application compiled in Qt (msvc 2012).
And when some 2d vectors unserializing an exception happens.
[code]
if(scount != s)
boost::serialization::throw_exception(
archive_exception(archive_exception::input_stream_error)
);
[/code]I tried to use all Struct Member Alignments in VS. It did not help. In QtCreator I did not find such option.