Sparkplug B C++ Library 1.0.0
Modern C++-23 implementation of Eclipse Sparkplug B 2.2 specification
Loading...
Searching...
No Matches
topic.hpp
1// include/sparkplug/topic.hpp
2#pragma once
3
4#include "detail/compat.hpp"
5
6#include <string>
7#include <string_view>
8
9namespace sparkplug {
10
11inline constexpr std::string_view NAMESPACE = "spBv1.0";
12
23enum class MessageType {
24 NBIRTH,
25 NDEATH,
26 DBIRTH,
27 DDEATH,
28 NDATA,
29 DDATA,
30 NCMD,
31 DCMD,
32 STATE
33};
34
47struct Topic {
48 std::string group_id;
49 MessageType message_type;
50 std::string edge_node_id;
51 std::string device_id;
52
60 [[nodiscard]] std::string to_string() const;
61
78 [[nodiscard]] static stdx::expected<Topic, std::string>
79 parse(std::string_view topic_str);
80};
81
82} // namespace sparkplug
Represents a parsed Sparkplug B MQTT topic.
Definition topic.hpp:47
std::string device_id
Device identifier (empty for node-level messages)
Definition topic.hpp:51
std::string edge_node_id
Edge node identifier.
Definition topic.hpp:50
std::string group_id
Group ID (topic namespace)
Definition topic.hpp:48
static stdx::expected< Topic, std::string > parse(std::string_view topic_str)
Parses a Sparkplug B topic string.
std::string to_string() const
Converts the topic back to a string.
MessageType message_type
Message type (NBIRTH, NDATA, etc.)
Definition topic.hpp:49