pree pree - 18 days ago 6
Java Question

Get field descriptor in Protocol Buffers

Is there a way to get the field descriptor by using the given field number in protocol buffers? I know it exists for C++ (FindKnownExtensionsByNumber()) using reflection, however, I couldn't one for Java.

Answer

I suspect you're looking for Descriptor.findFieldByNumber. Note that will find a field by number, not an extension. For extensions, use ExtensionRegistry.findExtensionByNumber.