
On Fri, Dec 28, 2012 at 12:07 PM, iwg molw5 <iwg.molw5@gmail.com> wrote:
On Fri, Dec 28, 2012 at 12:38 AM, Andrey Semashev <andrey.semashev@gmail.com
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?