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
13// Maximum length of a topic component (group/edge node/device id); longer
14// values are rejected to keep attacker-controlled ids from bloating state.
15inline constexpr size_t kMaxComponentLength = 128;
16
27enum class MessageType {
28 NBIRTH,
29 NDEATH,
30 DBIRTH,
31 DDEATH,
32 NDATA,
33 DDATA,
34 NCMD,
35 DCMD,
36 STATE
37};
38
51struct Topic {
52 std::string group_id;
53 MessageType message_type;
54 std::string edge_node_id;
55 std::string device_id;
56
64 [[nodiscard]] std::string to_string() const;
65
82 [[nodiscard]] static stdx::expected<Topic, std::string>
83 parse(std::string_view topic_str);
84};
85
86} // namespace sparkplug
Represents a parsed Sparkplug B MQTT topic.
Definition topic.hpp:51
std::string device_id
Device identifier (empty for node-level messages)
Definition topic.hpp:55
std::string edge_node_id
Edge node identifier.
Definition topic.hpp:54
std::string group_id
Group ID (topic namespace)
Definition topic.hpp:52
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:53