grpcurl
grpcurl copied to clipboard
Proto generation
Hi, can we export proto from grpc server reflection?
Thanks
@wahmedswl, yes. Run grpcurl -h and then take a look at the -protoset-out. Note, however, that this exports a FileDescriptorSet that is written in the binary protobuf format. It does not produce proto sources.
Though you could use the packages in https://github.com/jhump/protoreflect to translate them into source files. You'd have to write some Go code to make that happen.
- Read the contents of the output descriptor set file and unmarshal into a
*descriptorpb.FileDescriptorSet - Call
desc.CreateFileDescriptorsFromSetto turn that into a set of "rich" descriptors. - Create a
*protoprint.Printerand use itsPrintProtoFilemethod to generate proto source from each "rich" descriptor.
Nice, can this be integrated within grpcurl? This is something useful.
Thanks
Alternatively, grpcurl could follow up on #57 and add a -recursive option to describe, so that the whole accessible "tree" of services and types would be described in a protobuf format (bonus points if we could filter out grpc.reflection.* and exclude the "x.Y is a service" comments :wink: ). This would probably miss a lot of corner-cases, but might be useful enough regardless?
Would an PR in this direction be considered? Or am I missing some obvious deal-breaker?
@costela, I'm not sure that would really work. The resulting source would not be compile-able unless it emitted, at a minimum, one file per referenced package. IMO, it would ideally be one file per actual input source file that defined the schema, which is how -protoset-out works.
So it needs to be special-cased to support multi-file export; it's not sufficient to just print the transitive closure of all elements independently as if in one file. I'm thinking that it would instead be a -proto-out option, where the resulting output will be a ZIP file, with possibly multiple proto source files inside.
@jhump ah yes, that makes sense. I'm coming from the "easy" case of single package proto definitions, so it would be enough for us, but not for a lot of other people.
Just out of curiosity, why do you suggest zipping the output (as opposed to, e.g. --proto-out-dir)?