DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
Serialization.hpp File Reference
#include "ers/Issue.hpp"
#include "logging/Logging.hpp"
#include "boost/preprocessor.hpp"
#include "msgpack.hpp"
#include <algorithm>
#include <string>
#include <vector>
Include dependency graph for Serialization.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  dunedaq::serialization::is_serializable< T >
 

Namespaces

namespace  dunedaq
 Including Qt Headers.
 
namespace  dunedaq::serialization
 

Macros

#define DUNE_DAQ_TYPESTRING(Type, typestring)
 
#define DUNE_DAQ_SERIALIZABLE(Type, typestring)
 
#define DUNE_DAQ_SERIALIZE(Type, ...)
 Macro to make a class/struct serializable intrusively.
 
#define OPACK(r, data, elem)
 
#define OUNPACK(r, data, elem)
 
#define DUNE_DAQ_SERIALIZE_NON_INTRUSIVE(NS, Type, ...)
 Macro to make a class/struct serializable non-intrusively.
 

Enumerations

enum  dunedaq::serialization::SerializationType { dunedaq::serialization::kMsgPack }
 Serialization methods that are available. More...
 

Functions

 dunedaq::ERS_DECLARE_ISSUE (serialization, UnknownSerializationTypeString, "Unknown serialization type "<< t,((std::string) t)) ERS_DECLARE_ISSUE(serialization
 
Unknown serialization dunedaq::ERS_DECLARE_ISSUE (serialization, UnknownSerializationTypeByte, "Unknown serialization type "<< t,((char) t)) ERS_DECLARE_ISSUE(serialization
 
template<typename T >
Unknown serialization Cannot deserialize std::string dunedaq::datatype_to_string ()
 
SerializationType dunedaq::serialization::from_string (const std::string s)
 Convert string to SerializationType.
 
constexpr uint8_t dunedaq::serialization::serialization_type_byte (SerializationType stype)
 
template<class T >
std::vector< uint8_t > dunedaq::serialization::serialize (const T &obj, SerializationType stype)
 Serialize object obj using serialization method stype.
 
template<class T , typename CharType = unsigned char>
dunedaq::serialization::deserialize (const std::vector< CharType > &v)
 Deserialize vector of bytes v into an instance of class T.
 

Variables

 dunedaq::UnknownSerializationTypeEnum
 
Unknown serialization dunedaq::type
 
Unknown serialization dunedaq::CannotDeserializeMessage
 
Unknown serialization Cannot deserialize dunedaq::message
 

Detailed Description

This is part of the DUNE DAQ Application Framework, copyright 2020. Licensing/copyright details are in the COPYING file that you should have received with this code.

Definition in file Serialization.hpp.

Macro Definition Documentation

◆ DUNE_DAQ_SERIALIZABLE

#define DUNE_DAQ_SERIALIZABLE ( Type,
typestring )
Value:
DUNE_DAQ_TYPESTRING(Type, typestring) \
template<> \
{ \
static constexpr bool value = true; \
}
#define DUNE_DAQ_TYPESTRING(Type, typestring)

Definition at line 30 of file Serialization.hpp.

30#define DUNE_DAQ_SERIALIZABLE(Type, typestring) \
31 DUNE_DAQ_TYPESTRING(Type, typestring) \
32 template<> \
33 struct dunedaq::serialization::is_serializable<Type> \
34 { \
35 static constexpr bool value = true; \
36 }

◆ DUNE_DAQ_SERIALIZE

#define DUNE_DAQ_SERIALIZE ( Type,
... )
Value:
MSGPACK_DEFINE(__VA_ARGS__) \
static_assert(true, "")

Macro to make a class/struct serializable intrusively.

Call the macro inside your class declaration, with the first argument being the class name, followed by each of the member variables. Example:

 struct MyType
 {
   int i;
   std::string s;
   std::vector<double> v;

   DUNE_DAQ_SERIALIZE(MyType, i, s, v);
 };

Definition at line 56 of file Serialization.hpp.

56#define DUNE_DAQ_SERIALIZE(Type, ...) \
57 MSGPACK_DEFINE(__VA_ARGS__) \
58 static_assert(true, "")

◆ DUNE_DAQ_SERIALIZE_NON_INTRUSIVE

#define DUNE_DAQ_SERIALIZE_NON_INTRUSIVE ( NS,
Type,
... )

Macro to make a class/struct serializable non-intrusively.

Call the macro outside your class declaration, from the global namespace. The first argument is the namespace of your class, the second is the class name, and the rest of the arguments list the member variables. Example:

 namespace ns {
 struct MyType
 {
   int i;
   std::string s;
   std::vector<double> v;
 }
 }

 DUNE_DAQ_SERIALIZE_NON_INTRUSIVE(ns, MyType, i, s, v);

Definition at line 87 of file Serialization.hpp.

87#define DUNE_DAQ_SERIALIZE_NON_INTRUSIVE(NS, Type, ...) \
88 DUNE_DAQ_SERIALIZABLE(NS::Type, #Type); \
89 namespace msgpack { \
90 MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) \
91 { \
92 namespace adaptor { \
93 template<> \
94 struct pack<NS::Type> \
95 { \
96 template<typename Stream> \
97 packer<Stream>& operator()(msgpack::packer<Stream>& o, NS::Type const& m) const \
98 { \
99 o.pack_array(BOOST_PP_VARIADIC_SIZE(__VA_ARGS__)); \
100 BOOST_PP_SEQ_FOR_EACH(OPACK, , BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)) \
101 return o; \
102 } \
103 }; \
104 template<> \
105 struct convert<NS::Type> \
106 { \
107 msgpack::object const& operator()(msgpack::object const& o, NS::Type& m) const \
108 { \
109 if (o.type != msgpack::type::ARRAY) \
110 throw msgpack::type_error(); \
111 if (o.via.array.size != BOOST_PP_VARIADIC_SIZE(__VA_ARGS__)) \
112 throw msgpack::type_error(); \
113 int i = 0; \
114 BOOST_PP_SEQ_FOR_EACH(OUNPACK, , BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)) \
115 return o; \
116 } \
117 }; \
118 } \
119 } \
120 }

◆ DUNE_DAQ_TYPESTRING

#define DUNE_DAQ_TYPESTRING ( Type,
typestring )
Value:
template<> \
inline std::string dunedaq::datatype_to_string<Type>() \
{ \
return typestring; \
}
Unknown serialization Cannot deserialize std::string datatype_to_string()

Definition at line 23 of file Serialization.hpp.

23#define DUNE_DAQ_TYPESTRING(Type, typestring) \
24 template<> \
25 inline std::string dunedaq::datatype_to_string<Type>() \
26 { \
27 return typestring; \
28 }

◆ OPACK

#define OPACK ( r,
data,
elem )
Value:
o.pack(m.elem);

Definition at line 62 of file Serialization.hpp.

◆ OUNPACK

#define OUNPACK ( r,
data,
elem )
Value:
m.elem = o.via.array.ptr[i++].as<decltype(m.elem)>();

Definition at line 64 of file Serialization.hpp.