Belle II Software development
ZMQIdMessage Class Reference

A message with the socket ID. Needed in input<->worker communication. More...

#include <ZMQIdMessage.h>

Inheritance diagram for ZMQIdMessage:
ZMQModuleMessage< 4 >

Public Types

using MessageParts = std::array< zmq::message_t, ZMQModuleMessage::c_messageParts >
 The base class of the message parts.
 

Public Member Functions

bool isMessage (const EMessageTypes isType) const
 The if the message is of a given type.
 
std::string getIdentity () const
 Get the identity part.
 
zmq::message_t & getDataMessage ()
 Get the data part.
 
zmq::message_t & getAdditionalDataMessage ()
 Get the additional data part.
 
MessagePartsgetMessageParts ()
 Get a reference to the message parts.
 
const MessagePartsgetMessageParts () const
 Get a const reference to the message parts.
 
const zmq::message_t & getMessagePart () const
 Get the message part with the given index (const version)
 
zmq::message_t & getMessagePart ()
 Get the message part with the given index.
 
const char * getMessagePartAsCharArray () const
 Get the message part with the given index as char* (const version)
 
char * getMessagePartAsCharArray ()
 Get the message part with the given index as char*.
 
std::string getMessagePartAsString () const
 Get the message part with the given index as string (const version)
 

Static Public Member Functions

static void toSocket (std::unique_ptr< ZMQModuleMessage > message, const std::unique_ptr< zmq::socket_t > &socket)
 Send the message to the given socket. As the message is nullified, you have to move it in here.
 

Static Public Attributes

static constexpr const unsigned int c_identity = 0
 Where the identity is stored.
 
static constexpr const unsigned int c_type = 1
 Where the type of the message is stored.
 
static constexpr const unsigned int c_data = 2
 Where the data is stored.
 
static constexpr const unsigned int c_additionalData = 3
 Where the additional data is stored.
 
static constexpr unsigned int c_messageParts
 The number of message parts this message carries.
 

Private Member Functions

 ZMQModuleMessage (const ZMQModuleMessage &)=delete
 Copy the constructor from the base class.
 
 ZMQModuleMessage ()=default
 Copy the constructor from the base class.
 
template<class ... T>
 ZMQModuleMessage (T &&... arguments)
 Copy the constructor from the base class.
 

Private Attributes

MessageParts m_messageParts
 The content of this message as an array of zmq messages. Will be set during constructor or when coming from a socket.
 

Friends

class ZMQMessageFactory
 

Detailed Description

A message with the socket ID. Needed in input<->worker communication.

Definition at line 21 of file ZMQIdMessage.h.

Member Typedef Documentation

◆ MessageParts

using MessageParts = std::array<zmq::message_t, ZMQModuleMessage::c_messageParts>
inherited

The base class of the message parts.

Definition at line 32 of file ZMQModuleMessage.h.

Member Function Documentation

◆ getAdditionalDataMessage()

zmq::message_t & getAdditionalDataMessage ( )
inline

Get the additional data part.

Definition at line 54 of file ZMQIdMessage.h.

55 {
56 return getMessagePart<c_additionalData>();
57 }

◆ getDataMessage()

zmq::message_t & getDataMessage ( )
inline

Get the data part.

Definition at line 48 of file ZMQIdMessage.h.

49 {
50 return getMessagePart<c_data>();
51 }

◆ getIdentity()

std::string getIdentity ( ) const
inline

Get the identity part.

Definition at line 42 of file ZMQIdMessage.h.

43 {
44 return getMessagePartAsString<c_identity>();
45 }

◆ getMessagePart() [1/2]

zmq::message_t & getMessagePart ( )
inlineinherited

Get the message part with the given index.

Definition at line 85 of file ZMQModuleMessage.h.

86 {
87 return m_messageParts[index];
88 }
MessageParts m_messageParts
The content of this message as an array of zmq messages. Will be set during constructor or when comin...

◆ getMessagePart() [2/2]

const zmq::message_t & getMessagePart ( ) const
inlineinherited

Get the message part with the given index (const version)

Definition at line 62 of file ZMQModuleMessage.h.

63 {
64 return m_messageParts[index];
65 }

◆ getMessagePartAsCharArray() [1/2]

char * getMessagePartAsCharArray ( )
inlineinherited

Get the message part with the given index as char*.

Definition at line 92 of file ZMQModuleMessage.h.

93 {
94 auto& messagePart = getMessagePart<index>();
95 return static_cast<char*>(messagePart.data());
96 }

◆ getMessagePartAsCharArray() [2/2]

const char * getMessagePartAsCharArray ( ) const
inlineinherited

Get the message part with the given index as char* (const version)

Definition at line 69 of file ZMQModuleMessage.h.

70 {
71 const auto& messagePart = getMessagePart<index>();
72 return static_cast<const char*>(messagePart.data());
73 }

◆ getMessagePartAsString()

std::string getMessagePartAsString ( ) const
inlineinherited

Get the message part with the given index as string (const version)

Definition at line 77 of file ZMQModuleMessage.h.

78 {
79 const auto& messagePart = getMessagePart<index>();
80 return std::string(static_cast<const char*>(messagePart.data()), messagePart.size());
81 }

◆ getMessageParts() [1/2]

MessageParts & getMessageParts ( )
inlineinherited

Get a reference to the message parts.

Definition at line 49 of file ZMQModuleMessage.h.

50 {
51 return m_messageParts;
52 };

◆ getMessageParts() [2/2]

const MessageParts & getMessageParts ( ) const
inlineinherited

Get a const reference to the message parts.

Definition at line 55 of file ZMQModuleMessage.h.

56 {
57 return m_messageParts;
58 };

◆ isMessage()

bool isMessage ( const EMessageTypes  isType) const
inline

The if the message is of a given type.

Definition at line 35 of file ZMQIdMessage.h.

36 {
37 const auto& type = getMessagePartAsString<c_type>();
38 return type.size() == 1 and type[0] == static_cast<char>(isType);
39 }

◆ toSocket()

static void toSocket ( std::unique_ptr< ZMQModuleMessage< 4 > >  message,
const std::unique_ptr< zmq::socket_t > &  socket 
)
inlinestaticinherited

Send the message to the given socket. As the message is nullified, you have to move it in here.

Definition at line 35 of file ZMQModuleMessage.h.

36 {
37 for (unsigned int i = 0; i < c_messageParts - 1; i++) {
38 socket->send(message->m_messageParts[i], zmq::send_flags::sndmore);
39 }
40 socket->send(message->m_messageParts[c_messageParts - 1], zmq::send_flags::none);
41 }
static constexpr unsigned int c_messageParts
The number of message parts this message carries.

◆ ZMQModuleMessage()

ZMQModuleMessage ( T &&...  arguments)
inlineexplicitprivate

Copy the constructor from the base class.

Definition at line 104 of file ZMQModuleMessage.h.

104 :
105 m_messageParts({ZMQMessageHelper::createZMQMessage(std::forward<T>(arguments)) ... })
106 {
107 }
static zmq::message_t createZMQMessage(zmq::message_t message)
Just pass a zmq message.

Friends And Related Function Documentation

◆ ZMQMessageFactory

friend class ZMQMessageFactory
friend

Definition at line 22 of file ZMQIdMessage.h.

Member Data Documentation

◆ c_additionalData

constexpr const unsigned int c_additionalData = 3
staticconstexpr

Where the additional data is stored.

Definition at line 32 of file ZMQIdMessage.h.

◆ c_data

constexpr const unsigned int c_data = 2
staticconstexpr

Where the data is stored.

Definition at line 30 of file ZMQIdMessage.h.

◆ c_identity

constexpr const unsigned int c_identity = 0
staticconstexpr

Where the identity is stored.

Definition at line 26 of file ZMQIdMessage.h.

◆ c_messageParts

constexpr unsigned int c_messageParts
staticconstexprinherited

The number of message parts this message carries.

Definition at line 29 of file ZMQModuleMessage.h.

◆ c_type

constexpr const unsigned int c_type = 1
staticconstexpr

Where the type of the message is stored.

Definition at line 28 of file ZMQIdMessage.h.

◆ m_messageParts

MessageParts m_messageParts
privateinherited

The content of this message as an array of zmq messages. Will be set during constructor or when coming from a socket.

Definition at line 111 of file ZMQModuleMessage.h.


The documentation for this class was generated from the following file: