Belle II Software development
ZMQMessageHelper.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#pragma once
9
10#include <framework/dataobjects/EventMetaData.h>
11#include <framework/pcore/zmq/messages/ZMQDefinitions.h>
12#include <framework/pcore/zmq/utils/EventMetaDataSerialization.h>
13#include <framework/pcore/EvtMessage.h>
14#include <framework/datastore/StoreObjPtr.h>
15#include <zmq.hpp>
16#include <string>
17#include <memory>
18
19namespace Belle2 {
27 public:
29 static zmq::message_t createZMQMessage(zmq::message_t message)
30 {
31 return message;
32 }
33
35 static zmq::message_t createZMQMessage(const EMessageTypes& c)
36 {
37 return createZMQMessage(std::string(1, static_cast<char>(c)));
38 }
39
41 static zmq::message_t createZMQMessage(const std::string& s)
42 {
43 return zmq::message_t(s.c_str(), s.length());
44 }
45
47 static zmq::message_t createZMQMessage(const int i)
48 {
49 return createZMQMessage(std::to_string(i));
50 }
51
53 static zmq::message_t createZMQMessage(const StoreObjPtr<EventMetaData>& evtMetaData)
54 {
55 const auto& message = EventMetaDataSerialization::serialize(*evtMetaData);
56 return zmq::message_t(message.c_str(), message.length());
57 }
58
60 static zmq::message_t createZMQMessage(const std::unique_ptr<EvtMessage>& evtMessage)
61 {
62 // TODO: here are the messages copied
63 return zmq::message_t(evtMessage->buffer(), evtMessage->size());
64 }
65
66 };
68}
static std::string serialize(const EventMetaData &eventMetaData)
Serialize the event meta data to a string.
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
Internal helper for creating ZMQ messages (should not be used otherwise).
static zmq::message_t createZMQMessage(const int i)
Create a message out of an int by casting to a string.
static zmq::message_t createZMQMessage(const std::string &s)
Create a message out of a string.
static zmq::message_t createZMQMessage(const std::unique_ptr< EvtMessage > &evtMessage)
Create a message out of an event message.
static zmq::message_t createZMQMessage(const StoreObjPtr< EventMetaData > &evtMetaData)
Create a message out of an event meta data by serialization.
static zmq::message_t createZMQMessage(const EMessageTypes &c)
Create a message out of a type by casting to a char.
static zmq::message_t createZMQMessage(zmq::message_t message)
Just pass a zmq message.
EMessageTypes
Type the messages can have.
Abstract base class for different kinds of events.