Boost logo

Boost :

Subject: Re: [boost] Interest in serialization library
From: iwg molw5 (iwg.molw5_at_[hidden])
Date: 2012-12-28 03:07:09


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.

Does the library control the validity of the serialized data when
> deserializing? Is there an associated overhead?
>

The library supports custom wrapper types (such as little_endian) and
custom implementations (not introduced above - see
custom_implementation.cpp or the documentation's tutorial) depending on
the type of input validation required.


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