Involved Source Files
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.
Package-Level Type Names (total 9, in which 4 are exported)
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.
The map of descsByName contains:
EnumDescriptor
EnumValueDescriptor
MessageDescriptor
ExtensionDescriptor
ServiceDescriptor
*packageDescriptor
Note that files are stored as a slice, since a package may contain
multiple files. Only top-level declarations are registered.
Note that enum values are in the top-level since that are in the same
scope as the parent enum.
filesByPathmap[string]protoreflect.FileDescriptor
FindDescriptorByName looks up a descriptor by the full name.
This returns (nil, NotFound) if not found.
FindFileByPath looks up a file by the path.
This returns (nil, NotFound) if not found.
NumFiles reports the number of registered files.
NumFilesByPackage reports the number of registered files in a proto package.
RangeFiles iterates over all registered files while f returns true.
The iteration order is undefined.
RangeFilesByPackage iterates over all registered files in a given proto package
while f returns true. The iteration order is undefined.
RegisterFile registers the provided file descriptor.
If any descriptor within the file conflicts with the descriptor of any
previously 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.
Several well-known types were hosted in the google.golang.org/genproto module
but were later moved to this module. To avoid a weak dependency on the
genproto module (and its relatively large set of transitive dependencies),
we rely on a registration conflict to determine whether the genproto version
is too old (i.e., does not contain aliases to the new type declarations).
*T : google.golang.org/protobuf/reflect/protodesc.Resolver
*T : google.golang.org/protobuf/internal/filetype.fileRegistry
func google.golang.org/protobuf/reflect/protodesc.NewFiles(fd *descriptorpb.FileDescriptorSet) (*Files, error)
func google.golang.org/protobuf/reflect/protodesc.FileOptions.NewFiles(fds *descriptorpb.FileDescriptorSet) (*Files, error)
func google.golang.org/protobuf/reflect/protodesc.FileOptions.addFileDeps(r *Files, fd *descriptorpb.FileDescriptorProto, files map[string]*descriptorpb.FileDescriptorProto) error
var GlobalFiles *Files
MessageTypeResolver is an interface for looking up messages.
A compliant implementation must deterministically return the same type
if no error is encountered.
The Types type implements this interface.
FindMessageByName looks up a message by its full name.
E.g., "google.protobuf.Any"
This return (nil, NotFound) if not found.
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.
*Types
Types is a registry for looking up or iterating over descriptor types.
The Find and Range methods are safe for concurrent use.
extensionsByMessageextensionsByMessagenumEnumsintnumExtensionsintnumMessagesinttypesByNametypesByName
FindEnumByName looks up an enum by its full name.
E.g., "google.protobuf.Field.Kind".
This returns (nil, NotFound) if not found.
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.
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.
FindMessageByName looks up a message by its full name,
e.g. "google.protobuf.Any".
This returns (nil, NotFound) if not found.
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.
NumEnums reports the number of registered enums.
NumExtensions reports the number of registered extensions.
NumExtensionsByMessage reports the number of registered extensions for
a given message type.
NumMessages reports the number of registered messages.
RangeEnums iterates over all registered enums while f returns true.
Iteration order is undefined.
RangeExtensions iterates over all registered extensions while f returns true.
Iteration order is undefined.
RangeExtensionsByMessage iterates over all registered extensions filtered
by a given message type while f returns true. Iteration order is undefined.
RangeMessages iterates over all registered messages while f returns true.
Iteration order is undefined.
RegisterEnum registers the provided enum type.
If a naming conflict occurs, the type is not registered and an error is returned.
RegisterExtension registers the provided extension type.
If a naming conflict occurs, the type is not registered and an error is returned.
RegisterMessage registers the provided message type.
If a naming conflict occurs, the type is not registered and an error is returned.
(*T) register(kind string, desc protoreflect.Descriptor, typ interface{}) error
*T : ExtensionTypeResolver
*T : MessageTypeResolver
var GlobalTypes *Types
Package-Level Variables (total 6, in which 3 are exported)
GlobalFiles is a global registry of file descriptors.
GlobalTypes is the registry used by default for type lookups
unless a local registry is provided by the user.
NotFound is a sentinel error value to indicate that the type was not found.
Since registry lookup can happen in the critical performance path, resolvers
must return this exact error value, not an error wrapping it.
conflictPolicy configures the policy for handling registration conflicts.
It can be over-written at compile time with a linker-initialized variable:
go build -ldflags "-X google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=warn"
It can be over-written at program execution with an environment variable:
GOLANG_PROTOBUF_REGISTRATION_CONFLICT=warn ./main
Neither of the above are covered by the compatibility promise and
may be removed in a future release of this module.
ignoreConflict reports whether to ignore a registration conflict
given the descriptor being registered and the error.
It is a variable so that the behavior is easily overridden in another file.
The pages are generated with Goldsv0.3.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.