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"
49 inline namespace GZ_TRANSPORT_VERSION_NAMESPACE {
57 : hUuid(
Uuid().ToString())
99 #pragma warning(disable: 4251)
139 std::cerr <<
"RepHandler::RunLocalCallback() error: "
144 #if GOOGLE_PROTOBUF_VERSION >= 5028000
146 google::protobuf::DynamicCastMessage<Req>(&_msgReq);
148 google::protobuf::DynamicCastMessage<Rep>(&_msgRep);
149 #elif GOOGLE_PROTOBUF_VERSION >= 4022000
151 google::protobuf::internal::DownCast<const Req*>(&_msgReq);
152 auto msgRep = google::protobuf::internal::DownCast<Rep*>(&_msgRep);
153 #elif GOOGLE_PROTOBUF_VERSION > 2999999
154 auto msgReq = google::protobuf::down_cast<const Req*>(&_msgReq);
155 auto msgRep = google::protobuf::down_cast<Rep*>(&_msgRep);
158 google::protobuf::internal::down_cast<const Req*>(&_msgReq);
159 auto msgRep = google::protobuf::internal::down_cast<Rep*>(&_msgRep);
163 if (msgReq ==
nullptr || msgRep ==
nullptr)
165 if (msgReq ==
nullptr)
167 if (_msgReq.GetDescriptor() !=
nullptr)
169 std::cerr <<
"RepHandler::RunLocalCallback() error: "
170 <<
"Failed to cast the request of the type "
171 << _msgReq.GetDescriptor()->full_name()
172 <<
" to the specified type" <<
'\n';
176 std::cerr <<
"RepHandler::RunLocalCallback() error: "
177 <<
"Failed to cast the request of an unknown type"
178 <<
" to the specified type" <<
'\n';
181 if (msgRep ==
nullptr)
183 if (_msgRep.GetDescriptor() !=
nullptr)
185 std::cerr <<
"RepHandler::RunLocalCallback() error: "
186 <<
"Failed to cast the response of the type "
187 << _msgRep.GetDescriptor()->full_name()
188 <<
" to the specified type" <<
'\n';
192 std::cerr <<
"RepHandler::RunLocalCallback() error: "
193 <<
"Failed to cast the response of an unknown type"
194 <<
" to the specified type" <<
'\n';
201 return this->cb(*msgReq, *msgRep);
211 std::cerr <<
"RepHandler::RunCallback() error: "
217 auto msgReq = this->CreateMsg(_req);
224 if (!this->cb(*msgReq, msgRep))
227 if (!msgRep.SerializeToString(&_rep))
229 std::cerr <<
"RepHandler::RunCallback(): Error serializing the "
240 return Req().GetTypeName();
246 return Rep().GetTypeName();
258 if (!msgPtr->ParseFromString(_data))
260 std::cerr <<
"RepHandler::CreateMsg() error: ParseFromString failed"