Skip to content

feat(rust): add streaming deserialization support#3369

Open
Zakir032002 wants to merge 19 commits intoapache:mainfrom
Zakir032002:feat/rust-streaming-deserialization
Open

feat(rust): add streaming deserialization support#3369
Zakir032002 wants to merge 19 commits intoapache:mainfrom
Zakir032002:feat/rust-streaming-deserialization

Conversation

@Zakir032002
Copy link

Summary

Introduces streaming deserialization support for the Rust implementation of Fory, mirroring the C++ ForyInputStreamBuf model.

Changes

  • stream.rs — New ForyStreamBuf struct and Reader::from_stream for incremental stream-backed deserialization from any Read source
  • buffer.rs — Extended to support stream-backed buffer operations
  • fory.rs — Wired up stream reader support
  • lib.rs — Exported new stream module
  • stream_test.rs — Integration tests for stream deserialization

Design

Closes #3300

@Zakir032002 Zakir032002 marked this pull request as ready for review February 19, 2026 10:18
@Zakir032002
Copy link
Author

Hey @chaokunyang, Have a look at the implementation and let me know your reviews

@chaokunyang
Copy link
Collaborator

chaokunyang commented Feb 28, 2026

Hi @Zakir032002 , could you address the conflict?

@chaokunyang
Copy link
Collaborator

chaokunyang commented Mar 3, 2026

Please take #3307 as reference to finish the remaining works. And create a Deseralize help methods in tests, then use that instead of fory.Deserialize for deserialization, and in the Deseralize test helper, first deserialize from bytes, then wrap it into a OneByteStream to deserialize it to ensure deserialization works.

Then run benchmarks/rust to compare with asf/main to enure this pr doesn't introduce any performance regression.

Introduces ForyStreamBuf and Reader::from_stream for incremental
stream-backed deserialization from any Read source. Preserves
existing in-memory fast path with zero overhead.

Closes apache#3300
@Zakir032002 Zakir032002 force-pushed the feat/rust-streaming-deserialization branch from 18de059 to 78a59c7 Compare March 4, 2026 11:44
@chaokunyang
Copy link
Collaborator

Hi @Zakir032002 , Are you still working on this PR?

@Zakir032002
Copy link
Author

Zakir032002 commented Mar 5, 2026 via email

@Zakir032002 Zakir032002 force-pushed the feat/rust-streaming-deserialization branch from dc1c898 to 010ae68 Compare March 6, 2026 17:19
- fix reader attach/detach lifecycle in deserialize_from_stream
- isolate stream and in-memory paths in deserialize_from
- add struct round-trip test for reference parity with C++/Go
- fix clippy lints in stream_test.rs
- implement ForyStreamBuf stream buffer
- integrate Reader streaming support
- add OneByteStream tests for streaming validation
- add deserialize helper parity tests
- fix varuint64 streaming decode to match C++ implementation
- add sequential stream decoding tests
- validate truncated stream error behavior
- add overflow guard in ensure_readable
- propagate set_reader_index failure in fill_to
- remove dead shrink_buffer call in deserialize_from_stream
- clarify varuint64 stream decoding comment
- Add stream_reader_index() and stream_remaining() public accessors to Reader
- Fix unused Result warnings in test_fory.rs and test_buffer.rs
- Apply rustfmt formatting to test_stream.rs
…alize_check helper

Updated 13 test files to use the centralized deserialize_check helper
which verifies deserialization through both in-memory and stream-backed
paths (including byte-at-a-time OneByte stress testing), asserting
identical results.

Files updated:
- test_simple_struct, test_complex_struct, test_ext, test_list, test_map
- test_tuple (29 calls), test_tuple_struct (19 calls), test_enum (6 calls)
- test_collection (2 calls), test_complex_refs (5 calls)
- test_rc_arc (21 calls), test_box (10 calls)
- mod.rs: removed test_tuple/test_collection as submodules (standalone)
- test_helpers.rs: OneByte wrapper + deserialize_check helper

Exceptions (kept as fory.deserialize):
- Schema evolution tests (different serialize/deserialize types)
- BinaryHeap tests (no PartialEq)
- test_any tests (dyn Any types)
- test_stream.rs (has its own stream-specific helpers)

All tests pass, clippy clean, fmt clean.
@Zakir032002
Copy link
Author

Hey @chaokunyang, have added helper , and tell me if you need any changes, do you want me to change every call site of fory.deserialize(_) with the helper?

@chaokunyang
Copy link
Collaborator

@Zakir032002 Are you still working on this PR? If not, I will close this PR. Other pull requests rely on this pr got merged to continue their work. For example, https://github.com/apache/fory/pull/3483/changes

/// # Buffer size limit
/// The internal buffer is capped at `u32::MAX` bytes (~4 GiB).
/// Requesting more than this returns [`Error::buffer_out_of_bound`].
pub struct ForyStreamBuf {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fory C++ don't use ForyStreamBuf, please align with Fory C++ instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Rust] Streaming Deserialization Support For Rust

2 participants