I need the message name and the field name of the protobuf in the form of a string.
I could not find a way to do this in nanopb's documentation.
I need the message name and the field name of the protobuf in the form of a string.
I could not find a way to do this in nanopb's documentation.
Nanopb does not have reflection (runtime introspection) support, as listed in features and limitations.
As such there is no API for accessing or iterating fields by their names.
At compile time, you can use the
FIELDLISTX-macro that is included in the generated.pb.hfile. That can be used for autogenerating some things, such as list of strings for the field names.The autogenerated list format is:
And access is by defining a macro:
But there is quite little you can actually do with the field names, apart from printing out for logging and similar.