From f3231e8555377b0cb8f6f425260f40cc216829d0 Mon Sep 17 00:00:00 2001 From: Josh Humphries Date: Mon, 30 Sep 2019 09:38:29 -0400 Subject: [PATCH] review feedback --- cmd/grpcurl/grpcurl.go | 8 ++++---- desc_source.go | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cmd/grpcurl/grpcurl.go b/cmd/grpcurl/grpcurl.go index 1c07598..aaa3bbf 100644 --- a/cmd/grpcurl/grpcurl.go +++ b/cmd/grpcurl/grpcurl.go @@ -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(` diff --git a/desc_source.go b/desc_source.go index 1a79e6b..635ddef 100644 --- a/desc_source.go +++ b/desc_source.go @@ -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()) }