protoregistry
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package protoregistry provides data structures to register and lookupprotobuf descriptor types.
TheFiles registry contains file descriptors and provides the abilityto iterate over the files or lookup a specific descriptor within the files.Files only contains protobuf descriptors and has no understanding of Gotype information that may be associated with each descriptor.
TheTypes registry contains descriptor types for which there is a knownGo type associated with that descriptor. It provides the ability to iterateover the registered types or lookup a type by name.
Index¶
- Variables
- type ExtensionTypeResolver
- type Files
- func (r *Files) FindDescriptorByName(name protoreflect.FullName) (protoreflect.Descriptor, error)
- func (r *Files) FindFileByPath(path string) (protoreflect.FileDescriptor, error)
- func (r *Files) NumFiles() int
- func (r *Files) NumFilesByPackage(name protoreflect.FullName) int
- func (r *Files) RangeFiles(f func(protoreflect.FileDescriptor) bool)
- func (r *Files) RangeFilesByPackage(name protoreflect.FullName, f func(protoreflect.FileDescriptor) bool)
- func (r *Files) RegisterFile(file protoreflect.FileDescriptor) error
- type MessageTypeResolver
- 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) NumEnums() int
- func (r *Types) NumExtensions() int
- func (r *Types) NumExtensionsByMessage(message protoreflect.FullName) int
- func (r *Types) NumMessages() int
- 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) RegisterEnum(et protoreflect.EnumType) error
- func (r *Types) RegisterExtension(xt protoreflect.ExtensionType) error
- func (r *Types) RegisterMessage(mt protoreflect.MessageType) 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.
Since registry lookup can happen in the critical performance path, resolversmust return this exact error value, not an error wrapping it.
Functions¶
This section is empty.
Types¶
typeExtensionTypeResolver¶
type ExtensionTypeResolver interface {// 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.FindExtensionByName(fieldprotoreflect.FullName) (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.FindExtensionByNumber(messageprotoreflect.FullName, fieldprotoreflect.FieldNumber) (protoreflect.ExtensionType,error)}ExtensionTypeResolver is an interface for looking up extensions.
A compliant implementation must deterministically return the same typeif no error is encountered.
TheTypes type implements this interface.
typeFiles¶
type Files struct {// contains filtered or unexported fields}Files is a registry for looking up or iterating over files and thedescriptors contained within them.The Find and Range methods are safe for concurrent use.
func (*Files)FindDescriptorByName¶
func (r *Files) FindDescriptorByName(nameprotoreflect.FullName) (protoreflect.Descriptor,error)
FindDescriptorByName looks up a descriptor by the full name.
This returns (nil,NotFound) if not found.
func (*Files)FindFileByPath¶
func (r *Files) FindFileByPath(pathstring) (protoreflect.FileDescriptor,error)
FindFileByPath looks up a file by the path.
This returns (nil,NotFound) if not found.This returns an error if multiple files have the same path.
func (*Files)NumFiles¶
NumFiles reports the number of registered files,including duplicate files with the same name.
func (*Files)NumFilesByPackage¶
func (r *Files) NumFilesByPackage(nameprotoreflect.FullName)int
NumFilesByPackage reports the number of registered files in a proto package.
func (*Files)RangeFiles¶
func (r *Files) RangeFiles(f func(protoreflect.FileDescriptor)bool)
RangeFiles iterates over all registered files while f returns true.If multiple files have the same name, RangeFiles iterates over all of them.The iteration order is undefined.
func (*Files)RangeFilesByPackage¶
func (r *Files) RangeFilesByPackage(nameprotoreflect.FullName, f func(protoreflect.FileDescriptor)bool)
RangeFilesByPackage iterates over all registered files in a given proto packagewhile f returns true. The iteration order is undefined.
func (*Files)RegisterFile¶
func (r *Files) RegisterFile(fileprotoreflect.FileDescriptor)error
RegisterFile registers the provided file descriptor.
If any descriptor within the file conflicts with the descriptor of anypreviously registered file (e.g., two enums with the same full name),then the file is not registered and an error is returned.
It is permitted for multiple files to have the same file path.
typeMessageTypeResolver¶
type MessageTypeResolver interface {// FindMessageByName looks up a message by its full name.// E.g., "google.protobuf.Any"//// This return (nil, NotFound) if not found.FindMessageByName(messageprotoreflect.FullName) (protoreflect.MessageType,error)// FindMessageByURL looks up a message by a URL identifier.// See documentation on google.protobuf.Any.type_url for the URL format.//// This returns (nil, NotFound) if not found.FindMessageByURL(urlstring) (protoreflect.MessageType,error)}MessageTypeResolver is an interface for looking up messages.
A compliant implementation must deterministically return the same typeif no error is encountered.
TheTypes type implements this interface.
typeTypes¶
type Types struct {// 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 lookupsunless a local registry is provided by the user.
func (*Types)FindEnumByName¶
func (r *Types) FindEnumByName(enumprotoreflect.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(fieldprotoreflect.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 bywhere the extension is declared and is unrelated to the full name of themessage being extended.
This returns (nil,NotFound) if not found.
func (*Types)FindExtensionByNumber¶
func (r *Types) FindExtensionByNumber(messageprotoreflect.FullName, fieldprotoreflect.FieldNumber) (protoreflect.ExtensionType,error)
FindExtensionByNumber looks up a extension field by the field numberwithin some parent message, identified by full name.
This returns (nil,NotFound) if not found.
func (*Types)FindMessageByName¶
func (r *Types) FindMessageByName(messageprotoreflect.FullName) (protoreflect.MessageType,error)
FindMessageByName looks up a message by its full name,e.g. "google.protobuf.Any".
This returns (nil,NotFound) if not found.
func (*Types)FindMessageByURL¶
func (r *Types) FindMessageByURL(urlstring) (protoreflect.MessageType,error)
FindMessageByURL looks up a message by a URL identifier.See documentation on google.protobuf.Any.type_url for the URL format.
This returns (nil,NotFound) if not found.
func (*Types)NumExtensions¶
NumExtensions reports the number of registered extensions.
func (*Types)NumExtensionsByMessage¶
func (r *Types) NumExtensionsByMessage(messageprotoreflect.FullName)int
NumExtensionsByMessage reports the number of registered extensions fora given message type.
func (*Types)NumMessages¶
NumMessages reports the number of registered messages.
func (*Types)RangeEnums¶
func (r *Types) RangeEnums(f func(protoreflect.EnumType)bool)
RangeEnums iterates over all registered enums while f returns true.Iteration order is undefined.
func (*Types)RangeExtensions¶
func (r *Types) RangeExtensions(f func(protoreflect.ExtensionType)bool)
RangeExtensions iterates over all registered extensions while f returns true.Iteration order is undefined.
func (*Types)RangeExtensionsByMessage¶
func (r *Types) RangeExtensionsByMessage(messageprotoreflect.FullName, f func(protoreflect.ExtensionType)bool)
RangeExtensionsByMessage iterates over all registered extensions filteredby a given message type while f returns true. Iteration order is undefined.
func (*Types)RangeMessages¶
func (r *Types) RangeMessages(f func(protoreflect.MessageType)bool)
RangeMessages iterates over all registered messages while f returns true.Iteration order is undefined.
func (*Types)RegisterEnum¶
func (r *Types) RegisterEnum(etprotoreflect.EnumType)error
RegisterEnum registers the provided enum type.
If a naming conflict occurs, the type is not registered and an error is returned.
func (*Types)RegisterExtension¶
func (r *Types) RegisterExtension(xtprotoreflect.ExtensionType)error
RegisterExtension registers the provided extension type.
If a naming conflict occurs, the type is not registered and an error is returned.
func (*Types)RegisterMessage¶
func (r *Types) RegisterMessage(mtprotoreflect.MessageType)error
RegisterMessage registers the provided message type.
If a naming conflict occurs, the type is not registered and an error is returned.