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

Reflection to get mutable message #407

Closed
shadowng opened this issue Apr 15, 2019 · 5 comments
Closed

Reflection to get mutable message #407

shadowng opened this issue Apr 15, 2019 · 5 comments

Comments

@shadowng
Copy link

Hello,

In "protobuf::reflect::FieldDescriptor", the function "pub fn mut_message<'a>(&self, _m: &'a mut Message) -> &'a mut Message" is not yet implemented. Could you please let us know if you have any plan to implement it? if not, is there any work-around?
I'd like to use reflection to set all fields in a Message to its default value (traverse the message and use get_singular_field_or_default() on FieldDescriptor).

Thank you very much,
C

@stepancheg
Copy link
Owner

It is implemented in master. But it is not possible (or very hard) to backport it to the stable version without breaking backwards compatibility.

It will be released in the next major version (3).

I think next major version will be released in a couple months.

JFYI, before releasing next major version I'd like to fix this: #339 But I don't know how to fix it.

I'd like to use reflection to set all fields in a Message to its default value

Why? Maybe you simply want to use syntax = "proto3" where fields have no flag, and initialized to zero.

@shadowng
Copy link
Author

Thanks for your help. I'm using Master branch, but I still see "unimplemented!()" (protobuf\src\reflect\field.rs line 170).

@stepancheg stepancheg reopened this Apr 16, 2019
@stepancheg
Copy link
Owner

Looking...

@stepancheg
Copy link
Owner

My bad.

You can now do get_message(), clone it, modify it, and then call set_singular_field(). Obviously, it would be somewhat expensive.

Looking how hard would it be to implement mut_message.

@stepancheg
Copy link
Owner

stepancheg commented Apr 16, 2019

Implemented in 3d532dd.

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