stepancheg / rust-protobuf

Rust implementation of Google protocol buffers
MIT License
2.81k stars 382 forks source link

Hook Service Generation #667

Closed AThilenius closed 1 year ago

AThilenius commented 1 year ago

Thank you so much for your work on this library, it's really wonderful!

I want to use it to implement the Connect-Web RPC schema on top of Axum. To do that I need to generate code for each service definition, alongside the already generated message types. I see the reflection API which is quite easy to use, and I see the customization callback API, but it doesn't do anything with file/before customization, like this:

struct ServiceGenerator;

impl CustomizeCallback for ServiceGenerator {
    fn file(&self, _file: &FileDescriptor) -> Customize {
        Customize::default().before("THIS IS NEVER ADDED TO THE FILE")
    }
}

I'm happy to PR a change for this if I am correct in reading that it's not yet supported? I'm not sure it fits the current customization API super well though. Maybe it would fit better if service customization was added even though no code is generated for them by default? I can hack around it for now by just reopening the generated files and using the reflection API to gen code at the end of the file, but would also happily contribute support here.

AThilenius commented 1 year ago

I endued up somewhat hackily working my way around it: https://github.com/AThilenius/axum-connect/blob/main/axum-connect-build/src/lib.rs

Gonna mark this as closed.