jhump / protoreflect

Reflection (Rich Descriptors) for Go Protocol Buffers
Apache License 2.0
1.35k stars 172 forks source link

Can load the descriptor_set file generated by protoc? #532

Closed residual-paranoia closed 1 year ago

residual-paranoia commented 2 years ago

example:protoc -I$GOPATH/src -I. --include_imports --include_source_info --descriptor_set_out=testdesc.pb testdesc.proto. Can load testdesc.pb file to generate FileDescriptor.

jhump commented 2 years ago

@residual-paranoia, yes, you can load the descriptors generated by protoc: https://pkg.go.dev/github.com/jhump/protoreflect/desc#CreateFileDescriptorsFromSet

First you'll unmarshal the file into a *descriptorpb.FileDescriptorSet (since the file contents are the binary encoding of this type). Then you can use the method above to process that into desc.FileDescriptor objects.