prost icon indicating copy to clipboard operation
prost copied to clipboard

Expose an API to consume `FileDescriptorProto`s

Open Plecra opened this issue 5 years ago • 7 comments

I have a collection of FileDescriptorProtos that I have decoded from a protobuf stream. I want to generate Rust code capable of parsing them, but there doesn't seem to be any public API for this.

I think I want the prost_build::Config::generate method in the public api.

Plecra avatar May 29 '20 10:05 Plecra

Hi @Plecra! You can use the prost-types crate for this - it has a FileDescriptorProto type which can be parsed in the normal way.

jen20 avatar Jul 07 '20 00:07 jen20

I'd actually already managed to decode a prost_type::FileDescriptorProto :) My problem is that I'm not really able to do anything with it.

Ultimately, I want to generate a rust crate capable of consuming the types in the FileDescriptorProtos, but I'd have to rewrite the code from the generate method to do that (or practically, fork the crate)

Plecra avatar Jul 08 '20 08:07 Plecra

Ah, I see! Sorry, I misunderstood the aim here.

jen20 avatar Jul 10 '20 16:07 jen20

I don't understand the request, @Plecra could you add more details about what functionality you would like? Is this something you could do in your own crate?

danburkert avatar Dec 27 '20 15:12 danburkert

prost_build::Config::compile_protos can be used to compile .proto files to rust code that can consume them - in my crate, I want to compile FileDescriptorProtos to rust code. For this, I need to call the prost_build::Config::generate function directly with the FileDescriptorProtos I have. My request is for it to be made a pub fn

Plecra avatar Dec 28 '20 18:12 Plecra

Ah I see. At this time prost-build is exclusively meant to be used from build.rs's. I'd like to have a more thought out public API for niche usecases to build off, but it hasn't been top priority.

danburkert avatar Dec 31 '20 20:12 danburkert

I think this is possible with the current prost_build API by:

andrewhickman avatar Jan 18 '22 01:01 andrewhickman