Documentation
¶
Overview ¶
Package protoregistry provides data structures to register and lookup protobuf descriptor types.
The Files registry contains file descriptors and provides the ability to iterate over the files or lookup a specific descriptor within the files. Files only contains protobuf descriptors and has no understanding of Go type information that may be associated with each descriptor.
The Types registry contains descriptor types for which there is a known Go type associated with that descriptor. It provides the ability to iterate over the registered types or lookup a type by name.
Index ¶
- Variables
- type Files
- func (r *Files) FindEnumByName(name protoreflect.FullName) (protoreflect.EnumDescriptor, error)
- func (r *Files) FindExtensionByName(name protoreflect.FullName) (protoreflect.ExtensionDescriptor, error)
- func (r *Files) FindMessageByName(name protoreflect.FullName) (protoreflect.MessageDescriptor, error)
- func (r *Files) FindServiceByName(name protoreflect.FullName) (protoreflect.ServiceDescriptor, error)
- func (r *Files) RangeFiles(f func(protoreflect.FileDescriptor) bool)
- func (r *Files) RangeFilesByPackage(name protoreflect.FullName, f func(protoreflect.FileDescriptor) bool)
- func (r *Files) RangeFilesByPath(path string, f func(protoreflect.FileDescriptor) bool)
- func (r *Files) Register(files ...protoreflect.FileDescriptor) error
- type Type
- type Types
- func (r *Types) FindEnumByName(enum protoreflect.FullName) (protoreflect.EnumType, error)
- func (r *Types) FindExtensionByName(field protoreflect.FullName) (protoreflect.ExtensionType, error)
- func (r *Types) FindExtensionByNumber(message protoreflect.FullName, field protoreflect.FieldNumber) (protoreflect.ExtensionType, error)
- func (r *Types) FindMessageByName(message protoreflect.FullName) (protoreflect.MessageType, error)
- func (r *Types) FindMessageByURL(url string) (protoreflect.MessageType, error)
- func (r *Types) RangeEnums(f func(protoreflect.EnumType) bool)
- func (r *Types) RangeExtensions(f func(protoreflect.ExtensionType) bool)
- func (r *Types) RangeExtensionsByMessage(message protoreflect.FullName, f func(protoreflect.ExtensionType) bool)
- func (r *Types) RangeMessages(f func(protoreflect.MessageType) bool)
- func (r *Types) Register(typs ...Type) error
Constants ¶
This section is empty.
Variables ¶
var NotFound = errors.New("not found")
NotFound is a sentinel error value to indicate that the type was not found.
Functions ¶
This section is empty.
Types ¶
type Files ¶
type Files struct {
// contains filtered or unexported fields
}
Files is a registry for looking up or iterating over files and the descriptors contained within them. The Find and Range methods are safe for concurrent use.
func NewFiles ¶
func NewFiles(files ...protoreflect.FileDescriptor) *Files
NewFiles returns a registry initialized with the provided set of files. If there are duplicates, the first one takes precedence.
func (*Files) FindEnumByName ¶
func (r *Files) FindEnumByName(name protoreflect.FullName) (protoreflect.EnumDescriptor, error)
FindEnumByName looks up an enum by the enum's full name.
This returns (nil, NotFound) if not found.
func (*Files) FindExtensionByName ¶
func (r *Files) FindExtensionByName(name protoreflect.FullName) (protoreflect.ExtensionDescriptor, error)
FindExtensionByName looks up an extension field by the field's full name. Note that this is the full name of the field as determined by where the extension is declared and is unrelated to the full name of the message being extended.
This returns (nil, NotFound) if not found.
func (*Files) FindMessageByName ¶
func (r *Files) FindMessageByName(name protoreflect.FullName) (protoreflect.MessageDescriptor, error)
FindMessageByName looks up a message by the message's full name.
This returns (nil, NotFound) if not found.
func (*Files) FindServiceByName ¶
func (r *Files) FindServiceByName(name protoreflect.FullName) (protoreflect.ServiceDescriptor, error)
FindServiceByName looks up a service by the service's full name.
This returns (nil, NotFound) if not found.
func (*Files) RangeFiles ¶
func (r *Files) RangeFiles(f func(protoreflect.FileDescriptor) bool)
RangeFiles iterates over all registered files. The iteration order is undefined.
func (*Files) RangeFilesByPackage ¶
func (r *Files) RangeFilesByPackage(name protoreflect.FullName, f func(protoreflect.FileDescriptor) bool)
RangeFilesByPackage iterates over all registered files in a give proto package. The iteration order is undefined.
func (*Files) RangeFilesByPath ¶
func (r *Files) RangeFilesByPath(path string, f func(protoreflect.FileDescriptor) bool)
RangeFilesByPath iterates over all registered files filtered by the given proto path. The iteration order is undefined.
func (*Files) Register ¶
func (r *Files) Register(files ...protoreflect.FileDescriptor) error
Register registers the provided list of file descriptors. Placeholder files are ignored.
If any descriptor within a file conflicts with the descriptor of any previously registered file (e.g., two enums with the same full name), then that file is not registered and an error is returned.
It is permitted for multiple files to have the same file path.
type Type ¶
type Type interface { protoreflect.Descriptor GoType() reflect.Type }
Type is an interface satisfied by protoreflect.EnumType, protoreflect.MessageType, or protoreflect.ExtensionType.
type Types ¶
type Types struct { // Parent sets the parent registry to consult if a find operation // could not locate the appropriate entry. // // Setting a parent results in each Range operation also iterating over the // entries contained within the parent. In such a case, it is possible for // Range to emit duplicates (since they may exist in both child and parent). // Range iteration is guaranteed to iterate over local entries before // iterating over parent entries. Parent *Types // Resolver sets the local resolver to consult if the local registry does // not contain an entry. The resolver takes precedence over the parent. // // The url is a URL where the full name of the type is the last segment // of the path (i.e. string following the last '/' character). // When missing a '/' character, the URL is the full name of the type. // See documentation on the google.protobuf.Any.type_url field for details. // // If the resolver returns a result, it is not automatically registered // into the local registry. Thus, a resolver function should cache results // such that it deterministically returns the same result given the // same URL assuming the error returned is nil or NotFound. // // If the resolver returns the NotFound error, the registry will consult the // parent registry if it is set. // // Setting a resolver has no effect on the result of each Range operation. Resolver func(url string) (Type, error) // contains filtered or unexported fields }
Types is a registry for looking up or iterating over descriptor types. The Find and Range methods are safe for concurrent use.
GlobalTypes is the registry used by default for type lookups unless a local registry is provided by the user.
func NewTypes ¶
NewTypes returns a registry initialized with the provided set of types. If there are conflicts, the first one takes precedence.
func (*Types) FindEnumByName ¶
func (r *Types) FindEnumByName(enum protoreflect.FullName) (protoreflect.EnumType, error)
FindEnumByName looks up an enum by its full name. E.g., "google.protobuf.Field.Kind".
This returns (nil, NotFound) if not found.
func (*Types) FindExtensionByName ¶
func (r *Types) FindExtensionByName(field protoreflect.FullName) (protoreflect.ExtensionType, error)
FindExtensionByName looks up a extension field by the field's full name. Note that this is the full name of the field as determined by where the extension is declared and is unrelated to the full name of the message being extended.
This returns (nil, NotFound) if not found.
func (*Types) FindExtensionByNumber ¶
func (r *Types) FindExtensionByNumber(message protoreflect.FullName, field protoreflect.FieldNumber) (protoreflect.ExtensionType, error)
FindExtensionByNumber looks up a extension field by the field number within some parent message, identified by full name.
This returns (nil, NotFound) if not found.
func (*Types) FindMessageByName ¶
func (r *Types) FindMessageByName(message protoreflect.FullName) (protoreflect.MessageType, error)
FindMessageByName looks up a message by its full name. E.g., "google.protobuf.Any"
This return (nil, NotFound) if not found.
func (*Types) FindMessageByURL ¶
func (r *Types) FindMessageByURL(url string) (protoreflect.MessageType, error)
FindMessageByURL looks up a message by a URL identifier. See Resolver for the format of the URL.
This returns (nil, NotFound) if not found.
func (*Types) RangeEnums ¶
func (r *Types) RangeEnums(f func(protoreflect.EnumType) bool)
RangeEnums iterates over all registered enums. Iteration order is undefined.
func (*Types) RangeExtensions ¶
func (r *Types) RangeExtensions(f func(protoreflect.ExtensionType) bool)
RangeExtensions iterates over all registered extensions. Iteration order is undefined.
func (*Types) RangeExtensionsByMessage ¶
func (r *Types) RangeExtensionsByMessage(message protoreflect.FullName, f func(protoreflect.ExtensionType) bool)
RangeExtensionsByMessage iterates over all registered extensions filtered by a given message type. Iteration order is undefined.
func (*Types) RangeMessages ¶
func (r *Types) RangeMessages(f func(protoreflect.MessageType) bool)
RangeMessages iterates over all registered messages. Iteration order is undefined.