DUNE-DAQ
DUNE Trigger and Data Acquisition software
|
#include "ers/Issue.hpp"
#include "logging/Logging.hpp"
#include "boost/preprocessor.hpp"
#include "msgpack.hpp"
#include <algorithm>
#include <string>
#include <vector>
Go to the source code of this file.
Namespaces | |
namespace | dunedaq |
The DUNE-DAQ namespace. | |
Macros | |
#define | DUNE_DAQ_TYPESTRING(Type, typestring) |
Declare the datatype_to_string method for the given type. | |
#define | DUNE_DAQ_SERIALIZABLE(Type, typestring) |
Macro to define a type as serializable, so it can be sent over the network. | |
#define | DUNE_DAQ_SERIALIZE(Type, ...) |
Macro to make a class/struct serializable intrusively. | |
#define | OPACK(r, data, elem) |
Helper macro for DUNE_DAQ_SERIALIZE_NON_INTRUSIVE() | |
#define | OUNPACK(r, data, elem) |
Helper maro for DUNE_DAQ_SERIALIZE_NON_INTRUSIVE. | |
#define | DUNE_DAQ_SERIALIZE_NON_INTRUSIVE(NS, Type, ...) |
Macro to make a class/struct serializable non-intrusively. | |
#define | DUNE_DAQ_SERIALIZE_ENUM(Type) |
Macro to declare an enum type to the serialization library. | |
Functions | |
dunedaq::ERS_DECLARE_ISSUE (serialization, UnknownSerializationTypeString, "Unknown serialization type "<< t,((std::string) t)) ERS_DECLARE_ISSUE(serialization | |
Issue for when the serialization type cannot be determined from an input string. | |
return obj | dunedaq::as< T > () |
dunedaq::catch (msgpack::type_error &e) | |
dunedaq::catch (msgpack::unpack_error &e) | |
Variables | |
dunedaq::UnknownSerializationTypeByte | |
Unknown serialization type<< t,((char) t)) template< typename T > inline std::string datatype_to_string() { return "Unknown";} namespace serialization { template< typename T > struct is_serializable :std::false_type {};enum SerializationType { kMsgPack };inline SerializationType from_string(const std::string s) { if(s=="msgpack") return kMsgPack;throw UnknownSerializationTypeString(ERS_HERE, s);} constexpr uint8_t serialization_type_byte(SerializationType stype) { switch(stype) { case kMsgPack:return 'M';default:throw UnknownSerializationTypeEnum(ERS_HERE);} } constexpr SerializationType DEFAULT_SERIALIZATION_TYPE=kMsgPack;template< class T > std::vector< uint8_t > serialize(const T &obj, SerializationType stype=DEFAULT_SERIALIZATION_TYPE) { switch(stype) { case kMsgPack:{ msgpack::sbuffer buf;msgpack::pack(buf, obj);std::vector< uint8_t > ret(buf.size()+1);ret[0]=serialization_type_byte(stype);std::copy(buf.data(), buf.data()+buf.size(), ret.begin()+1);return ret;} default:throw UnknownSerializationTypeEnum(ERS_HERE);} } template< class T, typename CharType=unsigned char > T deserialize(const std::vector< CharType > &v) { switch(v[0]) { case serialization_type_byte(kMsgPack):{ try { msgpack::object_handle oh=msgpack::unpack(const_cast< char * >(reinterpret_cast< const char * >(v.data()+1)), v.size() - 1,[](msgpack::type::object_type, std::size_t, void *) -> | dunedaq::bool { return true |
msgpack::object | dunedaq::obj = oh.get() |
default | dunedaq::__pad0__ |
default char | dunedaq::v [0] |
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.
Serialization methods are defined here, currently only MsgPack is supported. For an example of how nlohmann::json was implemented, look at tag v1.4.0 of this file: https://github.com/DUNE-DAQ/serialization/blob/v1.4.0/include/serialization/Serialization.hpp In general, the DUNE_DAQ_SERIALIZE and DUNE_DAQ_SERIALIZE_NON_INTRUSIVE macros need to have definitions for the seralizer, and the serialize and deseralize methods need a case for each serialization type.
Definition in file Serialization.hpp.
#define DUNE_DAQ_SERIALIZABLE | ( | Type, | |
typestring ) |
Macro to define a type as serializable, so it can be sent over the network.
Definition at line 47 of file Serialization.hpp.
#define DUNE_DAQ_SERIALIZE | ( | Type, | |
... ) |
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 73 of file Serialization.hpp.
#define DUNE_DAQ_SERIALIZE_ENUM | ( | Type | ) |
Macro to declare an enum type to the serialization library.
Definition at line 144 of file Serialization.hpp.
#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 105 of file Serialization.hpp.
#define DUNE_DAQ_TYPESTRING | ( | Type, | |
typestring ) |
Declare the datatype_to_string method for the given type.
Type | C++ class |
typestring | String representation for this class |
Definition at line 36 of file Serialization.hpp.
#define OPACK | ( | r, | |
data, | |||
elem ) |
Helper macro for DUNE_DAQ_SERIALIZE_NON_INTRUSIVE()
Definition at line 79 of file Serialization.hpp.
#define OUNPACK | ( | r, | |
data, | |||
elem ) |
Helper maro for DUNE_DAQ_SERIALIZE_NON_INTRUSIVE.
Definition at line 82 of file Serialization.hpp.