Sparkplug B C++ Library 1.0.0
Modern C++-23 implementation of Eclipse Sparkplug B 2.2 specification
Loading...
Searching...
No Matches
sparkplug::Topic Struct Reference

Represents a parsed Sparkplug B MQTT topic. More...

#include <topic.hpp>

Public Member Functions

std::string to_string () const
 Converts the topic back to a string.
 

Static Public Member Functions

static stdx::expected< Topic, std::string > parse (std::string_view topic_str)
 Parses a Sparkplug B topic string.
 

Public Attributes

std::string group_id
 Group ID (topic namespace)
 
MessageType message_type
 Message type (NBIRTH, NDATA, etc.)
 
std::string edge_node_id
 Edge node identifier.
 
std::string device_id
 Device identifier (empty for node-level messages)
 

Detailed Description

Represents a parsed Sparkplug B MQTT topic.

Sparkplug B topics follow the format:

  • spBv1.0/{group_id}/{message_type}/{edge_node_id}[/{device_id}]
  • spBv1.0/STATE/{host_id} (for primary application state)
Example Topics
  • spBv1.0/Energy/NBIRTH/Gateway01 - Node birth
  • spBv1.0/Energy/DBIRTH/Gateway01/Sensor01 - Device birth
  • spBv1.0/STATE/ScadaHost1 - Primary application state

Definition at line 47 of file topic.hpp.

Member Function Documentation

◆ parse()

static stdx::expected< Topic, std::string > sparkplug::Topic::parse ( std::string_view  topic_str)
static

Parses a Sparkplug B topic string.

Parameters
topic_strTopic string to parse
Returns
Parsed Topic on success, error message on failure
Example
auto result = sparkplug::Topic::parse("spBv1.0/Energy/NBIRTH/Gateway01");
if (result) {
const auto& topic = *result;
std::cout << "Group: " << topic.group_id << "\n";
}
static stdx::expected< Topic, std::string > parse(std::string_view topic_str)
Parses a Sparkplug B topic string.

◆ to_string()

std::string sparkplug::Topic::to_string ( ) const

Converts the topic back to a string.

Returns
Formatted topic string (e.g., "spBv1.0/Energy/NBIRTH/Gateway01")
Note
May throw if std::format throws (e.g., out of memory), but this is rare.

Member Data Documentation

◆ device_id

std::string sparkplug::Topic::device_id

Device identifier (empty for node-level messages)

Definition at line 51 of file topic.hpp.

◆ edge_node_id

std::string sparkplug::Topic::edge_node_id

Edge node identifier.

Definition at line 50 of file topic.hpp.

◆ group_id

std::string sparkplug::Topic::group_id

Group ID (topic namespace)

Definition at line 48 of file topic.hpp.

◆ message_type

MessageType sparkplug::Topic::message_type

Message type (NBIRTH, NDATA, etc.)

Definition at line 49 of file topic.hpp.


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