You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fory.apache.org by "esafak (via GitHub)" <gi...@apache.org> on 2025/07/14 04:54:49 UTC
[PR] feat: Implement ObjectSerializer for custom objects [fory]
esafak opened a new pull request, #2413:
URL: https://github.com/apache/fory/pull/2413
## What does this PR do?
* Introduce ObjectSerializer to handle serialization of arbitrary Python objects. bjectSerializer serializes based on object's `__dict__` or `__slots__`.
* Update `_registry.py` to correctly identify and register ObjectSerializer.
## Related issues
Closes #2410
## Does this PR introduce any user-facing change?
- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
## Benchmark
Not done
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat: Implement ObjectSerializer for custom objects [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2413:
URL: https://github.com/apache/fory/pull/2413#discussion_r2203852005
##########
python/pyfory/serializer.py:
##########
@@ -497,10 +504,7 @@ def _gen_xread_method(self):
context[serializer_var] = self._serializers[index]
field_value = f"field_value{index}"
stmts.append(f"{field_value} = {fory}.xdeserialize_ref({buffer}, serializer={serializer_var})")
- if not self._has_slots:
- stmts.append(f"{obj_dict}['{field_name}'] = {field_value}")
- else:
- stmts.append(f"{obj}.{field_name} = {field_value}")
+ stmts.append(f"setattr({obj}, '{field_name}', {field_value})")
Review Comment:
The original stmts seems have better performance than `setattr`
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat: Implement ObjectSerializer for custom objects [fory]
Posted by "esafak (via GitHub)" <gi...@apache.org>.
esafak commented on code in PR #2413:
URL: https://github.com/apache/fory/pull/2413#discussion_r2203856859
##########
python/pyfory/serializer.py:
##########
@@ -497,10 +504,7 @@ def _gen_xread_method(self):
context[serializer_var] = self._serializers[index]
field_value = f"field_value{index}"
stmts.append(f"{field_value} = {fory}.xdeserialize_ref({buffer}, serializer={serializer_var})")
- if not self._has_slots:
- stmts.append(f"{obj_dict}['{field_name}'] = {field_value}")
- else:
- stmts.append(f"{obj}.{field_name} = {field_value}")
+ stmts.append(f"setattr({obj}, '{field_name}', {field_value})")
Review Comment:
I'll get rid of the setattr then
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat: Implement ObjectSerializer for custom objects [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang merged PR #2413:
URL: https://github.com/apache/fory/pull/2413
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat: Implement ObjectSerializer for custom objects [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2413:
URL: https://github.com/apache/fory/pull/2413#discussion_r2203955271
##########
python/pyfory/serializer.py:
##########
@@ -1178,6 +1188,45 @@ def read(self, buffer):
return self.fory.handle_unsupported_read(buffer)
+class ObjectSerializer(Serializer):
+ """Serializer for regular Python objects.
+ It serializes objects based on `__dict__` or `__slots__`.
+ """
+
+ def write(self, buffer, value):
+ field_names = []
+ if hasattr(value, "__slots__"):
Review Comment:
this check could be done in the `__init__`
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org