DUNE-DAQ
DUNE Trigger and Data Acquisition software
|
This repository contains utilities for serializing/deserializing C++ objects for DUNE DAQ. Serialization allows objects to be sent across the network or persisted to disk.
An appropriately-defined C++ type (see below) can be serialized/deserialized as follows:
Classes can be made serializable by adding convertor functions for msgpack
.
The easiest way to make your class (de)serializable is with the DUNE_DAQ_SERIALIZE()
and DUNE_DAQ_SERIALIZABLE()
convenience macros provided in Serialization.hpp
:
You may not be able to change the type itself, either because you don't have access to it, or because it lives in a package that cannot depend on the serialization
package. In this case, you can use the DUNE_DAQ_SERIALIZE_NON_INTRUSIVE()
macro instead. In the global namespace, call DUNE_DAQ_SERIALIZE_NON_INTRUSIVE()
with first argument the namespace of your class, second argument the class name, and the rest of the arguments listing the member variables. For example:
A complete example, showing both intrusive and non-intrusive strategies, can be found in theSerialization_test
unit test.
It is also a good idea to define a unit test for each message type being serialized and deserialized, to ensure that all macro calls are complete (i.e. not missing member variables as parameters). See the dfmessages tests for good examples.
Full instructions for serializing arbitrary types with msgpack
are available here. These include instructions for (de)serializing classes that are not default-constructible. Several custom serializers have been implemented, such as Fragment_serialization.hpp in dfmessages
. Note that custom seralizers may need to use macros or functions specific to serialization libraries. This is the only place where seralizers should be referenced outside of this library!
Currently, only MsgPack is supported. Additional serialization methods can be implmemented using the instructions in Serialization.hpp. The design of Serialization.hpp was created with only a few serialization types envisioned. If multiple serialization libraries need to be added, the design of this package may need to be revisited.
Choice of serialization methods: there are many, many libraries and formats for serialization/deserialization, with a range of tradeoffs. For the binary format, we wanted a library that allows serialization of arbitrary types, rather than requiring types to be specified in a library-specific manner or DSL (this rules out, eg, protobuf
). We may have to revisit that requirement if we find that msgpack
does not meet performance requirements. However, via the macros DUNE_DAQ_SERIALIZE and DUNE_DAQ_SERIALIZE_NON_INSTRUSIVE, it is possible to inject code into the message types if needed by the serialization library (as is done for MsgPack and was done for nlohmann::json).
Serialization libraries are tested in Serialization_test
, by adding to the BOOST_DATA_TEST_CASE macro calls.