@@ -32,23 +32,37 @@ PythonMessage::~PythonMessage()
3232
3333std::string Arcus::PythonMessage::getTypeName () const
3434{
35- return _message->GetTypeName ();
35+ return std::string ( _message->GetTypeName () );
3636}
3737
3838MessagePtr Arcus::PythonMessage::getSharedMessage () const
3939{
4040 return _shared_message;
4141}
4242
43+ // Instead of `_descriptor->FindFieldByName(field_name)`.
44+ const google::protobuf::FieldDescriptor* findFieldByNameHack (const google::protobuf::Descriptor* _descriptor, const std::string_view field_name)
45+ {
46+ for (int ii = 0 ; ii < _descriptor->field_count (); ++ii)
47+ {
48+ auto candidate = _descriptor->field (ii);
49+ if (field_name.compare (candidate->name ()) == 0 )
50+ {
51+ return candidate;
52+ }
53+ }
54+ return nullptr ;
55+ }
56+
4357bool Arcus::PythonMessage::__hasattr__ (const std::string& field_name) const
4458{
45- auto field = _descriptor-> FindFieldByName ( field_name);
59+ auto field = findFieldByNameHack (_descriptor, field_name);
4660 return bool (field);
4761}
4862
4963PyObject* Arcus::PythonMessage::__getattr__ (const std::string& field_name) const
5064{
51- auto field = _descriptor-> FindFieldByName ( field_name);
65+ auto field = findFieldByNameHack (_descriptor, field_name);
5266 if (! field)
5367 {
5468 PyErr_SetString (PyExc_AttributeError, field_name.c_str ());
@@ -101,7 +115,7 @@ PyObject* Arcus::PythonMessage::__getattr__(const std::string& field_name) const
101115
102116void Arcus::PythonMessage::__setattr__ (const std::string& field_name, PyObject* value)
103117{
104- auto field = _descriptor-> FindFieldByName ( field_name);
118+ auto field = findFieldByNameHack (_descriptor, field_name);
105119 if (! field)
106120 {
107121 PyErr_SetString (PyExc_AttributeError, field_name.c_str ());
@@ -177,7 +191,7 @@ void Arcus::PythonMessage::__setattr__(const std::string& field_name, PyObject*
177191
178192PythonMessage* Arcus::PythonMessage::addRepeatedMessage (const std::string& field_name)
179193{
180- auto field = _descriptor-> FindFieldByName ( field_name);
194+ auto field = findFieldByNameHack (_descriptor, field_name);
181195 if (! field)
182196 {
183197 PyErr_SetString (PyExc_AttributeError, field_name.c_str ());
@@ -190,7 +204,7 @@ PythonMessage* Arcus::PythonMessage::addRepeatedMessage(const std::string& field
190204
191205int PythonMessage::repeatedMessageCount (const std::string& field_name) const
192206{
193- auto field = _descriptor-> FindFieldByName ( field_name);
207+ auto field = findFieldByNameHack (_descriptor, field_name);
194208 if (! field)
195209 {
196210 PyErr_SetString (PyExc_AttributeError, field_name.c_str ());
@@ -202,7 +216,7 @@ int PythonMessage::repeatedMessageCount(const std::string& field_name) const
202216
203217PythonMessage* Arcus::PythonMessage::getMessage (const std::string& field_name)
204218{
205- auto field = _descriptor-> FindFieldByName ( field_name);
219+ auto field = findFieldByNameHack (_descriptor, field_name);
206220 if (! field)
207221 {
208222 PyErr_SetString (PyExc_AttributeError, field_name.c_str ());
@@ -213,7 +227,7 @@ PythonMessage* Arcus::PythonMessage::getMessage(const std::string& field_name)
213227
214228PythonMessage* Arcus::PythonMessage::getRepeatedMessage (const std::string& field_name, int index)
215229{
216- auto field = _descriptor-> FindFieldByName ( field_name);
230+ auto field = findFieldByNameHack (_descriptor, field_name);
217231 if (! field)
218232 {
219233 PyErr_SetString (PyExc_AttributeError, field_name.c_str ());
0 commit comments