pree pree - 8 months ago 62
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 Source

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