Boost logo

Boost Users :

Subject: Re: [Boost-users] (boost serialization) wstring portability issue
From: Arash Abghari (arash.abghari_at_[hidden])
Date: 2010-12-16 13:58:21


On Thu, 16 Dec 2010 10:46:19 -0800
"Robert Ramey" <ramey_at_[hidden]> wrote:

> Arash Abghari wrote:
> > Hi,
> >
> > I wonder if there is a way to have wstring portable between Windows
> > and Linux. To be more elaborative consider the following code:
> >
> > wstring s(L"abcd");
> > std::ofstream
> > ofs("./my_archive",std::iostream::binary);
> > boost::archive::text_oarchive oa(ofs);
> > oa << s;
> >
> > the file my_archive under Linux looks like this:
> >
> > $ xxd my_archive
> > 0000000: 3232 2073 6572 6961 6c69 7a61 7469 6f6e 22 serialization
> > 0000010: 3a3a 6172 6368 6976 6520 3520 3420 6100 ::archive 5 4 a.
> > 0000020: 0000 6200 0000 6300 0000 6400 0000 ..b...c...d...
> >
> > while under Windows it looks like:
> >
> > $ xxd my_archive
> > 0000000: 3232 2073 6572 6961 6c69 7a61 7469 6f6e 22 serialization
> > 0000010: 3a3a 6172 6368 6976 6520 3520 3420 6100 ::archive 5 4 a.
> > 0000020: 6200 6300 6400 b.c.d.
> >
> > as expected it reserved 4 bytes for each character under Linux
> > while 2 bytes under Windows. Thus the archive file created under
> > Linux is not loadable under Windows and vice versa.
>
> wow - this is a huge surprise to me. It's totally contrary to the
> intention of
> the text archive. looks to me that wstring serialization needs some
> work. I guess it hasn't come up because it's rare to serialize
> wstring into a text archive.
 I agree

>
> >
> > So my question is if there is a workaround or solution to this
> > problem?
>
> One way MIGHT be to use a utf-8 conversion facet on the
> stream used by the text archive.
>
I thought about it.

> Another solution might eb to try text_warchive - I don't know
> if that would help either
>
 
I tried it as well. This does not help either since it suffers from same
problem. (reserves 4 bytes under Linux and 2 bytes under Windows for
each character).

> BTW - the would issue of what a wstring is or should be is
> more than a little messy in my humble opinion. Recent
> discussions make me think the same for string as well.
>
> Robert Ramey
>
> > By the way I am using boost 1.40 , gcc 4.3.4 and VC 9.0.
> >
> > Thanks,
> >
> > Arash
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users

I wonder if it is possible to overwrite the serialization of wstring
in boost by the custom one in which it converts it to utf-8 first and
save it and does the reverse in load.


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