Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prost_build::compile_protos could return information on the generated files #116

Open
Moxinilian opened this issue Jul 11, 2018 · 1 comment

Comments

@Moxinilian
Copy link

Moxinilian commented Jul 11, 2018

Hello.
I am writing a wrapper library for a networking protocol that uses protobuf.
Among the wrapping I do, I want to make the interface backend-agnostic, and add IDs automatically attributed to all message types.
However, I find the task unnecessary difficult: adding the automated IDs requires me to parse prost_build's output, and juggle with modules.

The task would be much easier if prost_build::compile_protos returned information on what it built, most notably the message's names, as with that it is easy to generate code that will implement a custom trait on those structs.

@danburkert
Copy link
Collaborator

danburkert commented Jul 29, 2018

protoc has a concept of plugins which can be used for inserting snippets into the generated code. See https://developers.google.com/protocol-buffers/docs/reference/other for more info. prost doesn't have support for that type of plugin at this point. For protobuf services there is the ServiceGenerator API, though.

That being said, I think a better solution to this is not to add hooks deep into prost code generation, but instead see if you could solve it by creating your own custom derive implementation and annotating the prost generated messages with a derive annotation via type_attribute. This has the considerable upside that you can annotate any struct, not just prost-generated types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants