Documentation
¶
Overview ¶
Package nsregistry provides file and type registries with per-namespace isolation and hierarchical fallback, for a process that serves schemas which would conflict in the global registries of google.golang.org/protobuf/reflect/protoregistry.
It came from the trendvidia/protobuf-go fork and needs only protobuf's public API. The code is BSD-licensed; see the LICENSE file in this directory.
Index ¶
- type Namespace
- type NamespacedFiles
- func (r *NamespacedFiles) FindDescriptorByName(name protoreflect.FullName) (protoreflect.Descriptor, error)
- func (r *NamespacedFiles) FindFileByPath(path string) (protoreflect.FileDescriptor, error)
- func (r *NamespacedFiles) NumFiles() int
- func (r *NamespacedFiles) NumFilesByPackage(name protoreflect.FullName) int
- func (r *NamespacedFiles) RangeFiles(f func(protoreflect.FileDescriptor) bool)
- func (r *NamespacedFiles) RangeFilesAll(f func(protoreflect.FileDescriptor) bool)
- func (r *NamespacedFiles) RangeFilesByPackage(name protoreflect.FullName, f func(protoreflect.FileDescriptor) bool)
- func (r *NamespacedFiles) RegisterFile(file protoreflect.FileDescriptor) error
- func (r *NamespacedFiles) UnregisterFile(path string) error
- func (r *NamespacedFiles) UpdateFile(file protoreflect.FileDescriptor) error
- type NamespacedTypes
- func (r *NamespacedTypes) FindEnumByName(enum protoreflect.FullName) (protoreflect.EnumType, error)
- func (r *NamespacedTypes) FindExtensionByName(field protoreflect.FullName) (protoreflect.ExtensionType, error)
- func (r *NamespacedTypes) FindExtensionByNumber(message protoreflect.FullName, field protoreflect.FieldNumber) (protoreflect.ExtensionType, error)
- func (r *NamespacedTypes) FindMessageByName(message protoreflect.FullName) (protoreflect.MessageType, error)
- func (r *NamespacedTypes) FindMessageByURL(url string) (protoreflect.MessageType, error)
- func (r *NamespacedTypes) NumEnums() int
- func (r *NamespacedTypes) NumExtensions() int
- func (r *NamespacedTypes) NumExtensionsByMessage(message protoreflect.FullName) int
- func (r *NamespacedTypes) NumMessages() int
- func (r *NamespacedTypes) RangeEnums(f func(protoreflect.EnumType) bool)
- func (r *NamespacedTypes) RangeExtensions(f func(protoreflect.ExtensionType) bool)
- func (r *NamespacedTypes) RangeExtensionsByMessage(message protoreflect.FullName, f func(protoreflect.ExtensionType) bool)
- func (r *NamespacedTypes) RangeMessages(f func(protoreflect.MessageType) bool)
- func (r *NamespacedTypes) RegisterEnum(et protoreflect.EnumType) error
- func (r *NamespacedTypes) RegisterExtension(xt protoreflect.ExtensionType) error
- func (r *NamespacedTypes) RegisterMessage(mt protoreflect.MessageType) error
- func (r *NamespacedTypes) UnregisterEnum(name protoreflect.FullName) error
- func (r *NamespacedTypes) UnregisterExtension(name protoreflect.FullName) error
- func (r *NamespacedTypes) UnregisterMessage(name protoreflect.FullName) error
- func (r *NamespacedTypes) UpdateEnum(et protoreflect.EnumType) error
- func (r *NamespacedTypes) UpdateExtension(xt protoreflect.ExtensionType) error
- func (r *NamespacedTypes) UpdateMessage(mt protoreflect.MessageType) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Namespace ¶
type Namespace struct {
Files *NamespacedFiles
Types *NamespacedTypes
}
Namespace bundles a NamespacedFiles and NamespacedTypes together, providing an isolated, hierarchical registry for multi-tenant or dynamic-plugin use. A child namespace falls back to its parent for lookups, but mutations only affect the local namespace. Globals are treated as read-only.
func NewNamespace ¶
NewNamespace creates a child namespace whose lookups fall back to parent. Pass nil to create a root namespace with no fallback.
func NewNamespaceOverGlobal ¶
func NewNamespaceOverGlobal() *Namespace
NewNamespaceOverGlobal creates a namespace that falls back to protoregistry.GlobalFiles and protoregistry.GlobalTypes for lookups. The globals are read-only through this handle.
func NewRootNamespace ¶
func NewRootNamespace() *Namespace
NewRootNamespace creates a root namespace with no parent fallback.
type NamespacedFiles ¶
type NamespacedFiles struct {
// contains filtered or unexported fields
}
NamespacedFiles is a file descriptor registry with hierarchical fallback. Mutations (Register, Update, Unregister) affect only the local registry. Lookups check the local registry first, then walk the parent chain.
Safe for concurrent use.
func NewNamespacedFiles ¶
func NewNamespacedFiles(parent *NamespacedFiles) *NamespacedFiles
NewNamespacedFiles creates a new NamespacedFiles whose lookups fall back to parent. Pass nil to create a root namespace with no fallback.
func (*NamespacedFiles) FindDescriptorByName ¶
func (r *NamespacedFiles) FindDescriptorByName(name protoreflect.FullName) (protoreflect.Descriptor, error)
FindDescriptorByName looks up a descriptor by full name. Checks the local namespace first, then walks the parent chain.
This returns (nil, protoregistry.NotFound) if not found.
func (*NamespacedFiles) FindFileByPath ¶
func (r *NamespacedFiles) FindFileByPath(path string) (protoreflect.FileDescriptor, error)
FindFileByPath looks up a file by path. Checks the local namespace first, then walks the parent chain.
This returns (nil, protoregistry.NotFound) if not found.
func (*NamespacedFiles) NumFiles ¶
func (r *NamespacedFiles) NumFiles() int
NumFiles reports the number of files registered in the local namespace.
func (*NamespacedFiles) NumFilesByPackage ¶
func (r *NamespacedFiles) NumFilesByPackage(name protoreflect.FullName) int
NumFilesByPackage reports the number of files in a proto package in the local namespace.
func (*NamespacedFiles) RangeFiles ¶
func (r *NamespacedFiles) RangeFiles(f func(protoreflect.FileDescriptor) bool)
RangeFiles iterates over files in the local namespace while f returns true. Iteration order is undefined.
func (*NamespacedFiles) RangeFilesAll ¶
func (r *NamespacedFiles) RangeFilesAll(f func(protoreflect.FileDescriptor) bool)
RangeFilesAll iterates over all files visible to this namespace (local first, then parent chain). Files in a child namespace shadow files with the same path in a parent. Iteration order is undefined.
func (*NamespacedFiles) RangeFilesByPackage ¶
func (r *NamespacedFiles) RangeFilesByPackage(name protoreflect.FullName, f func(protoreflect.FileDescriptor) bool)
RangeFilesByPackage iterates over files in a given package in the local namespace.
func (*NamespacedFiles) RegisterFile ¶
func (r *NamespacedFiles) RegisterFile(file protoreflect.FileDescriptor) error
RegisterFile registers the provided file descriptor in the local namespace. Returns an error if a descriptor within the file conflicts with an existing local registration.
func (*NamespacedFiles) UnregisterFile ¶
func (r *NamespacedFiles) UnregisterFile(path string) error
UnregisterFile removes the file at the given path and all its contributed descriptors from the local namespace. Returns protoregistry.NotFound if no file with that path is registered locally.
func (*NamespacedFiles) UpdateFile ¶
func (r *NamespacedFiles) UpdateFile(file protoreflect.FileDescriptor) error
UpdateFile registers or replaces the file at the given path. If a file with the same path already exists, stale descriptors are removed and all indexes are updated. If no file with that path exists, this behaves like RegisterFile but without conflict checks (upsert semantics).
type NamespacedTypes ¶
type NamespacedTypes struct {
// contains filtered or unexported fields
}
NamespacedTypes is a type registry with hierarchical fallback. Mutations affect only the local registry. Lookups check the local registry first, then walk the parent chain.
Safe for concurrent use.
func NewNamespacedTypes ¶
func NewNamespacedTypes(parent *NamespacedTypes) *NamespacedTypes
NewNamespacedTypes creates a new NamespacedTypes whose lookups fall back to parent. Pass nil to create a root namespace with no fallback.
func (*NamespacedTypes) FindEnumByName ¶
func (r *NamespacedTypes) FindEnumByName(enum protoreflect.FullName) (protoreflect.EnumType, error)
FindEnumByName looks up an enum by its full name. Checks the local namespace first, then the parent chain.
This returns (nil, protoregistry.NotFound) if not found.
func (*NamespacedTypes) FindExtensionByName ¶
func (r *NamespacedTypes) FindExtensionByName(field protoreflect.FullName) (protoreflect.ExtensionType, error)
FindExtensionByName looks up an extension field by the field's full name. Checks the local namespace first, then the parent chain.
This returns (nil, protoregistry.NotFound) if not found.
func (*NamespacedTypes) FindExtensionByNumber ¶
func (r *NamespacedTypes) FindExtensionByNumber(message protoreflect.FullName, field protoreflect.FieldNumber) (protoreflect.ExtensionType, error)
FindExtensionByNumber looks up an extension field by the field number within some parent message. Checks the local namespace first, then the parent chain.
This returns (nil, protoregistry.NotFound) if not found.
func (*NamespacedTypes) FindMessageByName ¶
func (r *NamespacedTypes) FindMessageByName(message protoreflect.FullName) (protoreflect.MessageType, error)
FindMessageByName looks up a message by its full name. Checks the local namespace first, then the parent chain.
This returns (nil, protoregistry.NotFound) if not found.
func (*NamespacedTypes) FindMessageByURL ¶
func (r *NamespacedTypes) FindMessageByURL(url string) (protoreflect.MessageType, error)
FindMessageByURL looks up a message by a URL identifier. Checks the local namespace first, then the parent chain.
This returns (nil, protoregistry.NotFound) if not found.
func (*NamespacedTypes) NumEnums ¶
func (r *NamespacedTypes) NumEnums() int
NumEnums reports the number of enums registered in the local namespace.
func (*NamespacedTypes) NumExtensions ¶
func (r *NamespacedTypes) NumExtensions() int
NumExtensions reports the number of extensions registered in the local namespace.
func (*NamespacedTypes) NumExtensionsByMessage ¶
func (r *NamespacedTypes) NumExtensionsByMessage(message protoreflect.FullName) int
NumExtensionsByMessage reports the number of extensions for a given message in the local namespace.
func (*NamespacedTypes) NumMessages ¶
func (r *NamespacedTypes) NumMessages() int
NumMessages reports the number of messages registered in the local namespace.
func (*NamespacedTypes) RangeEnums ¶
func (r *NamespacedTypes) RangeEnums(f func(protoreflect.EnumType) bool)
RangeEnums iterates over enums in the local namespace while f returns true.
func (*NamespacedTypes) RangeExtensions ¶
func (r *NamespacedTypes) RangeExtensions(f func(protoreflect.ExtensionType) bool)
RangeExtensions iterates over extensions in the local namespace while f returns true.
func (*NamespacedTypes) RangeExtensionsByMessage ¶
func (r *NamespacedTypes) RangeExtensionsByMessage(message protoreflect.FullName, f func(protoreflect.ExtensionType) bool)
RangeExtensionsByMessage iterates over extensions for a given message in the local namespace while f returns true.
func (*NamespacedTypes) RangeMessages ¶
func (r *NamespacedTypes) RangeMessages(f func(protoreflect.MessageType) bool)
RangeMessages iterates over messages in the local namespace while f returns true.
func (*NamespacedTypes) RegisterEnum ¶
func (r *NamespacedTypes) RegisterEnum(et protoreflect.EnumType) error
RegisterEnum registers the provided enum type in the local namespace.
func (*NamespacedTypes) RegisterExtension ¶
func (r *NamespacedTypes) RegisterExtension(xt protoreflect.ExtensionType) error
RegisterExtension registers the provided extension type in the local namespace.
func (*NamespacedTypes) RegisterMessage ¶
func (r *NamespacedTypes) RegisterMessage(mt protoreflect.MessageType) error
RegisterMessage registers the provided message type in the local namespace.
func (*NamespacedTypes) UnregisterEnum ¶
func (r *NamespacedTypes) UnregisterEnum(name protoreflect.FullName) error
UnregisterEnum removes an enum type by full name. Returns protoregistry.NotFound if not registered locally.
func (*NamespacedTypes) UnregisterExtension ¶
func (r *NamespacedTypes) UnregisterExtension(name protoreflect.FullName) error
UnregisterExtension removes an extension type by full name. Returns protoregistry.NotFound if not registered locally.
func (*NamespacedTypes) UnregisterMessage ¶
func (r *NamespacedTypes) UnregisterMessage(name protoreflect.FullName) error
UnregisterMessage removes a message type by full name. Returns protoregistry.NotFound if not registered locally.
func (*NamespacedTypes) UpdateEnum ¶
func (r *NamespacedTypes) UpdateEnum(et protoreflect.EnumType) error
UpdateEnum registers or replaces an enum type (upsert).
func (*NamespacedTypes) UpdateExtension ¶
func (r *NamespacedTypes) UpdateExtension(xt protoreflect.ExtensionType) error
UpdateExtension registers or replaces an extension type (upsert).
func (*NamespacedTypes) UpdateMessage ¶
func (r *NamespacedTypes) UpdateMessage(mt protoreflect.MessageType) error
UpdateMessage registers or replaces a message type (upsert).