Boost logo

Boost Users :

Subject: [Boost-users] [boost::serialization] string serialization
From: Bob Walters (bob.s.walters_at_[hidden])
Date: 2009-05-28 09:53:20

I've been trying to use boost::serialization to serialize non-standard
strings. Specifically, std::basic_string with a non-standard allocator
type, and in another case, boost::interprocess::basic_string.

Looking at how std::string serialization was enabled in
serialization/string.hpp, I thought I would try to broaden that
approach by using a specialization of the implementation_level
template as follows:

namespace boost {
namespace serialization {

template <typename C, class T, class A>
struct implementation_level< std::basic_string<C,T,A> >
  typedef mpl::integral_c_tag tag;
  typedef mpl::int_< boost::serialization::primitive_type > type;
      value = implementation_level::type::value

} // namespace
} // namespace

I've tried also adding wraper traits (also in boost::serialization namespace):

template<typename C, class T, class A>
struct is_wrapper< std::basic_string<C,T,A> > : mpl::true_ {};

Serialization of these strings is compiling, and
running. At first it looked like it worked, but not quite.
Specifically: when the string in question is 16 bytes or less in size
(including the \0), the string serializes fine. When longer than
that, its value appears to be completely truncated. (I'm looking at
the dump of a binary_oarchive.) This isn't the case for std::string,
but I'm having a problem figuring out why.

I realize this is an unconventional scenario, but any assistance on
how to make the support for string serialization apply to more than
just std::string is appreciated.

(Perhaps this should be ticketed as a feature request?)

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at