Boost logo

Boost Users :

Subject: Re: [Boost-users] (boost serialization) wstring portability issue
From: Robert Ramey (ramey_at_[hidden])
Date: 2010-12-16 13:46:19


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.

>
> 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.

Another solution might eb to try text_warchive - I don't know
if that would help either

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 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