square / wire

gRPC and protocol buffers for Android, Kotlin, Swift and Java.
https://square.github.io/wire/
Apache License 2.0
4.23k stars 572 forks source link

Accept binary DescriptorProto as input #2940

Open Maragues opened 3 months ago

Maragues commented 3 months ago

I would like to use a binary DescriptorProto as input to sourcePath or protoPath

wire {
    sourcePath {
        srcDir("my/dir")
        include("first_file.pb")
    }
}

Where first_file.pb is a serialized DescriptorProto.

I checked Wire's source code and I don't think there's a way to do this right now. ProtoParser expects .proto, and unfortunately protobuf-java does not support generating .proto files.

Since Wire can generate protobuf-compatible binary files, maybe it isn't too hard to accept binary as input too?

To expand on my use case, I receive a serialized FileDescriptorSet as input. On protoc, the call to generate code would be

protoc ... --descriptor_set_in=path/data_models.pb first_file_name.proto second_file_name.proto

Where first_file_name.proto and second_file_name.proto are DescriptorProto in data_models.pb, a FileDescriptorSet. When protoc doesn't find a .proto file in the filesystem, it looks if it exists in any of the descriptor_set_in parameters. If there's a FileDescriptorProto with that name, it generates the code.

Thanks!

oldergod commented 3 months ago

There is indeed no way to do that right now. And although we have a SchemaEncoder which can somewhat encode a schema into protobuf's descriptor.proto, there's nothing to decode it. It's unlikely that we implement something like that before a while unfortunately.

Maragues commented 3 months ago

Thanks for the reply. I understand this is a specific need of mine.

oldergod commented 3 months ago

No way for your source to expose .proto. files?

Maragues commented 3 months ago

Long story short, a subset of our proto messages are not defined in .proto files.

Our source of truth is a proto message in protobuf text format. We digest that message and produce N binary files of protobuf types, which are then fed to different platforms for code generation.