|
Boost Users : |
From: Dan Leibovich (dan_at_[hidden])
Date: 2007-02-27 17:01:27
Hi Robert,
I think I found a clue.
The following simple program produce deferent binary dump on linux and solaris.
#include "portable_binary_iarchive.hpp"
#include "portable_binary_oarchive.hpp"
#include <fstream>
int main () {
char* file = "file" ;
boost::archive::class_id_type cid ;
std::ofstream ofs(file) ;
portable_binary_oarchive oar(ofs) ;
oar << cid ;
ofs.close();
}
The output:
linux: 65 00 00 00
solaris: 00 00 00 65
I set a break point on save_impl() in portable_binary_archive.hpp and notice that the program never get to this method. The data is saved using the default template method which calls to :
boost::archive::binary_oarchive_impl<derived_t>::save(t);
Do you have any idea of how to overcome this issue.
Thank you
Dan Leibovich
________________________________
From: boost-users-bounces_at_[hidden] [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Robert Ramey
Sent: â 27 ôáøåàø 2007 18:15
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] [Serialization] issue withportable_binary_oarchive
I ran your example and made it fail on my machine.
I traced this to an asymetry in the serialization of class_id_optional. I can fix this - but
I don't think its the cause of any other problems. I changed your program to
use class_id rather than class_id_optional and it passed fine. I also ran it with
object_id_type and no problems. I'm not sure what to suggest now.
Robert Ramey
"Dan Leibovich" <dan_at_[hidden]> wrote in message news:80726DBE398EBB4A8B77AD210C509EAA0291B278_at_MAILEU.global.cadence.com...
Hi,
I have tried to create tests as you described.
I assume you meant boost::archive::class_id_type
I tried it also with class_id_optional_type, class_id_reference_type, object_id_type, object_reference_type, version_type, tracking_type . Are there any others I should check ?
I guess I did not understand your request since almost all tests failed (also with text archive)
For example the following simple test fails:
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <fstream>
#include <cassert>
#include <iostream>
int main () {
char* file = "file" ;
boost::archive::class_id_optional_type cido ;
boost::archive::class_id_optional_type cido_(101) ;
std::ofstream ofs(file) ;
boost::archive::text_oarchive oar(ofs) ;
oar << cido_ ;
ofs.close();
std::ifstream ifs(file) ;
boost::archive::text_iarchive iar(ifs) ;
iar >> cido ;
std::cout << cido << std::endl ;
assert (cido_ == cido) ;
}
Could you help me understand what am I doing wrong ?
Thanks
Dan Leibovich
________________________________
From: boost-users-bounces_at_[hidden] [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Robert Ramey
Sent: á 26 ôáøåàø 2007 22:29
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] [Serialization] issue withportable_binary_oarchive
Sorry, I haven't looked into it.
Looking at ...basic_binary_archive I do see that the meta data - object id, etc
are converted to integer types so it looks like this issue was considered. So its not a super obvious issue. I do believe that by making a small test - serializing each of the meta data tag types, you might reveal which one - or more - are hanging things up. Try making a small test:
boost::archive::class_id cid = 100;
ar << cid;
ar << 324;
...
boost::archive::class_id cid
ar >> cid;
assert(100 == cide);
ar >> i;
assert(i == 324);
...
That would be helpful.
Robert Ramey
"Dan Leibovich" <dan_at_[hidden]> wrote in message news:80726DBE398EBB4A8B77AD210C509EAA0291B077_at_MAILEU.global.cadence.com...
Hi Robert,
Were you able to find some clue?
I don't think it is related to the problem but there are some compilation warnings, do you have suggestion how to avoid it?
../boost/boost_1_33_1/boost/archive/impl/basic_binary_iarchive.ipp: In member
function `void boost::archive::basic_binary_iarchive<Archive>::init() [with
Archive = portable_binary_iarchive]':
portable_binary_iarchive.hpp:116: instantiated from here
../boost/boost_1_33_1/boost/archive/impl/basic_binary_iarchive.ipp:67: warning: choosing
`boost::archive::version_type::operator unsigned int&()' over `
boost::archive::version_type::operator const unsigned int&() const'
../boost/boost_1_33_1/boost/archive/impl/basic_binary_iarchive.ipp:67: warning:
for conversion from `boost::archive::version_type' to `unsigned int'
../boost/boost_1_33_1/boost/archive/impl/basic_binary_iarchive.ipp:67: warning:
because conversion sequence for the argument is better
../boost/boost_1_33_1/boost/archive/impl/basic_binary_iarchive.ipp: In member
function `void boost::archive::basic_binary_iarchive<Archive>::init() [with
Archive = boost::archive::binary_iarchive]':
../boost/boost_1_33_1/boost/archive/binary_iarchive.hpp:51: instantiated from `void boost::archive::binary_iarchive_impl<Archive>::init() [with Archive = boost::archive::binary_iarchive]'
../boost/boost_1_33_1/boost/archive/binary_iarchive.hpp:66: instantiated from `boost::archive::binary_iarchive_impl<Archive>::binary_iarchive_impl(std::istream&, unsigned int) [with Archive = boost::archive::binary_iarchive]'
../boost/boost_1_33_1/boost/archive/binary_iarchive.hpp:80: instantiated from here
../boost/boost_1_33_1/boost/archive/impl/basic_binary_iarchive.ipp:67: warning: choosing
`boost::archive::version_type::operator unsigned int&()' over `
boost::archive::version_type::operator const unsigned int&() const'
../boost/boost_1_33_1/boost/archive/impl/basic_binary_iarchive.ipp:67: warning:
for conversion from `boost::archive::version_type' to `unsigned int'
../boost/boost_1_33_1/boost/archive/impl/basic_binary_iarchive.ipp:67: warning:
because conversion sequence for the argument is better
Thank you
Dan
________________________________
From: boost-users-bounces_at_[hidden] [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Robert Ramey
Sent: ã 21 ôáøåàø 2007 21:54
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] [Serialization] issue withportable_binary_oarchive
We'll look into it. If you get any more information, feel free to share it.
Robert Ramey
"Dan Leibovich" <dan_at_[hidden]> wrote in message news:80726DBE398EBB4A8B77AD210C509EAA0291A579_at_MAILEU.global.cadence.com...
Hi,
I am trying to use the portable binary archive example.
I need to serialize only integers and strings.
I tried it on linux and solaris5.8. The result binary stream is not the same and deserialization fails.
I used hex viewer and notice that the files are very similar except for some few differences which results from endienness issues. Can it be that the metadata is written differently on each platform.
This is happens when I serialize derived class through a pointer to base class. (I used BOOS_CLASS_EXPORT)
Below you will find a test case. It produce differ output on linux and solaris.
Am I missing something?
Thanks in advance
Dan Leibovich
#include <fstream>
#include "portable_binary_oarchive.hpp"
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/export.hpp>
class Base {
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & x;
}
protected:
int x;
public:
Base() {} ;
Base(int x_) : x(x_) {} ;
virtual void foo() {} ;
};
class Derived1 : public Base {
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & boost::serialization::base_object<Base>(*this);
ar & y;
}
protected:
int y;
public:
Derived1() {} ;
Derived1(int x_, int y_) : Base(x_), y(y_) {} ;
virtual void foo() {x++;}
};
class Derived2 : public Base {
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & boost::serialization::base_object<Base>(*this);
ar & z;
}
protected:
bool z;
public:
Derived2() {} ;
Derived2(int x_) : Base(x_), z(true) {} ;
virtual void foo() {x--;}
};
class Container {
Base* b1 ;
Base* b2 ;
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & b1;
ar & b2 ;
}
public:
Container() {} ;
Container(int x, int y) {
b1 = new Derived1(x,y) ;
b2 = new Derived2(x) ;
}
};
BOOST_CLASS_EXPORT(Derived1) ;
BOOST_CLASS_EXPORT(Derived2) ;
int main() {
std::ofstream ofs("filename");
const Container c(1,2) ;
portable_binary_oarchive oa(ofs);
oa << c;
}
________________________________
_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
________________________________
_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
________________________________
_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net