Astarte device API for C++ 0.7.1
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 <variant>
17
20#include "astarte_device_sdk/property.hpp"
21
22namespace AstarteDeviceSdk {
23
26 public:
33 template <typename T>
34 AstarteMessage(std::string_view interface, std::string_view path, T data)
35 : interface_(interface), path_(path), data_(data) {}
36
41 [[nodiscard]] auto get_interface() const -> const std::string&;
46 [[nodiscard]] auto get_path() const -> const std::string&;
51 [[nodiscard]] auto is_datastream() const -> bool;
56 [[nodiscard]] auto is_individual() const -> bool;
61 template <typename T>
62 [[nodiscard]] auto into() const -> const T& {
63 return std::get<T>(data_);
64 }
65
69 template <typename T>
70 [[nodiscard]] auto try_into() const -> std::optional<T> {
71 if (std::holds_alternative<T>(data_)) {
72 return std::get<T>(data_);
73 }
74
75 return std::nullopt;
76 }
77
81 [[nodiscard]] auto get_raw_data() const
89 [[nodiscard]] auto operator==(const AstarteMessage& other) const -> bool;
95 [[nodiscard]] auto operator!=(const AstarteMessage& other) const -> bool;
96
97 private:
98 std::string interface_;
99 std::string path_;
101 data_;
102};
103
104} // namespace AstarteDeviceSdk
105
106#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
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:62
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.
AstarteMessage(std::string_view interface, std::string_view path, T data)
Constructor for the AstarteMessage class.
Definition msg.hpp:34
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:70
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:22
Astarte object class and its related methods.