Astarte device API for C++ 0.8.1
Astarte device SDK for C++
Loading...
Searching...
No Matches
astarte::device::Message Class Reference

Astarte message class, represents a full message for/from Astarte. More...

#include <msg.hpp>

Public Member Functions

template<typename T>
 Message (std::string_view interface, std::string_view path, T data)
 Constructor for the Message class.
 
auto get_interface () const -> const std::string &
 Gets the interface of the message.
 
auto get_path () const -> const std::string &
 Gets the path of the message.
 
auto is_datastream () const -> bool
 Checks if this message contains a datastream.
 
auto is_individual () const -> bool
 Checks if this message contains individual data.
 
template<typename T>
auto into () const -> const T &
 Get the content of the message.
 
template<typename T>
auto try_into () const -> std::optional< T >
 Return the content of the message if it's of the correct type.
 
auto get_raw_data () const -> const std::variant< DatastreamIndividual, DatastreamObject, PropertyIndividual > &
 Returns the raw data contained in this class instance.
 
auto operator== (const Message &other) const -> bool
 Overloader for the comparison operator ==.
 
auto operator!= (const Message &other) const -> bool
 Overloader for the comparison operator !=.
 

Detailed Description

Astarte message class, represents a full message for/from Astarte.

The Message class acts as a unified container for data received from Astarte (via polling). It can hold individual datastreams, aggregated objects, or individual properties.

Constructor & Destructor Documentation

◆ Message()

template<typename T>
astarte::device::Message::Message ( std::string_view interface,
std::string_view path,
T data )
inline

Constructor for the Message class.

Template Parameters
TThe type of the data payload.
Parameters
[in]interfaceThe interface for the message.
[in]pathThe path for the message.
[in]dataThe data for the message.

Member Function Documentation

◆ get_interface()

auto astarte::device::Message::get_interface ( ) const -> const std::string &
nodiscard

Gets the interface of the message.

Returns
A constant reference to the interface name.

◆ get_path()

auto astarte::device::Message::get_path ( ) const -> const std::string &
nodiscard

Gets the path of the message.

Returns
A constant reference to the path.

◆ get_raw_data()

auto astarte::device::Message::get_raw_data ( ) const -> const std::variant< DatastreamIndividual, DatastreamObject, PropertyIndividual > &
nodiscard

Returns the raw data contained in this class instance.

Returns
A constant reference to the internal variant containing the data.

◆ into()

template<typename T>
auto astarte::device::Message::into ( ) const -> const T&
inlinenodiscard

Get the content of the message.

Template Parameters
TThe target type to cast the content to.
Returns
A constant reference to the value contained in the message.

◆ is_datastream()

auto astarte::device::Message::is_datastream ( ) const -> bool
nodiscard

Checks if this message contains a datastream.

Returns
True if the message contains a datastream, false otherwise.

◆ is_individual()

auto astarte::device::Message::is_individual ( ) const -> bool
nodiscard

Checks if this message contains individual data.

Returns
True if the message contains individual data, false otherwise.

◆ operator!=()

auto astarte::device::Message::operator!= ( const Message & other) const -> bool
nodiscard

Overloader for the comparison operator !=.

Parameters
[in]otherThe object to compare to.
Returns
True when different, false otherwise.

◆ operator==()

auto astarte::device::Message::operator== ( const Message & other) const -> bool
nodiscard

Overloader for the comparison operator ==.

Parameters
[in]otherThe object to compare to.
Returns
True when equal, false otherwise.

◆ try_into()

template<typename T>
auto astarte::device::Message::try_into ( ) const -> std::optional<T>
inlinenodiscard

Return the content of the message if it's of the correct type.

Template Parameters
TThe target type to attempt casting to.
Returns
std::optional containing the value if the type matches, or std::nullopt.

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