Astarte device API for C++ 0.6.2
Astarte device SDK for C++
Loading...
Searching...
No Matches
msg.hpp
Go to the documentation of this file.
1// (C) Copyright 2025, SECO Mind Srl
2//
3// SPDX-License-Identifier: Apache-2.0
4
5#ifndef ASTARTE_DEVICE_SDK_MSG_H
6#define ASTARTE_DEVICE_SDK_MSG_H
7
12
13#include <optional>
14#include <string>
15#include <string_view>
16#include <utility>
17#include <variant>
18
21#include "astarte_device_sdk/property.hpp"
22
23namespace AstarteDeviceSdk {
24
27 public:
34 template <typename T>
35 AstarteMessage(std::string_view interface, std::string path, T data)
36 : interface_(interface), path_(std::move(path)), data_(data) {}
37
42 [[nodiscard]] auto get_interface() const -> const std::string&;
47 [[nodiscard]] auto get_path() const -> const std::string&;
52 [[nodiscard]] auto is_datastream() const -> bool;
57 [[nodiscard]] auto is_individual() const -> bool;
62 template <typename T>
63 [[nodiscard]] auto into() const -> const T& {
64 return std::get<T>(data_);
65 }
66
70 template <typename T>
71 [[nodiscard]] auto try_into() const -> std::optional<T> {
72 if (std::holds_alternative<T>(data_)) {
73 return std::get<T>(data_);
74 }
75
76 return std::nullopt;
77 }
78
82 [[nodiscard]] auto get_raw_data() const
90 [[nodiscard]] auto operator==(const AstarteMessage& other) const -> bool;
96 [[nodiscard]] auto operator!=(const AstarteMessage& other) const -> bool;
97
98 private:
99 std::string interface_;
100 std::string path_;
102 data_;
103};
104
105} // namespace AstarteDeviceSdk
106
107#endif // ASTARTE_DEVICE_SDK_MSG_H
Representing the Astarte individual datastream data.
Definition individual.hpp:18
Astarte object class, representing the Astarte object datastream data.
Definition object.hpp:22
AstarteMessage(std::string_view interface, std::string path, T data)
Constructor for the AstarteMessage class.
Definition msg.hpp:35
auto get_raw_data() const -> const std::variant< AstarteDatastreamIndividual, AstarteDatastreamObject, AstartePropertyIndividual > &
Return the raw data contained in this class instance.
auto is_datastream() const -> bool
Check if this message contains a datastream.
auto into() const -> const T &
Get the content of the message.
Definition msg.hpp:63
auto is_individual() const -> bool
Check if this message contains individual data.
auto get_path() const -> const std::string &
Get the path of the message.
auto get_interface() const -> const std::string &
Get the interface of the message.
auto try_into() const -> std::optional< T >
Return the content of the message if it's of the correct type.
Definition msg.hpp:71
Representing the Astarte individual datastream data.
Definition property.hpp:20
Astarte individual datastream class and its related methods.
Umbrella namespace for the Astarte device SDK.
Definition data.hpp:25
Astarte object class and its related methods.