rad 6.2.0
Loading...
Searching...
No Matches
topicHandler.hpp
Go to the documentation of this file.
1
9#ifndef RAD_TOPIC_HANDLER_HPP
10#define RAD_TOPIC_HANDLER_HPP
11
12#include <rad/exceptions.hpp>
13
14#include <memory>
15#include <string>
16#include <unordered_map>
17
18namespace rad {
19
24 public:
25 virtual ~TopicHandler() {}
33 virtual void Handle(const std::string& topic_type_id, const void* data, size_t data_size) = 0;
34};
35
43template <typename EventType>
44EventType ParseTopicAndCreateEvent(const std::string& topic_name, const void* msg,
45 size_t msg_size) {
46 typename EventType::payload_t topic_payload;
47 if (topic_payload.ParseFromArray(msg, msg_size) == false) {
48 throw rad::Exception("Error parsing <" + topic_name + "> payload.");
49 }
50 return EventType(topic_payload);
51}
52
53} // namespace rad
54
55#endif /* #ifndef RAD_TOPIC_HANDLER_HPP */
Base class for the exceptions thrown by RAD and its users.
Definition exceptions.hpp:53
Definition topicHandler.hpp:23
virtual void Handle(const std::string &topic_type_id, const void *data, size_t data_size)=0
virtual ~TopicHandler()
Definition topicHandler.hpp:25
Exception classes header file.
Definition actionsApp.cpp:23
EventType ParseTopicAndCreateEvent(const std::string &topic_name, const void *msg, size_t msg_size)
Definition topicHandler.hpp:44