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"
54 inline namespace GZ_TRANSPORT_VERSION_NAMESPACE {
102 #pragma warning(push)
103 #pragma warning(disable: 4251)
176 auto msgPtr = std::make_shared<T>();
179 if (!msgPtr->ParseFromString(_data))
181 std::cerr <<
"SubscriptionHandler::CreateMsg() error: ParseFromString"
191 return T().GetTypeName();
208 std::cerr <<
"SubscriptionHandler::RunLocalCallback() error: "
214 if (!this->UpdateThrottling())
217 #if GOOGLE_PROTOBUF_VERSION >= 5028000
218 auto msgPtr = google::protobuf::DynamicCastMessage<T>(&_msg);
219 #elif GOOGLE_PROTOBUF_VERSION >= 4022000
220 auto msgPtr = google::protobuf::internal::DownCast<const T*>(&_msg);
221 #elif GOOGLE_PROTOBUF_VERSION >= 3000000
222 auto msgPtr = google::protobuf::down_cast<const T*>(&_msg);
224 auto msgPtr = google::protobuf::internal::down_cast<const T*>(&_msg);
228 if (msgPtr ==
nullptr)
230 if (_msg.GetDescriptor() !=
nullptr)
232 std::cerr <<
"SubscriptionHandler::RunLocalCallback() error: "
233 <<
"Failed to cast the message of the type "
234 << _msg.GetDescriptor()->full_name()
235 <<
" to the specified type" <<
'\n';
239 std::cerr <<
"SubscriptionHandler::RunLocalCallback() error: "
240 <<
"Failed to cast the message of an unknown type"
241 <<
" to the specified type" <<
'\n';
247 this->cb(*msgPtr, _info);
274 const google::protobuf::Descriptor *desc =
275 google::protobuf::DescriptorPool::generated_pool()
276 ->FindMessageTypeByName(_type);
282 msgPtr.
reset(google::protobuf::MessageFactory::generated_factory()
283 ->GetPrototype(desc)->New());
288 msgPtr = gz::msgs::Factory::New(_type);
295 if (!msgPtr->ParseFromString(_data))
324 std::cerr <<
"SubscriptionHandler::RunLocalCallback() "
325 <<
"error: Callback is NULL" <<
std::endl;
330 if (!this->UpdateThrottling())
333 this->cb(_msg, _info);
377 private:
class Implementation;
382 #pragma warning(push)
383 #pragma warning(disable: 4251)