-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
registry.go
52 lines (42 loc) · 1.33 KB
/
registry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package registry
import (
"sync"
"github.com/cosmos/gogoproto/proto"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
"cosmossdk.io/x/tx/signing"
)
var (
mergedRegistryOnce sync.Once
mergedRegistry *protoregistry.Files
_ signing.ProtoFileResolver = lazyProtoRegistry{}
)
// lazyProtoRegistry is a lazy loading wrapper around the global protobuf registry.
type lazyProtoRegistry struct{}
func getRegistry() *protoregistry.Files {
var err error
mergedRegistryOnce.Do(func() {
mergedRegistry, err = proto.MergedRegistry()
if err != nil {
panic(err)
}
})
return mergedRegistry
}
func (l lazyProtoRegistry) FindFileByPath(s string) (protoreflect.FileDescriptor, error) {
reg := getRegistry()
return reg.FindFileByPath(s)
}
func (l lazyProtoRegistry) FindDescriptorByName(name protoreflect.FullName) (protoreflect.Descriptor, error) {
reg := getRegistry()
return reg.FindDescriptorByName(name)
}
func (l lazyProtoRegistry) RangeFiles(f func(protoreflect.FileDescriptor) bool) {
reg := getRegistry()
reg.RangeFiles(f)
}
// MergedProtoRegistry returns a lazy loading wrapper around the global protobuf registry, a merged registry
// containing both gogo proto and pulsar types.
func MergedProtoRegistry() signing.ProtoFileResolver {
return lazyProtoRegistry{}
}