Boost logo

Boost :

Subject: Re: [boost] Interest in serialization library
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2012-12-28 03:45:10


On Fri, Dec 28, 2012 at 12:07 PM, iwg molw5 <iwg.molw5_at_[hidden]> wrote:
> On Fri, Dec 28, 2012 at 12:38 AM, Andrey Semashev <andrey.semashev_at_[hidden]
>> wrote:
>
>> Could you elaborate? A short example would certainly help.
>>
>
> struct S
> {
> int x;
> };
>
> namespace framework {namespace serializable {
> template <>
> serializable_specification <S>
> {
> template <typename Input>
> static bool read (Input& in, S& out)
> {
> return serializable_specification <little_endian
> <int>>::read(in, out.x));
> }
>
> template <typename Output>
> static bool write (S const& in, Output& out)
> {
> return serializable_specification <little_endian
> <int>>::write(in.x, out));
> }
> };
> }}
>
> Admittedly, the above is not particularly palatable - I wanted to
> introduce nested serializable_specification calls and avoid
> referencing operator types above. The library does not constrain the
> stream type - the above could just as easily assume the presence of stream
> operators and use those. See:
>
> framework/serializable/custom_serialization.cpp
>
> for a more complete example and:
>
> framework/serializable/custom_serialization_boost.cpp
>
> for a syntax closer to that used by boost.

I see. It would be great if the library provided a way to define the
serialization format as a grammar separately from the object
definition - perhaps similarly to how Boost.Fusion adapts structs or
in pure C++ syntax without macros in Boost.Spirit style; whichever
works best. The serializable_specification approach can be useful for
tricky cases but as a general solution it doesn't provide a good
readable description of the target format.

One more question. Does the library provide a portable binary format
for floating point numbers?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk