Boost logo

Boost Users :

Subject: Re: [Boost-users] Problem with Boost Serialization
From: Binh Luong (tbinhluong_at_[hidden])
Date: 2010-03-03 18:54:44


Hi,

thank you very much for your answer. I was stuck with this problem for days.
I have changed the code so that a const pointer is now passed to the
RemoteMessagingSystem::serialize:
string RemoteMessagingSystem::serialize (Message* const msg)
{
...
}

But the problem with deserialize is still there:
In file included from
/home/v0d0i/libraries/boost_1_42_0/include/boost/archive/xml_iarchive.hpp:24,
                 from message/remote/RemoteMessagingSystem.h:31,
                 from message/remote/RemoteMessagingSystem.cpp:1:
/home/v0d0i/libraries/boost_1_42_0/include/boost/archive/basic_xml_iarchive.hpp:
In member function ‘void
boost::archive::basic_xml_iarchive<Archive>::load_override(T&, int) [with T
= Message*, Archive = boost::archive::xml_iarchive]’:
/home/v0d0i/libraries/boost_1_42_0/include/boost/archive/xml_iarchive.hpp:80:
instantiated from ‘void
boost::archive::xml_iarchive_impl<Archive>::load_override(T&, int) [with T =
Message*, Archive = boost::archive::xml_iarchive]’
/home/v0d0i/libraries/boost_1_42_0/include/boost/archive/detail/interface_iarchive.hpp:61:
instantiated from ‘Archive&
boost::archive::detail::interface_iarchive<Archive>::operator>>(T&) [with T
= Message*, Archive = boost::archive::xml_iarchive]’
message/remote/RemoteMessagingSystem.cpp:164: instantiated from here
/home/v0d0i/libraries/boost_1_42_0/include/boost/archive/basic_xml_iarchive.hpp:70:
error: no matching function for call to
‘assertion_failed(mpl_::failed************
boost::serialization::is_wrapper<Message*>::************)’
make[1]: *** [RemoteMessagingSystem.o] Error 1
make[1]: Leaving directory `/home/v0d0i/workspace/trunk1/src/base'
make: *** [all-recursive] Error 1

Here is the code fragement:
Message* RemoteMessagingSystem::deserialize (string data)
{
        stringstream archivStream (data, ios_base::binary | ios_base::in);
#ifdef REMOTE_XML
        boost::archive::xml_iarchive inputArchive( archivStream );
#else
        boost::archive::binary_iarchive inputArchive( archivStream );
#endif

        Message* msg = NULL; //line 164
        inputArchive >> msg;

        return msg;
}

Should I also change here Message* to Message* const?

Actually it is something strange because with the old versoin Boost 1.38
there are no compiling errors. Since i compiled and installed the new
version 1.42 i got those errors. Something should be changed between the 2
versions although i have compared the both source codes but do not find any
difference :/

Regards,
Binh

Matthias Troyer-2 wrote:
>
>
> On 3 Mar 2010, at 00:44, Binh Luong wrote:
>
>>
>> Hi,
>>
>>
>> Matthias Troyer-2 wrote:
>>>
>>> You should not have to define your class as a wrapper. Can you send the
>>> code fragment that causes the problem?
>>>
>>> Matthias
>>> _______________________________________________
>>> Boost-users mailing list
>>> Boost-users_at_[hidden]
>>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>>>
>>
>> here are the code segments that cause the problem:
>> As you see in the last message, there are errors in
>> RemoteMessagingSystem.cpp:147 and RemoteMessagingSystem.cpp:147. They are
>> the following 2 functions which serializes the obj Message to xml archive
>> and deserializes xml archive backwards to obj Message.
>>
>> string RemoteMessagingSystem::serialize (Message* msg)
>> {
>> stringstream archiveStream (ios_base::binary | ios_base::out);
>> {
>> #ifdef REMOTE_XML
>> boost::archive::xml_oarchive outputArchive( archiveStream );
>> #else
>> boost::archive::binary_oarchive outputArchive( archiveStream );
>> #endif //REMOTE_XML
>> outputArchive & msg; //line 147
>> }
>>
>> string data = archiveStream.str();
>> return data;
>> }
>>
>> Message* RemoteMessagingSystem::deserialize (string data)
>> {
>> stringstream archivStream (data, ios_base::binary | ios_base::in);
>> #ifdef REMOTE_XML
>> boost::archive::xml_iarchive inputArchive( archivStream );
>> #else
>> boost::archive::binary_iarchive inputArchive( archivStream );
>> #endif
>>
>> Message* msg = NULL;
>> inputArchive >> msg; // line 164
>>
>> return msg;
>> }
>>
>>
>
> Two things:
>
> 1.) You need to wrap the object into a NVP to use it with XML archives.
> 2.) You can only serialize const objects into a output archive, hence try
> passing a const pointer to the RemoteMessagingSystem::serialize function
>
>
> Matthias
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>

-- 
View this message in context: http://old.nabble.com/Problem-with-Boost-Serialization-tp27743377p27773125.html
Sent from the Boost - Users mailing list archive at Nabble.com.

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