Hi,
I just found this "const",
I tried it but still the program never get to the save_impl() method, hence the output not portable.
Thanks
Dan
p.s : I missed the initialization in the code when I copied it. It should be: boost::archive::class_id_type const cid (100) ;
________________________________
From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Robert Ramey
Sent: ד 28 פברואר 2007 00:40
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] [Serialization] issue withportable_binary_oarchive
When I make the following change it works
"Dan Leibovich" wrote in message news:80726DBE398EBB4A8B77AD210C509EAA029C602A@MAILEU.global.cadence.com...
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 const cid ; // note "const" here
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::save(t);
Do you have any idea of how to overcome this issue.
Thank you
Dan Leibovich
________________________________
From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Robert Ramey
Sent: ג 27 פברואר 2007 18:15
To: boost-users@lists.boost.org
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" wrote in message news:80726DBE398EBB4A8B77AD210C509EAA0291B278@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
#include
#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@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Robert Ramey
Sent: ב 26 פברואר 2007 22:29
To: boost-users@lists.boost.org
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" wrote in message news:80726DBE398EBB4A8B77AD210C509EAA0291B077@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@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Robert Ramey
Sent: ד 21 פברואר 2007 21:54
To: boost-users@lists.boost.org
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" wrote in message news:80726DBE398EBB4A8B77AD210C509EAA0291A579@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
#include
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@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
________________________________
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
________________________________
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
________________________________
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users