Feature Request
Add Python stream deserialization support by reusing C++ stream-backed Buffer behavior.
Is your feature request related to a problem? Please describe
Current Python workflows usually deserialize from bytes/Buffer. For transport streams, users need extra buffering/framing glue.
Design update (based on PR #3307)
Reference: #3307
- API shape
- Keep existing
Fory.deserialize(...) API unchanged.
- Support stream input through
Buffer(stream_obj) where stream_obj provides read(size).
- No new
deserialize_from_stream(...) API required in this phase.
- C++ bridge
- Add
Fory_PyCreateBufferFromStream in cpp/fory/python/pyfory.cc.
- Bridge adapts Python stream
read(size) into C++ std::istream and constructs stream-backed fory::Buffer.
- Buffer integration
- In
python/pyfory/buffer.pyx, constructor detects stream-like objects and creates a stream-backed buffer.
- Bound checks/reads use C++
ensure_size to fetch more bytes on demand.
- Behavior model
- Sequential objects are decoded by reusing the same
Buffer(stream) instance.
- No seek/tell rewind requirement in this design.
- Mode compatibility
- Shared
Buffer behavior is used by existing deserialize paths and validated for xlang/native modes.
- Cython path is explicitly covered by new tests; semantics remain aligned for existing API usage.
- Tests
- Add Python tests for:
- stream-backed primitive and string reads,
- tiny fragmented stream reads,
- sequential multi-object decode,
- truncated stream failure.
Describe alternatives you've considered
- Python-only stream loop that materializes bytes before decode.
- New dedicated Python stream deserialize API in this phase.
Additional context
Relevant files (PR #3307):
python/pyfory/buffer.pyx
python/pyfory/includes/libpyfory.pxd
python/pyfory/tests/test_buffer.py
python/pyfory/tests/test_stream.py
cpp/fory/python/pyfory.cc
Feature Request
Add Python stream deserialization support by reusing C++ stream-backed
Bufferbehavior.Is your feature request related to a problem? Please describe
Current Python workflows usually deserialize from
bytes/Buffer. For transport streams, users need extra buffering/framing glue.Design update (based on PR #3307)
Reference: #3307
Fory.deserialize(...)API unchanged.Buffer(stream_obj)wherestream_objprovidesread(size).deserialize_from_stream(...)API required in this phase.Fory_PyCreateBufferFromStreamincpp/fory/python/pyfory.cc.read(size)into C++std::istreamand constructs stream-backedfory::Buffer.python/pyfory/buffer.pyx, constructor detects stream-like objects and creates a stream-backed buffer.ensure_sizeto fetch more bytes on demand.Buffer(stream)instance.Bufferbehavior is used by existing deserialize paths and validated for xlang/native modes.Describe alternatives you've considered
Additional context
Relevant files (PR #3307):
python/pyfory/buffer.pyxpython/pyfory/includes/libpyfory.pxdpython/pyfory/tests/test_buffer.pypython/pyfory/tests/test_stream.pycpp/fory/python/pyfory.cc