Boost logo

Boost Users :

Subject: Re: [Boost-users] How to serialize basic_string<unsigned char>
From: Robert Ramey (ramey_at_[hidden])
Date: 2010-04-10 14:21:36


Martin Dietze wrote:
> On Sat, April 10, 2010, Robert Ramey wrote:
>
>> Just look at boost/serialization/string.hpp and do the same thing
>> for unsigned char
>
> Yes, that was my first thought, too. Consider the code below.
> Execution fails with this assertion:
>
> a.out: test.cc:47: void load(): Assertion `size == 10' failed.
> Aborted

This is a little bit tricky. Look carefully at the documentation regarding
BOOST_CLASS_IMPLEMENTATION and try replacing

BOOST_CLASS_IMPLEMENTATION(std::basic_string<unsigned char>,
boost::serialization::primitive_type)
with
BOOST_CLASS_IMPLEMENTATION(std::basic_string<unsigned char>,
boost::serialization::object_type)

(double check "object_type") Basically you want the next level of support
above primitive_type.

Also, consider using

ar & static_cast<basic_string<char> >(my unsigned string)

Robert Ramey


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