Allow TypeProvider to iterate over message fields
Feature request checklist
- [X] There are no issues that match the desired change
- [X] The change is large enough it can't be addressed with a simple Pull Request
- [X] If this is a bug, please file a Bug Report.
Change There is currently no way in the TypeProvider interface to discover the fields available in a message.
Example
for _, field := range provider.MessageFields(msgName) {
fieldType, found := provider.FindFieldType(msgName, field)
...do something with field...
}
Alternatives considered
Could use proto reflection if you have an instance about, but won't work for a compiler server where foreign proto definitions are imported by FileDescriptorSet.
Most of what you need will be easily accessible in the pb/type.go once #399 is checked in. The one question I have is whether you want to use the ref.FieldType or if you want the pb.FieldDescription which provides much more information.
The reason I ask is because we have a few options available to accomplish this:
- Pass a
pb.Dbdirectly into theNewRegistrycall, no interface change to speak of. - Make it possible to iterate over the fields in of any type and expose
FindTypeFields(typeName string)on theTypeProvider
I prefer the former since it's a smaller API surface change and it shouldn't impact custom ref.TypeProvider implementations at all. Thoughts?
Just the field name is sufficient - I think we can get what we need from the TypeProvider interface once we have the name.