5#ifndef ASTARTE_DEVICE_SDK_MSG_H
6#define ASTARTE_DEVICE_SDK_MSG_H
48 Message(std::string_view interface, std::string_view path, T data)
49 : interface_(interface), path_(path), data_(std::move(data)) {}
63 [[nodiscard]] auto
get_path() const -> const std::
string&;
86 [[nodiscard]] auto
into() const -> const T& {
87 return std::get<T>(data_);
97 [[nodiscard]]
auto try_into() const -> std::optional<T> {
98 if (std::holds_alternative<T>(data_)) {
99 return std::get<T>(data_);
119 [[nodiscard]] auto operator==(const
Message& other) const ->
bool;
127 [[nodiscard]] auto operator!=(const
Message& other) const ->
bool;
130 std::
string interface_;
146 template <
typename ParseContext>
147 constexpr auto parse(ParseContext& ctx)
const {
158 template <
typename FormatContext>
160 auto out = ctx.out();
162 out = astarte_fmt::format_to(out,
"{{interface: {}, path: {}", msg.
get_interface(),
166 bool is_unset_prop =
false;
167 const auto* prop = std::get_if<astarte::device::PropertyIndividual>(&msg.
get_raw_data());
168 if (prop && !prop->get_value().has_value()) {
169 is_unset_prop =
true;
172 if (!is_unset_prop) {
173 out = astarte_fmt::format_to(out,
", value: ");
174 std::visit([&out](
const auto& arg) { out = astarte_fmt::format_to(out,
"{}", arg); },
178 return astarte_fmt::format_to(out,
"}}");
190 out << astarte_fmt::format(
"{}", msg);
Represents the Astarte individual datastream data.
Definition individual.hpp:29
Astarte object class, representing the Astarte object datastream data.
Definition object.hpp:33
Astarte message class, represents a full message for/from Astarte.
Definition msg.hpp:37
auto is_individual() const -> bool
Checks if this message contains individual data.
auto get_interface() const -> const std::string &
Gets the interface of the message.
auto into() const -> const T &
Get the content of the message.
Definition msg.hpp:86
auto try_into() const -> std::optional< T >
Return the content of the message if it's of the correct type.
Definition msg.hpp:97
auto get_raw_data() const -> const std::variant< DatastreamIndividual, DatastreamObject, PropertyIndividual > &
Returns the raw data contained in this class instance.
auto is_datastream() const -> bool
Checks if this message contains a datastream.
auto get_path() const -> const std::string &
Gets the path of the message.
Message(std::string_view interface, std::string_view path, T data)
Constructor for the Message class.
Definition msg.hpp:48
Representing the Astarte individual property data.
Definition property.hpp:22
auto operator<<(std::ostream &out, const astarte::device::Data &data) -> std::ostream &
Stream insertion operator for Data.
Definition data.hpp:243
Astarte individual datastream class and its related methods.
Umbrella namespace for the Astarte device library.
Definition data.hpp:29
Namespace alias for the formatting library (std or fmt).
Definition formatter.hpp:45
Global namespace for all Astarte related functionality.
Definition data.hpp:29
Astarte object class and its related methods.
Astarte individual property class and its related methods.