protocolbuffers / protobuf

Protocol Buffers - Google's data interchange format
http://protobuf.dev
Other
65.78k stars 15.51k forks source link

Add a way to convert `descriptorpb.FileDescriptorProto` to .proto file #8430

Closed xinnjie closed 3 years ago

xinnjie commented 3 years ago

What language does this apply to? If it's a proto syntax change, is it for proto2 or proto3? proto3 If it's about generated code change, what programming language? no

Describe the problem you are trying to solve. Our team has a tool to convert excel (has specific struct )to .proto. After analyze the structure, currently we just use "fmt.print" style to get a .proto . Better way may be construct descriptorpb.FileDescriptorProto, and let protolib do the rest staff.

Describe the solution you'd like Add a function input the descriptorpb.FileDescriptorProto and return the proto file content. This functionaily may help many tool that adjust content of .proto file Describe alternatives you've considered

Additional context Add any other context or screenshots about the feature request here.

haberman commented 3 years ago

In C++ the FileDescriptorProto::DebugString() function will do what you want:

https://github.com/protocolbuffers/protobuf/blob/049e05f0527d2211abd765715ea0a4927eb3cb99/src/google/protobuf/descriptor.h#L1528-L1529

I do not believe the same functionality exists in Java.