18 #ifndef GZ_TRANSPORT_SUBSCRIPTIONHANDLER_HH_
19 #define GZ_TRANSPORT_SUBSCRIPTIONHANDLER_HH_
23 #pragma warning(disable: 4251)
25 #include <google/protobuf/message.h>
26 #include <google/protobuf/stubs/common.h>
27 #if GOOGLE_PROTOBUF_VERSION >= 3000000 && GOOGLE_PROTOBUF_VERSION < 4022000
28 #include <google/protobuf/stubs/casts.h>
40 #include <gz/msgs/Factory.hh>
42 #include "gz/transport/config.hh"
43 #include "gz/transport/Export.hh"
52 inline namespace GZ_TRANSPORT_VERSION_NAMESPACE {
100 #pragma warning(push)
101 #pragma warning(disable: 4251)
174 auto msgPtr = std::make_shared<T>();
177 if (!msgPtr->ParseFromString(_data))
179 std::cerr <<
"SubscriptionHandler::CreateMsg() error: ParseFromString"
206 std::cerr <<
"SubscriptionHandler::RunLocalCallback() error: "
212 if (!this->UpdateThrottling())
215 #if GOOGLE_PROTOBUF_VERSION >= 5028000
216 auto msgPtr = google::protobuf::DynamicCastMessage<T>(&_msg);
217 #elif GOOGLE_PROTOBUF_VERSION >= 4022000
218 auto msgPtr = google::protobuf::internal::DownCast<const T*>(&_msg);
219 #elif GOOGLE_PROTOBUF_VERSION >= 3000000
220 auto msgPtr = google::protobuf::down_cast<const T*>(&_msg);
222 auto msgPtr = google::protobuf::internal::down_cast<const T*>(&_msg);
226 if (msgPtr ==
nullptr)
228 if (_msg.GetDescriptor() !=
nullptr)
230 std::cerr <<
"SubscriptionHandler::RunLocalCallback() error: "
231 <<
"Failed to cast the message of the type "
232 << _msg.GetDescriptor()->full_name()
233 <<
" to the specified type" <<
'\n';
237 std::cerr <<
"SubscriptionHandler::RunLocalCallback() error: "
238 <<
"Failed to cast the message of an unknown type"
239 <<
" to the specified type" <<
'\n';
245 this->cb(*msgPtr, _info);
272 const google::protobuf::Descriptor *desc =
273 google::protobuf::DescriptorPool::generated_pool()
274 ->FindMessageTypeByName(_type);
280 msgPtr.
reset(google::protobuf::MessageFactory::generated_factory()
281 ->GetPrototype(desc)->New());
286 msgPtr = gz::msgs::Factory::New(_type);
293 if (!msgPtr->ParseFromString(_data))
322 std::cerr <<
"SubscriptionHandler::RunLocalCallback() "
323 <<
"error: Callback is NULL" <<
std::endl;
328 if (!this->UpdateThrottling())
331 this->cb(_msg, _info);
375 private:
class Implementation;
380 #pragma warning(push)
381 #pragma warning(disable: 4251)