I want to get all the field names of a proto into a list. Is there a way to do this? I looked in the documentation and there doesn\'t seem to be anything for this.
qfiard's answer didn't work for me. Calling message.DESCRIPTOR.fields.keys()
produced AttributeError: 'list' object has no attribute 'keys'
.
Not sure why it wouldn't work. Maybe it has something to do with how the message was defined/compiled.
The workaround was to do a list composition of the individual field objects and get the name
property for each. This gave me a list of strings of all fields in this list.
res = [f.name for f in message.DESCRIPTOR.fields]
Note that this does not get you the field names within those fields recursively.