review feedback
This commit is contained in:
parent
4ebb88c4cb
commit
f3231e8555
|
|
@ -105,10 +105,10 @@ var (
|
|||
protosetOut = flags.String("protoset-out", "", prettify(`
|
||||
The name of a file to be written that will contain a FileDescriptorSet
|
||||
proto. With the list and describe verbs, the listed or described
|
||||
elements, and their transitive dependencies, will be written to the
|
||||
named file if this option is given. When invoking an RPC and this option
|
||||
is given, the method being invoked and its transitive dependencies will
|
||||
be included in the output file.`))
|
||||
elements and their transitive dependencies will be written to the named
|
||||
file if this option is given. When invoking an RPC and this option is
|
||||
given, the method being invoked and its transitive dependencies will be
|
||||
included in the output file.`))
|
||||
msgTemplate = flags.Bool("msg-template", false, prettify(`
|
||||
When describing messages, show a template of input data.`))
|
||||
verbose = flags.Bool("v", false, prettify(`
|
||||
|
|
|
|||
|
|
@ -277,7 +277,7 @@ func WriteProtoset(out io.Writer, descSource DescriptorSource, symbols ...string
|
|||
expandedFiles := make(map[string]struct{}, len(fds))
|
||||
allFilesSlice := make([]*descpb.FileDescriptorProto, 0, len(fds))
|
||||
for _, filename := range filenames {
|
||||
addFilesToSet(expandedFiles, &allFilesSlice, fds[filename])
|
||||
allFilesSlice = addFilesToSet(allFilesSlice, expandedFiles, fds[filename])
|
||||
}
|
||||
// now we can serialize to file
|
||||
b, err := proto.Marshal(&descpb.FileDescriptorSet{File: allFilesSlice})
|
||||
|
|
@ -290,15 +290,15 @@ func WriteProtoset(out io.Writer, descSource DescriptorSource, symbols ...string
|
|||
return nil
|
||||
}
|
||||
|
||||
func addFilesToSet(seen map[string]struct{}, fds *[]*descpb.FileDescriptorProto, fd *desc.FileDescriptor) {
|
||||
if _, ok := seen[fd.GetName()]; ok {
|
||||
func addFilesToSet(allFiles []*descpb.FileDescriptorProto, expanded map[string]struct{}, fd *desc.FileDescriptor) []*descpb.FileDescriptorProto {
|
||||
if _, ok := expanded[fd.GetName()]; ok {
|
||||
// already seen this one
|
||||
return
|
||||
return allFiles
|
||||
}
|
||||
seen[fd.GetName()] = struct{}{}
|
||||
expanded[fd.GetName()] = struct{}{}
|
||||
// add all dependencies first
|
||||
for _, dep := range fd.GetDependencies() {
|
||||
addFilesToSet(seen, fds, dep)
|
||||
allFiles = addFilesToSet(allFiles, expanded, dep)
|
||||
}
|
||||
*fds = append(*fds, fd.AsFileDescriptorProto())
|
||||
return append(allFiles, fd.AsFileDescriptorProto())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue