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