Boost logo

Boost Users :

Subject: Re: [Boost-users] Automating Serialization?
From: Stefan Strasser (strasser_at_[hidden])
Date: 2009-11-26 17:54:10


Am Thursday 26 November 2009 14:05:18 schrieb Bilokon, Paul:
> Hi,
>
> By design Boost Serialization requires the user to list each field that
> needs to be serialised.
>
> This is in contrast, for example, with Java and some other languages where
> serialisation is supported (kind of) at the language level.
>
> The current approach requires some code duplication. We have to declare a
> field. We have to manually (de)serialise it. If we need to make a change,
> we make it in at least two distinct places.
>
> Is there any way to automate the process of serialisation, perhaps
> harnessing the power of the preprocessor? E.g. we could label the fields
> that need to be serialised. Is there anything in Boost that could help?

not that I'm aware of, but I even think that's a good thing.
the serialize() function represents a file format, and you want file formats
to be stable and not being changed because someone added a runtime field to a
class.
usually when you do want to add a serialized field you'd also want old
versions of the file still to be readable, so you end up writing custom
(versioned) deserialization code anyway, even if your language has built-in
serialization support.

you could use some compile time code generator to write default serialization
code for you, using e.g. OpenC++, GCC-XML, or Doxygen, but I doubt those
generated functions would stay there very long.


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