-
Notifications
You must be signed in to change notification settings - Fork 380
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
Accessing custom MessageOptions #392
Comments
Should be However, the problem is that At the moment you can obtain |
Also, at the moment only bool options are implemented. Again, I'll fix it now. |
OK, master now support extensions: 0837187
Now I need to backport it to stable. |
Thanks @stepancheg for the really quick turnaround! I'll look at is later today and check it out. |
Just to follow up... I was able to create my custom boolean option and apply it to a message successfully! Thanks for the quick fix on this @stepancheg! Here is some generic code that I modelled my code after to check for the option. Protobuf definition
Rust code example
There may be a better "rust-ish" way of doing this but this appears to work for me. Hopefully this can help someone else down the line. |
API change suggestions are highly appreciated. But please note that that API changes won't be backported to the stable branch, and will be released on new major version.
As I said, string options should work too (in master). And a general comment. Extensions are not a very popular feature of protobuf, they are not even part of protobuf syntax version 3. That's why I was not in a hurry implementing them. |
Published a version 2.4.0. |
I have been attempting to figure out how to access custom MessageOptions in rust-protobuf. If we look at the protobuf documentation for Custom Options you see this example:
The documentation also show how to access this custom option using C++:
string value = MyMessage::descriptor()->options().GetExtension(my_option);
I have attempted to follow the same pattern using this library starting with something like the following:
let msg_desc = MyMessage::descriptor_static();
This gives me a
&'static protobuf::reflect::MessageDescriptor
and from here I'm lost. There is a privateproto
field inMessageDescriptor
which is of type&'static DescriptorProto
. TheDescriptorProto
struct has theoptions
field that appears to be what I'm after but I cannot access it sinceproto
is private.Where am I going wrong?
The text was updated successfully, but these errors were encountered: