MCPcopy Create free account
hub / github.com/apache/mesos / createPythonProtobuf

Function createPythonProtobuf

src/python/native_common/common.hpp:105–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103 */
104template <typename T>
105PyObject* createPythonProtobuf(const T& t, const char* typeName)
106{
107 PyObject* dict = PyModule_GetDict(mesos_pb2);
108 if (dict == nullptr) {
109 PyErr_Format(PyExc_Exception, "PyModule_GetDict failed");
110 return nullptr;
111 }
112
113 PyObject* type = PyDict_GetItemString(dict, typeName);
114 if (type == nullptr) {
115 PyErr_Format(PyExc_Exception, "Could not resolve mesos_pb2.%s", typeName);
116 return nullptr;
117 }
118 if (!PyType_Check(type)) {
119 PyErr_Format(PyExc_Exception, "mesos_pb2.%s is not a type", typeName);
120 return nullptr;
121 }
122
123 std::string str;
124 if (!t.SerializeToString(&str)) {
125 PyErr_Format(PyExc_Exception, "C++ %s SerializeToString failed", typeName);
126 return nullptr;
127 }
128
129 // Propagates any exception that might happen in FromString.
130 return PyObject_CallMethod(type,
131 (char*) "FromString",
132 (char*) "s#",
133 str.data(),
134 str.size());
135}
136
137
138// construct<T>() should take PyObject* as an argument, try to convert that

Callers 12

registeredMethod · 0.85
reregisteredMethod · 0.85
resourceOffersMethod · 0.85
offerRescindedMethod · 0.85
statusUpdateMethod · 0.85
frameworkMessageMethod · 0.85
slaveLostMethod · 0.85
executorLostMethod · 0.85
registeredMethod · 0.85
reregisteredMethod · 0.85
launchTaskMethod · 0.85
killTaskMethod · 0.85

Calls 2

dataMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected