| khenaidoo | 0927c72 | 2021-12-15 16:49:32 -0500 | [diff] [blame] | 1 | // Package desc contains "rich descriptors" for protocol buffers. The built-in |
| 2 | // descriptor types are simple protobuf messages, each one representing a |
| 3 | // different kind of element in the AST of a .proto source file. |
| 4 | // |
| 5 | // Because of this inherent "tree" quality, these build-in descriptors cannot |
| 6 | // refer to their enclosing file descriptor. Nor can a field descriptor refer to |
| 7 | // a message or enum descriptor that represents the field's type (for enum and |
| 8 | // nested message fields). All such links must instead be stringly typed. This |
| 9 | // limitation makes them much harder to use for doing interesting things with |
| 10 | // reflection. |
| 11 | // |
| 12 | // Without this package, resolving references to types is particularly complex. |
| 13 | // For example, resolving a field's type, the message type an extension extends, |
| 14 | // or the request and response types of an RPC method all require searching |
| 15 | // through symbols defined not only in the file in which these elements are |
| 16 | // declared but also in its transitive closure of dependencies. |
| 17 | // |
| 18 | // "Rich descriptors" avoid the need to deal with the complexities described |
| 19 | // above. A rich descriptor has all type references resolved and provides |
| 20 | // methods to access other rich descriptors for all referenced elements. Each |
| 21 | // rich descriptor has a usefully broad API, but does not try to mimic the full |
| 22 | // interface of the underlying descriptor proto. Instead, every rich descriptor |
| 23 | // provides access to that underlying proto, for extracting descriptor |
| 24 | // properties that are not immediately accessible through rich descriptor's |
| 25 | // methods. |
| 26 | // |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 27 | // Also see the grpcreflect, dynamic, and grpcdynamic packages in this same |
| 28 | // repo to see just how useful rich descriptors really are. |
| 29 | // |
| 30 | // # Loading Descriptors |
| 31 | // |
| khenaidoo | 0927c72 | 2021-12-15 16:49:32 -0500 | [diff] [blame] | 32 | // Rich descriptors can be accessed in similar ways as their "poor" cousins |
| 33 | // (descriptor protos). Instead of using proto.FileDescriptor, use |
| 34 | // desc.LoadFileDescriptor. Message descriptors and extension field descriptors |
| 35 | // can also be easily accessed using desc.LoadMessageDescriptor and |
| 36 | // desc.LoadFieldDescriptorForExtension, respectively. |
| 37 | // |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 38 | // If you are using the protoc-gen-gosrcinfo plugin (also in this repo), then |
| 39 | // the descriptors returned from these Load* functions will include source code |
| 40 | // information, and thus include comments for elements. |
| 41 | // |
| 42 | // # Creating Descriptors |
| 43 | // |
| khenaidoo | 0927c72 | 2021-12-15 16:49:32 -0500 | [diff] [blame] | 44 | // It is also possible create rich descriptors for proto messages that a given |
| 45 | // Go program doesn't even know about. For example, they could be loaded from a |
| 46 | // FileDescriptorSet file (which can be generated by protoc) or loaded from a |
| 47 | // server. This enables interesting things like dynamic clients: where a Go |
| 48 | // program can be an RPC client of a service it wasn't compiled to know about. |
| 49 | // |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 50 | // You cannot create a message descriptor without also creating its enclosing |
| 51 | // file, because the enclosing file is what contains other relevant information |
| 52 | // like other symbols and dependencies/imports, which is how type references |
| 53 | // are resolved (such as when a field in a message has a type that is another |
| 54 | // message or enum). |
| 55 | // |
| 56 | // So the functions in this package for creating descriptors are all for |
| 57 | // creating *file* descriptors. See the various Create* functions for more |
| 58 | // information. |
| 59 | // |
| 60 | // Also see the desc/builder sub-package, for another API that makes it easier |
| 61 | // to synthesize descriptors programmatically. |
| 62 | // |
| 63 | // Deprecated: This module was created for use with the older "v1" Protobuf API |
| 64 | // in github.com/golang/protobuf. However, much of this module is no longer |
| 65 | // necessary as the newer "v2" API in google.golang.org/protobuf provides similar |
| 66 | // capabilities. Instead of using this github.com/jhump/protoreflect/desc package, |
| 67 | // see [google.golang.org/protobuf/reflect/protoreflect]. |
| 68 | // |
| 69 | // [google.golang.org/protobuf/reflect/protoreflect]: https://pkg.go.dev/google.golang.org/protobuf/reflect/protoreflect |
| khenaidoo | 0927c72 | 2021-12-15 16:49:32 -0500 | [diff] [blame] | 70 | package desc |