Skip to content

Add non-consuming fetch and buffer access to IOBufCutter - #3686

Open
altman08 wants to merge 1 commit into
apache:masterfrom
altman08:dev
Open

altman08 wants to merge 1 commit into
apache:masterfrom
altman08:dev

Conversation

@altman08

@altman08 altman08 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: N/A

Problem Summary:

IOBufCutter can peek at only one byte with fetch1(). Parsers that need to inspect multiple bytes before consuming them lack an API that respects the cutter’s current position. Reading directly from the underlying IOBuf may include bytes already consumed by the cutter.

What is changed and the side effects?

Changed:

  • Add IOBufCutter::fetch(void*, size_t) const to peek at multiple bytes without advancing the cursor.
    • Return a direct pointer when the requested bytes are contiguous, including immediately after exhausting the current block.
    • Copy into the auxiliary buffer when the requested bytes span blocks.
    • Return nullptr on insufficient data without modifying the auxiliary buffer.
    • Return the auxiliary buffer directly for zero-length requests.
  • Add buf() to expose a const reference to the underlying IOBuf without synchronizing the cursor.
  • Add tests covering empty buffers, appended data, block boundaries, insufficient data, and cursor preservation.

Side effects:

  • Performance effects: Contiguous reads avoid copying; reads spanning blocks copy the requested bytes. No performance benchmark was run.
  • Breaking backward compatibility: None. The new methods are additive and do not change existing APIs or object layout.

Check List:

  • Compiled the updated IOBuf implementation and tests using existing build dependencies.
  • Added related tests; all 60 IOBuf non-performance tests passed.
  • Passed whitespace checks with git diff --cached --check.
  • Please follow Contributor Covenant Code of Conduct.

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.

1 participant