Skip to content

Commit

Permalink
due to pending PR grpc/grpc-go#5197, no need for srcinforeflection pa…
Browse files Browse the repository at this point in the history
…ckage; but sourceinfo.GlobalFiles needs to implement add'l methods to serve extension info
  • Loading branch information
jhump committed Feb 17, 2022
1 parent 1837b10 commit 17314e8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 354 deletions.
30 changes: 29 additions & 1 deletion desc/sourceinfo/registry.go
Expand Up @@ -34,13 +34,19 @@ var (
//
// If is mean to serve as a drop-in alternative to protoregistry.GlobalFiles that
// can include source code info in the returned descriptors.
GlobalFiles protodesc.Resolver = registry{}
GlobalFiles Resolver = registry{}

mu sync.RWMutex
sourceInfoByFile = map[string]*descriptorpb.SourceCodeInfo{}
fileDescriptors = map[protoreflect.FileDescriptor]protoreflect.FileDescriptor{}
)

type Resolver interface {
protodesc.Resolver
protoregistry.ExtensionTypeResolver
RangeExtensionsByMessage(message protoreflect.FullName, f func(protoreflect.ExtensionType) bool)
}

// RegisterSourceInfo registers the given source code info for the file descriptor
// with the given path/name.
//
Expand Down Expand Up @@ -138,3 +144,25 @@ func (r registry) FindDescriptorByName(name protoreflect.FullName) (protoreflect
return nil, fmt.Errorf("unrecognized descriptor type: %T", d)
}
}

func (r registry) FindExtensionByName(field protoreflect.FullName) (protoreflect.ExtensionType, error) {
xt, err := protoregistry.GlobalTypes.FindExtensionByName(field)
if err != nil {
return nil, err
}
return extensionType{xt}, nil
}

func (r registry) FindExtensionByNumber(message protoreflect.FullName, field protoreflect.FieldNumber) (protoreflect.ExtensionType, error) {
xt, err := protoregistry.GlobalTypes.FindExtensionByNumber(message, field)
if err != nil {
return nil, err
}
return extensionType{xt}, nil
}

func (r registry) RangeExtensionsByMessage(message protoreflect.FullName, fn func(protoreflect.ExtensionType) bool) {
protoregistry.GlobalTypes.RangeExtensionsByMessage(message, func(xt protoreflect.ExtensionType) bool {
return fn(extensionType{xt})
})
}
208 changes: 0 additions & 208 deletions desc/sourceinfo/srcinforeflection/serverreflection.go

This file was deleted.

0 comments on commit 17314e8

Please sign in to comment.