lizardfs/lizardfs — pull request #159 by lalek (2014-03-06 14:53:43+00:00)
Title: common: Add macro for generating serializable classes

Add a macro that defines a class, that has automatically generated
methods for serialization. Due to the genericness of this
implementation, there is no need to implement a unit test that
checks if serialization works fine for objects created with use
of this macro.

The macro should be used like this:

include "common/serializable_class.h"

SERIALIZABLE_CLASS_BEGIN(MyClassName : public SomeBase)
SERIALIZABLE_CLASS_BODY(
MyClassName,
int , fieldA,
double, fieldB,
long , fieldC
)
// Macro doesn't close class definition bracket, so we can provide
// any additional code we want:
MyClassName() = default; // Like a constructor
void myMethod() {
fieldA_ = 5; // We can also use class fields using underscore
}
SERIALIZABLE_CLASS_END

int main() {
MyClassName a = MyClassName(0, 1.0, 2l); // A tuple-like
// constructor is also generated
std::vector buffer;
serialize(buffer, a);
}

Change-Id: I3bd3f1e1ed2111f89aa9561c0d1571d5e424b23a