DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
dfmessages
include
dfmessages
Fragment_serialization.hpp
Go to the documentation of this file.
1
9
10
#ifndef DFMESSAGES_INCLUDE_DFMESSAGES_FRAGMENT_SERIALIZATION_HPP_
11
#define DFMESSAGES_INCLUDE_DFMESSAGES_FRAGMENT_SERIALIZATION_HPP_
12
13
#include "
daqdataformats/Fragment.hpp
"
14
#include "
serialization/Serialization.hpp
"
15
#include "
logging/Logging.hpp
"
// NOTE: if ISSUES ARE DECLARED BEFORE include logging/Logging.hpp, TLOG_DEBUG<<issue wont work.
16
17
#include <memory>
18
#include <vector>
19
20
// MsgPack serialization functions (which just put the raw bytes of
21
// the fragment array into a MsgPack message)
22
namespace
msgpack
{
23
MSGPACK_API_VERSION_NAMESPACE
(MSGPACK_DEFAULT_API_NS)
24
{
25
namespace
adaptor {
26
27
template
<>
28
struct
pack<dunedaq::daqdataformats::Fragment>
29
{
30
template
<
typename
Stream>
31
packer<Stream>& operator()(msgpack::packer<Stream>& o, dunedaq::daqdataformats::Fragment
const
& frag)
const
32
{
33
o.pack_bin(frag.
get_size
());
// pack header and size
34
o.pack_bin_body(
static_cast<
const
char
*
>
(frag.
get_storage_location
()), frag.
get_size
());
// pack payload
35
return
o;
36
}
37
};
38
39
// Typically we use convert<> for deserialization, but Fragment isn't
40
// default constructible, so we have to use as<>. See:
41
// https://github.com/msgpack/msgpack-c/wiki/v2_0_cpp_adaptor#non-default-constructible-class-support-c11-only-since-120
42
template
<>
43
struct
as<dunedaq::daqdataformats::Fragment>
44
{
45
dunedaq::daqdataformats::Fragment operator()(msgpack::object
const
& o)
const
46
{
47
// The second argument to the Fragment ctor is whether to copy
48
// the data array into the Fragment's own storage. Putting false
49
// here would be faster, but we have to copy, since the returned
50
// Fragment might outlast the msgpack::object which owns/points
51
// to the underlying data.
52
return
dunedaq::daqdataformats::Fragment(
const_cast<
char
*
>
(o.via.bin.ptr),
53
dunedaq::daqdataformats::Fragment::BufferAdoptionMode::kCopyFromBuffer
);
54
}
55
};
56
57
template
<>
58
struct
pack<std::unique_ptr<dunedaq::daqdataformats::Fragment>>
59
{
60
template
<
typename
Stream>
61
packer<Stream>& operator()(msgpack::packer<Stream>& o,
62
std::unique_ptr<dunedaq::daqdataformats::Fragment>
const
& frag)
const
63
{
64
o.pack_bin(frag->get_size());
// pack header and size
65
o.pack_bin_body(
static_cast<
const
char
*
>
(frag->get_storage_location()), frag->get_size());
// pack payload
66
return
o;
67
}
68
};
69
70
// Typically we use convert<> for deserialization, but Fragment isn't
71
// default constructible, so we have to use as<>. See:
72
// https://github.com/msgpack/msgpack-c/wiki/v2_0_cpp_adaptor#non-default-constructible-class-support-c11-only-since-120
73
template
<>
74
struct
as<std::unique_ptr<dunedaq::daqdataformats::Fragment>>
75
{
76
std::unique_ptr<dunedaq::daqdataformats::Fragment> operator()(msgpack::object
const
& o)
const
77
{
78
// The second argument to the Fragment ctor is whether to copy
79
// the data array into the Fragment's own storage. Putting false
80
// here would be faster, but we have to copy, since the returned
81
// Fragment might outlast the msgpack::object which owns/points
82
// to the underlying data.
83
return
std::make_unique<dunedaq::daqdataformats::Fragment>(
84
const_cast<
char
*
>
(o.via.bin.ptr),
dunedaq::daqdataformats::Fragment::BufferAdoptionMode::kCopyFromBuffer
);
85
}
86
};
87
}
// namespace adaptor
88
}
// namespace MSGPACK_DEFAULT_API_NS
89
}
// namespace msgpack
90
91
DUNE_DAQ_SERIALIZABLE
(
dunedaq::daqdataformats::Fragment
,
"Fragment"
);
92
DUNE_DAQ_SERIALIZABLE
(std::unique_ptr<dunedaq::daqdataformats::Fragment>,
"Fragment"
);
93
94
#endif
// DFMESSAGES_INCLUDE_DFMESSAGES_FRAGMENT_SERIALIZATION_HPP_
Fragment.hpp
Serialization.hpp
DUNE_DAQ_SERIALIZABLE
#define DUNE_DAQ_SERIALIZABLE(Type, typestring)
Macro to define a type as serializable, so it can be sent over the network.
Definition
Serialization.hpp:47
dunedaq::daqdataformats::Fragment
C++ Representation of a DUNE Fragment, wrapping the flat byte array that is the Fragment's "actual" f...
Definition
Fragment.hpp:38
dunedaq::daqdataformats::Fragment::BufferAdoptionMode::kCopyFromBuffer
@ kCopyFromBuffer
Copy the contents of the buffer into a new Fragment array.
Definition
Fragment.hpp:44
dunedaq::daqdataformats::Fragment::get_size
fragment_size_t get_size() const
Get the total size of the Fragment in bytes, including header and all payload pieces.
Definition
Fragment.hpp:147
dunedaq::daqdataformats::Fragment::get_storage_location
const void * get_storage_location() const
Get read-only access to the Fragment's underlying data array via a pointer.
Definition
Fragment.hpp:71
Logging.hpp
msgpack
Definition
serialize_variant.hpp:24
msgpack::MSGPACK_API_VERSION_NAMESPACE
MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS)
Definition
serialize_variant.hpp:25
Generated on
for DUNE-DAQ by
1.17.0