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

serialize private fields #10

Open
extrawurst opened this issue Feb 9, 2016 · 5 comments
Open

serialize private fields #10

extrawurst opened this issue Feb 9, 2016 · 5 comments

Comments

@extrawurst
Copy link

Is it possible to serialize private fields of classes and structs ?

@extrawurst
Copy link
Author

ok i dug a bit deeper and found out __traits(derivedMembers..) and the like do not support accessing private fields, I had the same problem when i wanted to add private autowiring to the dependency injection framework poodinis. the solution as i found out using the irc is using T.tupleof. for reference the change in poodinis is here:
extrawurst/poodinis@7d2ba1b

@atilaneves
Copy link
Owner

tupleof doesn't work on classes though, the base classe's variables would be left out. There could be a static if for structs but that could be messy. I'll take a look but I don't know if anything can be done.

A workaround is to mark the private member @NoCereal and use postBlit, or accept to customize it and do it from the struct/class itself.

@atilaneves
Copy link
Owner

I just tried a little experiment with __traits(getAttributes) and tupleof and it doesn't seem to work. So using it would mean a lot of the functionality that cerealed provides would stop working.

@extrawurst
Copy link
Author

we had the same problem with the base classes in poodinis and it can be solved iterating over the base classes also at ct:
mbierlee/poodinis@f84b025

i am pretty sure what needs to be done can be done using tupleof and getAttributes, we do the same in poodinis:
https://github.com/mbierlee/poodinis/blob/master/source/poodinis/autowire.d#L124

or what is it exactly with __traits(getAttributes) that does not work with tupleof?

@atilaneves
Copy link
Owner

Ah, I see. Your example does it correctly by using T.tupleof[i] to get the attributes, I used the value instead of a type, which is why it didn't work. Makes sense.

Well, then it seems to be possible, but incredibly annoying and a lot work to do. Given that there's a workaround and I'm not terribly interested in supporting private fields, I'd be more than happy to accept patches, but I don't think I'll work on this myself.

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