26 #include "google/protobuf/message.h"
28 #include "nrp_protobuf/engine_grpc.pb.h"
29 #include "nrp_protobuf/nrp_server.pb.h"
33 namespace gpb = google::protobuf;
46 template<
class MSG_TYPE,
class ...REMAINING_MSG_TYPES>
50 if(from.Is<MSG_TYPE>())
52 MSG_TYPE * dataPack =
new MSG_TYPE();
53 from.UnpackTo(dataPack);
54 return std::unique_ptr<gpb::Message>(dataPack);
58 if constexpr (
sizeof...(REMAINING_MSG_TYPES) > 0)
61 return std::unique_ptr<gpb::Message>();
72 template<
class MSG_TYPE,
class ...REMAINING_MSG_TYPES>
80 const auto& message =
dynamic_cast<const MSG_TYPE &
>(from);
81 to->mutable_data()->PackFrom(message);
84 catch(
const std::bad_cast& e)
92 if constexpr (
sizeof...(REMAINING_MSG_TYPES) > 0)
96 const auto errorMessage =
"Unable to pack data into DataPack '" +
97 to->datapackid().datapackname() +
99 to->datapackid().enginename() +
"'";
115 template<
class MSG_TYPE,
class ...REMAINING_MSG_TYPES>
119 const auto & dataPackId = from.datapackid();
123 engineName, dataPackId.datapacktype()));
124 else if(from.data().Is<MSG_TYPE>())
126 MSG_TYPE * data =
new MSG_TYPE();
127 from.data().UnpackTo(data);
133 if constexpr (
sizeof...(REMAINING_MSG_TYPES) > 0)
148 template<
class MSG_TYPE,
class ...REMAINING_MSG_TYPES>
155 to->mutable_datapackid()->set_datapackname(message.name());
156 to->mutable_datapackid()->set_datapacktype(message.type());
157 to->mutable_datapackid()->set_enginename(message.engineName());
158 to->mutable_data()->PackFrom(message.getData());
162 catch(
const std::bad_cast& e)
170 if constexpr (
sizeof...(REMAINING_MSG_TYPES) > 0)
173 throw NRPException(
"Failed to set DataPackMessage from DataPackInterface with name \"" + from.
name() +
"\"");
185 template<
class MSG_TYPE,
class ...REMAINING_MSG_TYPES>
191 to->mutable_data()->PackFrom(message.getData());
194 catch(
const std::bad_cast& e)
201 if constexpr (
sizeof...(REMAINING_MSG_TYPES) > 0)
212 virtual std::unique_ptr<gpb::Message>
unpackProtoAny(
const gpb::Any &from) = 0;
226 template<
class ...MSG_TYPES>
253 #define CREATE_PROTOBUF_OPS_FCN_STR "CreateNRPProtobufOps"
258 #define CREATE_PROTOBUF_OPS(proto_ops_class) \
259 extern "C" protobuf_ops::NRPProtobufOpsIface *CreateNRPProtobufOps (); \
260 protobuf_ops::NRPProtobufOpsIface *CreateNRPProtobufOps () { \
261 return new proto_ops_class(); \
264 #endif // PROTO_OPS_H