Messages#
constellation::message
Namespace#
-
using constellation::message::AssembledMessage = std::array<std::byte, chirp::CHIRP_MESSAGE_LENGTH>#
CHIRP message assembled to array of bytes
-
class BaseHeader#
- #include <constellation/core/message/BaseHeader.hpp>
Message Header Base Class
Subclassed by constellation::message::CDTP1Message::Header, constellation::message::CMDP1Message::Header, constellation::message::CSCP1Message::Header
Public Functions
-
virtual ~BaseHeader() = default#
-
inline std::string_view getSender() const#
Return message sender
-
inline std::chrono::system_clock::time_point getTime() const#
Return message time
-
inline const config::Dictionary &getTags() const#
Return message tags
-
inline bool hasTag(const std::string &key) const#
Return if message has given tag
-
inline void setTag(const std::string &key, config::Value value)#
Set message tag
-
virtual std::string to_string() const#
Convert message header to human readable string
-
virtual void msgpack_pack(msgpack::packer<msgpack::sbuffer> &msgpack_packer) const#
Pack message header with msgpack
Protected Functions
-
inline BaseHeader(protocol::Protocol protocol, std::string sender, std::chrono::system_clock::time_point time, config::Dictionary tags = {})#
Construct new message header
- Parameters:
protocol – Message protocol
sender – Sender name
time – Message time
tags – Message tags (defaults to empty dictionary)
Protected Static Functions
-
static BaseHeader disassemble(protocol::Protocol protocol, std::span<const std::byte> data)#
Disassemble message from from bytes
- Parameters:
protocol – Protocol
data – View to byte data
-
virtual ~BaseHeader() = default#
-
class CDTP1Message#
- #include <constellation/core/message/CDTP1Message.hpp>
Class representing a CDTP1 message
Public Types
Public Functions
-
CDTP1Message(Header header, std::size_t frames = 1)#
- Parameters:
header – CDTP1 header of the message
frames – Number of payload frames to reserve
-
inline const Header &getHeader() const#
- Returns:
Read-only reference to the CSCP1 header of the message
-
inline const std::vector<message::PayloadBuffer> &getPayload() const#
- Returns:
Read-only reference to the payload of the message
-
inline void addPayload(message::PayloadBuffer &&payload)#
- Parameters:
payload – Payload buffer containing a payload to be added as ZeroMQ message
-
inline std::size_t countPayloadFrames() const#
- Returns:
Current number of payload frames in this message
-
zmq::multipart_t assemble()#
Assemble full message to frames for ZeroMQ
This function always moves the payload
Public Static Functions
-
static CDTP1Message disassemble(zmq::multipart_t &frames)#
Disassemble message from ZeroMQ frames
This function moves the payload frames
-
class Header : public constellation::message::BaseHeader#
Public Functions
-
inline Header(std::string sender, std::uint64_t seq, Type type, std::chrono::system_clock::time_point time = std::chrono::system_clock::now(), config::Dictionary tags = {})#
-
inline std::uint64_t getSequenceNumber() const#
-
virtual std::string to_string() const final#
Convert message header to human readable string
-
virtual void msgpack_pack(msgpack::packer<msgpack::sbuffer> &msgpack_packer) const final#
Pack message header with msgpack
-
inline Header(std::string sender, std::uint64_t seq, Type type, std::chrono::system_clock::time_point time = std::chrono::system_clock::now(), config::Dictionary tags = {})#
-
CDTP1Message(Header header, std::size_t frames = 1)#
-
class CHIRPMessage#
- #include <constellation/core/message/CHIRPMessage.hpp>
CHIRP message
Public Functions
-
CHIRPMessage(chirp::MessageType type, MD5Hash group_id, MD5Hash host_id, chirp::ServiceIdentifier service_id, utils::Port port)#
- Parameters:
type – CHIRP message type
group_id – Constellation group ID (MD5 Hash of group name)
host_id – Constellation host ID (MD5 Hash of host name)
service_id – CHIRP service identifier
port – Service port
-
CHIRPMessage(chirp::MessageType type, std::string_view group, std::string_view host, chirp::ServiceIdentifier service_id, utils::Port port)#
-
inline chirp::MessageType getType() const#
Return the message type
-
inline chirp::ServiceIdentifier getServiceIdentifier() const#
Return the service identifier of the message
-
inline utils::Port getPort() const#
Return the service port of the message
-
AssembledMessage assemble() const#
Assemble message to byte array
Public Static Functions
-
static CHIRPMessage disassemble(std::span<const std::byte> assembled_message)#
Constructor for a CHIRP message from an assembled message
- Parameters:
assembled_message – View of assembled message
- Throws:
DecodeError – If the message header does not match the CHIRP specification, or if the message has an unknown
ServiceIdentifier
-
CHIRPMessage(chirp::MessageType type, MD5Hash group_id, MD5Hash host_id, chirp::ServiceIdentifier service_id, utils::Port port)#
-
class CHP1Message#
- #include <constellation/core/message/CHP1Message.hpp>
Class representing a CHP1 message
Public Functions
-
inline CHP1Message(std::string sender, protocol::CSCP::State state, std::chrono::milliseconds interval, std::chrono::system_clock::time_point time = std::chrono::system_clock::now())#
- Parameters:
sender – Sender name
time – Message time
state – State of the sender
interval – Time interval until next message is expected
-
inline std::string_view getSender() const#
Return message sender
-
inline std::chrono::system_clock::time_point getTime() const#
Return message time
-
inline std::chrono::milliseconds getInterval() const#
Return maxima time interval until next message is expected
-
zmq::multipart_t assemble()#
Assemble full message to frames for ZeroMQ
Public Static Functions
-
static CHP1Message disassemble(zmq::multipart_t &frames)#
Disassemble message from ZeroMQ frames
This function moves the frames
-
inline CHP1Message(std::string sender, protocol::CSCP::State state, std::chrono::milliseconds interval, std::chrono::system_clock::time_point time = std::chrono::system_clock::now())#
-
class CMDP1LogMessage : public constellation::message::CMDP1Message#
Public Functions
-
CMDP1LogMessage(log::Level level, std::string log_topic, Header header, std::string message)#
Construct a new CMDP1 message for logging
- Parameters:
level – Log level of the message
log_topic – Log topic of the message (can be empty)
header – CMDP1 header of the message
message – Log message
-
CMDP1LogMessage(CMDP1Message &&message)#
Construct a CMDP1LogMessage from a decoded CMDP1Message
- Throws:
IncorrectMessageType – If the message is not a (valid) log message
-
inline std::string_view getLogTopic() const#
- Returns:
Log topic of the message (might be empty)
-
std::string_view getLogMessage() const#
- Returns:
Log message
Public Static Functions
-
static CMDP1LogMessage disassemble(zmq::multipart_t &frames)#
Disassemble log message from ZeroMQ frames
This function moves the payload.
- Throws:
MessageDecodingError – If the message is not a valid CMDP1 message
IncorrectMessageType – If the message is a valid CMDP1 message but not a (valid) log message
- Returns:
New CMDP1LogMessage assembled from ZeroMQ frames
-
CMDP1LogMessage(log::Level level, std::string log_topic, Header header, std::string message)#
-
class CMDP1Message#
- #include <constellation/core/message/CMDP1Message.hpp>
Class representing a CMDP1 message
Subclassed by constellation::message::CMDP1LogMessage, constellation::message::CMDP1StatMessage
Public Functions
-
inline const Header &getHeader() const#
- Returns:
Read-only reference to the CMDP1 header of the message
-
inline std::string_view getTopic() const#
- Returns:
CMDP message topic
-
bool isLogMessage() const#
- Returns:
If the message is a log message
-
bool isStatMessage() const#
- Returns:
If the message is a stat message
-
zmq::multipart_t assemble()#
Assemble full message to frames for ZeroMQ
This function moves the payload.
- Returns:
Message assembled to ZeroMQ frames
Public Static Functions
-
static CMDP1Message disassemble(zmq::multipart_t &frames)#
Disassemble message from ZeroMQ frames
This function moves the payload.
- Throws:
MessageDecodingError – If the message is not a valid CMDP1 message
- Returns:
New CMDP1Message assembled from ZeroMQ frames
Protected Functions
-
CMDP1Message(std::string topic, Header header, message::PayloadBuffer &&payload)#
Construct a new CMDP1 message with payload
- Parameters:
topic – Topic of the message
header – Header of the message
payload – Payload of the message
-
inline const message::PayloadBuffer &get_payload() const#
- Returns:
Message payload
Protected Static Functions
-
static log::Level get_log_level_from_topic(std::string_view topic)#
Extract the log level from CMDP1 message topic
- Parameters:
topic – Topic of the message
- Throws:
MessageDecodingError – If not a valid log level
-
class Header : public constellation::message::BaseHeader#
- #include <constellation/core/message/CMDP1Message.hpp>
CMDP1 Header
Public Functions
-
inline Header(std::string sender, std::chrono::system_clock::time_point time = std::chrono::system_clock::now())#
-
inline Header(std::string sender, std::chrono::system_clock::time_point time = std::chrono::system_clock::now())#
-
inline const Header &getHeader() const#
-
class CMDP1StatMessage : public constellation::message::CMDP1Message#
Public Functions
Construct a new CMDP1 message for metrics
Note
The message payload will be create immediately from the current value
- Parameters:
topic – Topic of the statistics metric message
header – CMDP1 header of the message
metric – The metric to be sent
-
CMDP1StatMessage(CMDP1Message &&message)#
Construct a CMDP1StatMessage from a decoded CMDP1Message
- Throws:
IncorrectMessageType – If the message is not a (valid) metrics message
-
inline std::shared_ptr<metrics::Metric> getMetric() const#
- Returns:
Metric value and type
Public Static Functions
-
static CMDP1StatMessage disassemble(zmq::multipart_t &frames)#
Disassemble stats message from ZeroMQ frames
This function moves the payload.
- Throws:
MessageDecodingError – If the message is not a valid CMDP1 message
IncorrectMessageType – If the message is a valid CMDP1 message but not a (valid) stat message
- Returns:
New CMDP1StatMessage assembled from ZeroMQ frames
-
class CSCP1Message#
- #include <constellation/core/message/CSCP1Message.hpp>
Class representing a CSCP1 message
Public Types
-
enum class Type : std::uint8_t#
Enum describing the type of CSCP1 message
Values:
-
enumerator REQUEST#
Request with a command
-
enumerator SUCCESS#
Command is being executed
-
enumerator NOTIMPLEMENTED#
Command is valid but not implemented
-
enumerator INCOMPLETE#
Command is valid but mandatory payload information is missing or incorrectly formatted
-
enumerator INVALID#
Command is invalid for the current state
-
enumerator UNKNOWN#
Command is entirely unknown
-
enumerator ERROR#
Previously received message is invalid
-
enumerator REQUEST#
Public Functions
-
CSCP1Message(Header header, std::pair<Type, std::string> verb)#
- Parameters:
header – CSCP1 header of the message
verb – Message verb containing the type and the command/reply string
-
inline const Header &getHeader() const#
- Returns:
Read-only reference to the CSCP1 header of the message
-
inline std::pair<Type, std::string_view> getVerb() const#
- Returns:
Message verb containing the type and the command/reply string
-
inline const message::PayloadBuffer &getPayload() const#
- Returns:
Message payload
-
inline bool hasPayload() const#
- Returns:
True if message has payload
-
inline void addPayload(message::PayloadBuffer &&payload)#
- Parameters:
payload – Payload buffer containing the payload to be added as ZeroMQ message
-
zmq::multipart_t assemble(bool keep_payload = false)#
Assemble full message to frames for ZeroMQ
- Parameters:
keep_payload – If true, the payload is kept such that the message can be send again
- Returns:
Message assembled to ZeroMQ frames
Public Static Functions
-
static CSCP1Message disassemble(zmq::multipart_t &frames)#
Disassemble message from ZeroMQ frames
This function moves the payload frame if there is one.
- Throws:
TODO –
- Returns:
New CSCP1Message assembled from ZeroMQ frames
-
class Header : public constellation::message::BaseHeader#
- #include <constellation/core/message/CSCP1Message.hpp>
CSCP1 Header
Public Functions
-
inline Header(std::string sender, std::chrono::system_clock::time_point time = std::chrono::system_clock::now(), config::Dictionary tags = {})#
-
inline Header(std::string sender, std::chrono::system_clock::time_point time = std::chrono::system_clock::now(), config::Dictionary tags = {})#
-
enum class Type : std::uint8_t#
-
class IncorrectMessageType : public constellation::utils::RuntimeError#
- #include <constellation/core/message/exceptions.hpp>
Incorrect message type.
The message type does not match the requested operation
Public Functions
-
inline explicit IncorrectMessageType(std::string_view why)#
-
inline explicit IncorrectMessageType(std::string_view why)#
-
class InvalidProtocolError : public constellation::message::MessageDecodingError#
- #include <constellation/core/message/exceptions.hpp>
Invalid protocol identifier.
The message identifier does not represent a valid or known protocol identifier
Public Functions
-
inline explicit InvalidProtocolError(const std::string &protocol)#
-
inline explicit InvalidProtocolError(const std::string &protocol)#
-
class MD5Hash : public std::array<std::uint8_t, 16>#
- #include <constellation/core/message/CHIRPMessage.hpp>
MD5 hash stored as array with 16 bytes
Public Functions
-
constexpr MD5Hash() = default#
-
MD5Hash(std::string_view string)#
Construct MD5 hash from a string
- Parameters:
string – String from which to create the MD5 hash
-
std::string to_string() const#
Convert MD5 hash to an human readable string
- Returns:
String containing a lowercase hex representation of the MD5 hash
-
constexpr MD5Hash() = default#
-
class MessageDecodingError : public constellation::utils::RuntimeError#
- #include <constellation/core/message/exceptions.hpp>
Error in decoding the message.
The message cannot be correctly decoded because the format does not adhere to protocol.
Subclassed by constellation::message::InvalidProtocolError, constellation::message::UnexpectedProtocolError
Public Functions
-
inline explicit MessageDecodingError(const std::string &reason)#
Protected Functions
-
MessageDecodingError() = default#
-
inline explicit MessageDecodingError(const std::string &reason)#
-
class PayloadBuffer#
- #include <constellation/core/message/PayloadBuffer.hpp>
Buffer holding an arbitrary object that can be turned into a
zmq::message_t
This buffer takes ownership of an arbitrary object that owns some memory. The buffer stores the object in an
std::any
and memory range owned by the object in a span. The buffer features manual memory management to allow for zero-copy message transport with ZeroMQ.To make the zero-copy mechanism work, the
std::any
is allocated via new on the heap. This allows to pass a free function to ZeroMQ, which deallocates thestd::any
via delete. However, to avoid that thestd::any
is deleted when the buffer goes out of scope, the buffer has to be released. This simply means that it resets the pointer to thestd::any
such that it does not get deleted in the destructor of the buffer.Public Functions
-
template<typename T, typename F>
inline PayloadBuffer(T &&t, F f)# Construct buffer given by moving an arbitrary object.
Note
If T doesn’t construct nicely to an
std::any
, one possibility is moving it into anstd::shared_ptr
- Parameters:
t – L-Value Reference of object T to move into the buffer
f – Function F that takes a reference of T and returns an
std::span<std::byte>
-
inline PayloadBuffer(zmq::message_t &&msg)#
Specialized constructor for
zmq::message_t
-
inline PayloadBuffer(msgpack::sbuffer &&buf)#
Specialized constructor for
msgpack::sbuffer
-
PayloadBuffer() = default#
Default constructor (empty payload)
-
inline ~PayloadBuffer()#
Destructor deleting the
std::any
-
inline PayloadBuffer(PayloadBuffer &&other) noexcept#
Move constructor taking over other pointer and releasing other buffer.
-
inline PayloadBuffer &operator=(PayloadBuffer &&other) noexcept#
Move assignment freeing the buffer, taking over other pointer and releasing other buffer.
-
inline std::span<const std::byte> span() const#
Read-only access to the data in the buffer.
- Returns:
Constant span of the data
-
inline std::span<std::byte> span()#
Write access to the data in the buffer.
- Returns:
Non-constant span of the data
-
inline bool empty() const#
Check if the payload is empty.
- Returns:
If the span is empty
-
inline std::string_view to_string_view() const#
Interpret data as string.
Note
This function does not ensure that the data in the buffer is actually a string
- Returns:
String of the content in the buffer
-
inline zmq::message_t to_zmq_msg_copy() const#
Create a ZeroMQ message by copying the buffer.
- Returns:
ZeroMQ message with a copy of the data in the buffer
-
inline zmq::message_t to_zmq_msg_release()#
Create a ZeroMQ message for zero-copy transport.
Note
The buffer will be released after this function, meaning that the buffer cannot be used anymore
- Returns:
ZeroMQ message owning the data in the buffer
-
template<typename T, typename F>
-
class UnexpectedProtocolError : public constellation::message::MessageDecodingError#
- #include <constellation/core/message/exceptions.hpp>
Unexpected protocol identifier.
The protocol identifier of the message does not match the expected protocol