Skip to content

backmp11: Improve serializer interface #197

@chandryan

Description

@chandryan

The serializer interface in backmp11 is defined as a generic friend declaration without providing an implementation.
While this allows different user-provided serializer implementations, it requires users to understand implementation details of the back-end and potentially breaks when the implementation details change.

Consider potential improvements to decouple the user-provided serializer implementation from backmp11 implementation details.

Idea collection:


Idea 1: Adapt the interface to require generic operators on the serializer that only gets builtins as input

In place of a friend declaration we define a function that forwards its members on the archive argument. Example:

template<typename T, typename A0, typename A1, typename A2>
void serialize(T& archive, state_machine_base<A0, A1, A2>& sm)
{
    archive & sm.member_1;
    archive & sm.member_2;
    ...
}

The serialization methods should be chosen in a way to support a generic way of integrating different serialization frameworks.
The more frameworks are supported out-of-the-box the better. In case the methods don't match, an adapter pattern shall be possible to implement the needed syntax for the framework.

Existing serialization frameworks

Boost.Serialization:
132 stars on GitHub but probably a widely used library. Stars for Boost libraries have limited significance.

  • bidirectional syntax: operator& on the archive
  • Input/output syntax: operator>> , operator<< on the archive

cereal:
4.6k stars on GitHub, seems widespread. Inspired by Boost.Serialization, said to be a moremodern alternative.

  • bidirectional syntax: operator() on the archive with support for variadic arguments
  • Alternatively supports the Boost.Serlization operators for compatibility reasons

zpp_bits:
1k stars on GitHub.

  • bidirectional syntax: operator() on the archive with support for variadic arguments

bitsery:
1.2k stars on GitHub. Claims to be very efficient.

  • bidirectional syntax: Custom methods of the archive depending on the phyiscal layout
    • examples: archive.value1b(sm.m_event_processing);

Requires library-specific adapter code due to the custom methods.

nlohman/json:
49.3k stars on GitHub.
Does not work with binary streams, all state machine members must be passed with keys for identification.
Possiblity for support needs to be investigated. It would be a nice feature for easy introspection into a state machine.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions