tomasbrod / tbboinc

Boinc T.Brada apps and configs
0 stars 0 forks source link

Serialization Improvement #2

Open tomasbrod opened 4 years ago

tomasbrod commented 4 years ago

Currently serialization is handles using hand-written write and parse functions. This is cumbersome, due to the sheer amount of code written, and error-prone, because these two functions are separate. We also have separate functions to marshall and unmarshall objects into SQL database. I propose to unify and clean up these using either table-driven or template-driven automatic serialization. Existing libraries include: boost/archive, A Working Library, Cereal, eyalz800 and the bitcoin serializer. I think, none of them would work as-is and custom microframework for our use will be needed. Anyway, I predict, it will be less code, than what there currently is.

Approach a) each serializable structure defines a table containing description of the struct fields, xml-name, type and maybe custom handler. Macros can help defining this table. Then a set of general functions will, with the help of the table, write or parse the struct. Approach b) use templates and overloading to make to implement the same (like boost/archive and cereal). Currently the codebase is limited to C++03, which may, or may not affect this approach.

Gains: More developers interested in working with the code once they see it's not utter mess. Less duplicate code. Possibility to switch to a better format than XML in the future. Make it more developer-friendly.

Compatibility with the old clients (thus XML) should be maintained.

The XML part of the framework should be based on some standard SAX parsing library, see: https://github.com/BOINC/boinc/issues/2070 . Using DOM library may make it easier to implement, but also slower. Thoughts?

// sample structure with the approach B
struct MSG_FROM_HOST_DESC {
  char variety[256];
  std::string msg_text;
  template<clsss Seralizer> serialize_func(Ser& s) {
    SFIELD(variety);
    SFIELD(msg_text);
  }
};
tomasbrod commented 4 years ago

https://github.com/tomasbrod/tbboinc/tree/primes/serializ