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 >= 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);
225 this->cb(*msgPtr, _info);
252 const google::protobuf::Descriptor *desc =
253 google::protobuf::DescriptorPool::generated_pool()
254 ->FindMessageTypeByName(_type);
260 msgPtr.
reset(google::protobuf::MessageFactory::generated_factory()
261 ->GetPrototype(desc)->New());
266 msgPtr = gz::msgs::Factory::New(_type);
273 if (!msgPtr->ParseFromString(_data))
302 std::cerr <<
"SubscriptionHandler::RunLocalCallback() "
303 <<
"error: Callback is NULL" <<
std::endl;
308 if (!this->UpdateThrottling())
311 this->cb(_msg, _info);
355 private:
class Implementation;
360 #pragma warning(push)
361 #pragma warning(disable: 4251)