prost
prost copied to clipboard
Expose an API to consume `FileDescriptorProto`s
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.
Hi @Plecra! You can use the prost-types crate for this - it has a FileDescriptorProto type which can be parsed in the normal way.
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)
Ah, I see! Sorry, I misunderstood the aim here.
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?
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
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.
I think this is possible with the current prost_build API by:
- Create a
FileDescriptorSetfrom theFileDescriptorProtoinstances - Write it to a temporary file
- Set
file_descriptor_set_pathandskip_proto_runto haveprost_builduse the file descriptors