Boost logo

Boost :

Subject: Re: [boost] Interest in serialization library
From: iwg molw5 (iwg.molw5_at_[hidden])
Date: 2012-12-28 18:26:51


On Fri, Dec 28, 2012 at 1:45 AM, Andrey Semashev
<andrey.semashev_at_[hidden]>wrote:

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

I added some sample code that accomplishes the above - see:

  examples/serializable/non_intrusive_wrappers_1.cpp

Sample syntax:

  struct Object
  {
      uint32_t x;
      uint32_t y;
      uint32_t z;
  };

  using ObjectSpecification = alias <
      link <LINK(Object::x), little_endian <uint32_t>>,
      link <LINK(Object::y), little_endian <uint32_t>>,
      link <LINK(Object::z), little_endian <uint32_t>>>;

  BIND(ObjectSpecification, Object)

I'm not particularly happy with that implementation. The above syntax is
tolerable and the implementation is light, however that kind of detached
specification is not really compatible with generic member access.
Another possible approach involved binding the members of Object to a
temporary serializable object; this would avoid the preceding problems,
but it comes with it's own set of drawbacks. I'll add that implementation
to a similar example under non_intrusive_wrappers_2.cpp sometime this
weekend. Perhaps one of these was what you were looking for - if not,
comments are welcome.


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