[meta] Automatic opaque serialization #1409
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: