Go to the documentation of this file.
22 #ifndef PROTO_FIELD_OPS_H
23 #define PROTO_FIELD_OPS_H
25 #include "google/protobuf/message.h"
26 #include <boost/python.hpp>
29 namespace bpy = boost::python;
30 namespace gpb = google::protobuf;
41 bpy::object
GetScalarField(gpb::Message &m,
const gpb::FieldDescriptor *field);
56 template<
class MSG,
class ...REMAINING_MSGS>
58 static_assert(std::is_base_of_v<google::protobuf::Message, MSG>,
"Parameter MSG must derive from protobuf::Message");
59 static_assert((std::is_base_of_v<google::protobuf::Message, REMAINING_MSGS> && ...),
"Parameter REMAINING_MSGS must derive from protobuf::Message");
61 MSG *msg_field =
dynamic_cast<MSG *
>(m.GetReflection()->MutableMessage(&m, field));
62 if(msg_field !=
nullptr) {
64 return bpy::object(bpy::handle<>(convert(msg_field)));
67 if constexpr (
sizeof...(REMAINING_MSGS) > 0)
76 void SetScalarField(gpb::Message &m,
const gpb::FieldDescriptor *field,
const bpy::object &value);
81 void SetRepeatedScalarField(gpb::Message &m,
const gpb::FieldDescriptor *field,
const bpy::object &value,
int index);
90 #endif // PROTO_FIELD_OPS_H
std::string GetScalarFieldAsString(const gpb::Message &m, const gpb::FieldDescriptor *field)
Get scalar field value as a string.
Definition: proto_field_ops.cpp:68
void SetScalarField(gpb::Message &m, const gpb::FieldDescriptor *field, const bpy::object &value)
Set scalar field.
Definition: proto_field_ops.cpp:142
type
Definition: python_grpc_engine.py:63
Implement single field Get/Set operations using field descriptor and reflection interface.
Definition: proto_field_ops.cpp:25
bpy::object GetScalarField(gpb::Message &m, const gpb::FieldDescriptor *field)
Get scalar field. Returns a copy of the field value.
Definition: proto_field_ops.cpp:27
void SetRepeatedScalarField(gpb::Message &m, const gpb::FieldDescriptor *field, const bpy::object &value, int index)
Set repeated scalar field.
Definition: proto_field_ops.cpp:177
static EXCEPTION logCreate(LOG_EXCEPTION_T &exception, const std::string &msg, NRPLogger::spdlog_out_fcn_t spdlogCall=NRPLogger::critical)
Definition: nrp_exceptions.h:73
bpy::object GetRepeatedScalarField(gpb::Message &m, const gpb::FieldDescriptor *field, int index)
Get repeated scalar field. Returns a copy of the field value.
Definition: proto_field_ops.cpp:104
void AddRepeatedScalarField(gpb::Message &m, const gpb::FieldDescriptor *field, const bpy::object &value)
Append repeated scalar field.
Definition: proto_field_ops.cpp:211
bpy::object GetMessageField(gpb::Message &m, const gpb::FieldDescriptor *field)
Get message field. Returns a reference of the field value.
Definition: proto_field_ops.h:57