18 #ifndef GZ_TRANSPORT_REPHANDLER_HH_
19 #define GZ_TRANSPORT_REPHANDLER_HH_
23 #pragma warning(disable: 4251)
25 #include <google/protobuf/message.h>
26 #include <google/protobuf/stubs/common.h>
27 #if GOOGLE_PROTOBUF_VERSION > 2999999 && GOOGLE_PROTOBUF_VERSION < 4022000
28 #include <google/protobuf/stubs/casts.h>
39 #include "gz/transport/config.hh"
40 #include "gz/transport/Export.hh"
47 inline namespace GZ_TRANSPORT_VERSION_NAMESPACE {
55 : hUuid(
Uuid().ToString())
97 #pragma warning(disable: 4251)
137 std::cerr <<
"RepHandler::RunLocalCallback() error: "
142 #if GOOGLE_PROTOBUF_VERSION >= 5028000
144 google::protobuf::DynamicCastMessage<Req>(&_msgReq);
146 google::protobuf::DynamicCastMessage<Rep>(&_msgRep);
147 #elif GOOGLE_PROTOBUF_VERSION >= 4022000
149 google::protobuf::internal::DownCast<const Req*>(&_msgReq);
150 auto msgRep = google::protobuf::internal::DownCast<Rep*>(&_msgRep);
151 #elif GOOGLE_PROTOBUF_VERSION > 2999999
152 auto msgReq = google::protobuf::down_cast<const Req*>(&_msgReq);
153 auto msgRep = google::protobuf::down_cast<Rep*>(&_msgRep);
156 google::protobuf::internal::down_cast<const Req*>(&_msgReq);
157 auto msgRep = google::protobuf::internal::down_cast<Rep*>(&_msgRep);
161 if (msgReq ==
nullptr || msgRep ==
nullptr)
163 if (msgReq ==
nullptr)
165 if (_msgReq.GetDescriptor() !=
nullptr)
167 std::cerr <<
"RepHandler::RunLocalCallback() error: "
168 <<
"Failed to cast the request of the type "
169 << _msgReq.GetDescriptor()->full_name()
170 <<
" to the specified type" <<
'\n';
174 std::cerr <<
"RepHandler::RunLocalCallback() error: "
175 <<
"Failed to cast the request of an unknown type"
176 <<
" to the specified type" <<
'\n';
179 if (msgRep ==
nullptr)
181 if (_msgRep.GetDescriptor() !=
nullptr)
183 std::cerr <<
"RepHandler::RunLocalCallback() error: "
184 <<
"Failed to cast the response of the type "
185 << _msgRep.GetDescriptor()->full_name()
186 <<
" to the specified type" <<
'\n';
190 std::cerr <<
"RepHandler::RunLocalCallback() error: "
191 <<
"Failed to cast the response of an unknown type"
192 <<
" to the specified type" <<
'\n';
199 return this->cb(*msgReq, *msgRep);
209 std::cerr <<
"RepHandler::RunCallback() error: "
215 auto msgReq = this->CreateMsg(_req);
222 if (!this->cb(*msgReq, msgRep))
225 if (!msgRep.SerializeToString(&_rep))
227 std::cerr <<
"RepHandler::RunCallback(): Error serializing the "
253 auto msgPtr = std::make_shared<Req>();
256 if (!msgPtr->ParseFromString(_data))
258 std::cerr <<
"RepHandler::CreateMsg() error: ParseFromString failed"