-
Notifications
You must be signed in to change notification settings - Fork 533
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
Is there some way of getting a fields tag from its name? #137
Comments
No, currently the mapping of fields to tag numbers isn’t exposed. Can you expand on why you would want to do this? I’ve never had a need to work with tags directly. |
I use the tags for field permission management. I have a broker which can be configured to block messages with certain fields set. And the broker is configured with protobuf. I cannot think of any other way to programatically refer to fields. |
That’s an interesting usecase, thanks. If I were solving that with the upstream C++ library I’d probably use a custom annotation in the .proto along with a code generator plugin. Unfortunately prost doesn’t allow custom code gen plugins or hooks at the moment, and there’s no way to work with generic messages and schemes, so I don’t know of a synonymous way to do this. An alternative is to manually implement a trait for your message types which would hold the filtering logic, but then it’s obviously configured through rust source code instead of the .proto. |
@danburkert It shouldn't be necessary to modify the
I expected that something similar to golang's reflection would exist in rust for just this kind of problem, but it seems that is not the case: https://stackoverflow.com/questions/54573185/how-do-i-read-attributes-programatically-in-rust/54578601?noredirect=1#comment95957359_54578601 Would you accept a PR which appended to the generated code output a simple traversable data-structure which would include this metadata? |
Re-reading your comment it appears to me that you misunderstood what I meant by "Configured with protobuf". What I meant, is that a list or map of disallowed field tags is set over the wire to the broker in protobuf format. Not that the broker is configured in a |
I would also like this feature. I have a oneof enum with one field per API call. I also keep a list of field tag numbers of which api calls are currently legal and compare against it when an API call is made. |
I'd like to be able to write something like
Rather than writing the numbers directly into my code in places.
The text was updated successfully, but these errors were encountered: