Re: serializing an object to a string

From: Helge Jensen (helge.jensen_at_slog.dk)
Date: 03/15/05


Date: Tue, 15 Mar 2005 16:07:58 +0100

Marco Herrn wrote:
> Hi Helge,

Hi.

> Helge Jensen wrote:
>> Marco Herrn wrote:
>>> Another problem is: Is UTF8 Encoding the correct one? Would be
>>> another encoding more appropriate?

I don't think any *particular* encoding is appropriate.

A good choice would be the one the SoapFormatter uses, but it's really
not required.

>> There is probably no reason to even set the encoding.
> But when converting the byte Array to a string I need to use a Encoding.
> Or is there a different way of this conversion?

Can't you store the serialized object without conversion? You are
introducing an interpretation.

Try thinking what about what would happen if you chose Base64
en/de-coding for the conversion between byte[] and string. It would
work, since the encoding of the xml-document is independent of the
string<->byte conversion.

You could look into the serialized byte[] and choose an encoding based
on the xml encondig-declaration (it would be the identity encoding), but
it's really better if you could just skip the conversion byte[] <-> string.

> Thanks for your code example. It works. But still lacks the conversion
> to a string. How can I convert the buffer _without_ converting the extra
> bytes at the end?

I think you should go out of your way, not to do that conversion.

-- 
Helge Jensen
   mailto:helge.jensen@slog.dk
   sip:helge.jensen@slog.dk
                -=> Sebastian cover-music: http://ungdomshus.nu <=-


Relevant Pages

  • Re: utf8 vs iso8859-1 speed/responsiveness
    ... Glibc internal encoding is UTF32/UCS4, and modern toolkits, thus ... on RH9 as well. ... conversion happens everywhere on the fly. ... So regardless of RH9 or FC2, ...
    (Fedora)
  • Re: Proposal: require 7-bit source strs
    ... I'm referring to a time when there was no encoding ... It would be possible to go back and find all strings ... That's why I specified to do this after conversion to ... make the assumption that the character set is ASCII-based, ...
    (comp.lang.python)
  • Re: Proposal to extend documentation about interop
    ... > utf-8 encoding of the character FF. ... > I solved it by doing the conversion of UTF-8 to bytes and when going back to ...
    (microsoft.public.dotnet.framework.interop)
  • Re: RfD: XCHAR wordset (Version 3)
    ... The only switch of encoding that's reasonable possible is from ASCII to some ASCII-compatible encoding, but going back is not a good idea. ... If you add conversion semantics to it, you will break A LOT of code. ... In my code xc is an Unicode code point, but a sequence of utf8 bytes backed into one cell would be a valid implementation, too. ...
    (comp.lang.forth)
  • Re: New keyword orif and its implications
    ... code showing that the conversion of an enumerated type to and from a ... the usage of conversion functions at either end of a connection is ... the necessary conditions for the conversion functions to dissolve away....as ... A binary encoding is by definition ...
    (comp.lang.vhdl)