Skip to content

Comments

feat(buffer): add chunk iterator for Buffer#6672

Merged
Xuanwo merged 1 commit intoapache:mainfrom
TennyZhuang:feat-buffer-chunks
Oct 15, 2025
Merged

feat(buffer): add chunk iterator for Buffer#6672
Xuanwo merged 1 commit intoapache:mainfrom
TennyZhuang:feat-buffer-chunks

Conversation

@TennyZhuang
Copy link
Contributor

Which issue does this PR close?

Closes #6520.

Rationale for this change

Splitting Buffer values into fixed-size chunks currently requires copying into Vec<u8> or Bytes. Adding a chunk iterator exposes an ergonomic, zero-copy approach to splitting contiguous and non-contiguous buffers, matching the use cases raised in #6520.

What changes are included in this PR?

  • Introduce BufferChunks plus a Buffer::chunks helper that yield sub-buffers sharing the underlying storage.
  • Implement iterator traits (ExactSizeIterator, FusedIterator) with accurate size hints for predictable iteration.
  • Add unit tests covering contiguous, non-contiguous, and zero-size chunk scenarios.

Are there any user-facing changes?

New optional API Buffer::chunks; existing behavior is unchanged.

@TennyZhuang TennyZhuang requested a review from Xuanwo as a code owner October 15, 2025 12:56
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. releases-note/feat The PR implements a new feature or has a title that begins with "feat" labels Oct 15, 2025
Copy link
Member

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

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

Others LGTM, thank you!

Copy link
Member

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

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

Thank you for working on this!

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 15, 2025
@Xuanwo Xuanwo merged commit 1bcff4e into apache:main Oct 15, 2025
340 of 342 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer releases-note/feat The PR implements a new feature or has a title that begins with "feat" size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

new feature: support split Buffer into chunks

2 participants