-
-
Notifications
You must be signed in to change notification settings - Fork 459
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
[meta] Automatic opaque serialization #1409
base: master
Are you sure you want to change the base?
Conversation
d0c0e34
to
335bd9d
Compare
335bd9d
to
4a4fa0e
Compare
Similar to my comment on the other PR- I'm not sure how this works if you have a type with multiple members. I don't think the edge case of a type with a single member warrants extending the interface. |
I think perhaps my example here is misunderstood. You should not be looking at the fact that the opaque implementation happens to be a struct with just one member, because it is an opaque. It could be anything. I put a struct to make it a simple example. This opaque is saying, as per the example, that wants to be considered as a The same way, the Think of cursors. You should be able to read and write with them, not only write. When the cursor is pointing to an opaque, you should be able to read and write to it too as if it wasn't an opaque, because for what it is worth, that opaque has to behave as the When a type has multiple members, you mean the This PR is not as important as the other two; I would consider it optional. I wrote this one because I found interesting that using reflection itself and the new Again, the key background to properly understand the context of this set of contributions is here: |
fix const string serializer
bake --strict
4a4fa0e
to
723af5c
Compare
Note: must merge #1405 first
This PR builds on the previous two to add automatic opaque serialization for those opaques defining the appropriate
get_*
callbacks.When defining serialization for an opaque, you have to define a
serialize
callback. If this callback is not defined, serialization will fail.With this change, when a
serialize
callback is not defined, themeta
module will try to find a way to serialize the opaque if the opaque has defined another callback that can be used.This is useful if you have already defined a
get_
callback that does the work and don't want to define a serializer.If you do define a serializer, the serializer takes precedence and it is used as before.
For example:
It is still recommended to write a serializer if what you are doing with the type is to fully serialize it to JSON or something similar.
If, however, you are using reflection to access portions of opaque data randomly, the serializer could be slower/inefficient because it dumps the whole content, whereas the
get_
callbacks provide the opaque with a way to go straight to the requested data.For example, the following will now work without a serializer: