-
Notifications
You must be signed in to change notification settings - Fork 23
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
Nim should allow getField(someObj, someField)
to access private fields; use case: custom serialization/deserialization
#106
Comments
getField(someObj, someField)
to access private fields; use case: custom serialization/deserializationgetField(someObj, someField)
to access private fields; use case: custom serialization/deserialization
It's not about "preventing access to secret data", many objects with hidden fields or that contain sockets etc cannot be serialized and so if the library doesn't allow for it explicitly, it's foolish to assume that you can just go ahead as long as Nim lets you access private fields. |
Note that objects with private fields cannot be For example |
Unless they declare their hash, of course. It is usually good practice in many programming languages to declare equality and hashing together (to ensure they are consistent), and if you have some hidden fields you probably have some custom notion of equality |
Rejected, you may as well cast it to a blob type for "serialization" that doesn't work reliably. |
fixed via scopable |
proposal
someObj.someField
would still be disallowed under this proposalgetField(someObj, someField)
would allow accessing any field (including private) from an objectnotes
repr(a) already allows showing private fields
nothing else I tried allows accessing (read or write) private fields, including
fields
andfieldPais
, eg:rationale
writing custom serialization/deserialization (and custom pretty printing, eg for debugging, display etc) requires access to all object fields, not just public ones. Without this we're limited to what a 3rd party library exposes, which makes it impossible to support custom serializers on types imported form those 3rd party libs, eg:
msgpack
protobuf
captain'proto
Bson (for mongo)
etc
in D, custom serialization/deserialization was the reason to allow this escape hatch.
(eg for D, I forked d-msgpack to allow serializing/deserializing arbitrary data, even in presence of subclasses, references with cycles etc; it'd be even easier in Nim once this
private
field access issue is resolvedbut what about safety / preventing access to secret data?
repr
allows that, or casting to another object, or using a hex editor / gdb etccast
etc)The text was updated successfully, but these errors were encountered: