esafak commented on PR #2384:
URL: https://github.com/apache/fory/pull/2384#issuecomment-3041917723
How about this plan?
1. Define two new serializers:
- A "Stateful Serializer" for objects that support __getstate__ and
__setstate__.
- A "Reduce Serializer" for objects that implement __reduce__ or
__reduce_ex__.
2. For objects with __getstate__/__setstate__:
- In the serialization function, check if both methods are available.
- If yes, call __getstate__ to obtain the object state and then serialize
that state using Fory's native methods.
- For deserialization, create a new instance without calling __init__,
then use the deserialized state with __setstate__.
3. For objects with __reduce__/__reduce_ex__:
- Detect if these methods exist and give them higher precedence over
__getstate__/__setstate__.
- Support basic cases where __reduce__ returns either just a global name
or a tuple (callable, args).
- Extend to handle objects that include state or more complex information
(like iterators or custom functions).
4. For handling constructors (especially for immutable types):
- Check for __getnewargs_ex__ or __getnewargs__ during instance creation.
- Serialize the constructor arguments so that during deserialization, the
new instance is created with the correct arguments.
5. Testing & Backwards Compatibility:
- Implement incremental tests to cover each serialization case (basic
state, __reduce__ cases, and __getnewargs*__ cases).
- Ensure that existing functionality still falls back to the Python
pickle behavior when necessary, but aim to use Fory’s native XLANG format for
better cross-language support and performance.
In short, the idea is to leverage Fory’s native serialization for objects
that support customization, gradually replacing pickle's behavior with a more
transparent and cross-language-friendly approach while maintaining
compatibility with edge cases.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]