Skip to content

Conversation

@RaghavRoy145
Copy link
Contributor

@RaghavRoy145 RaghavRoy145 commented Mar 29, 2025

Motivation:

Existing get APIs require passing an explicit index and can be misused, leading to verbose and error-prone code. Adding peek variants that automatically use the current readerIndex improves safety and clarity. This aims to address #2034 and #2736, and is a continuation of PR #3157

Modifications:

  • Introduced peekBytes(), peekString(), peekNullTerminatedString(), peekUTF8ValidatedString() and peekDispatchData().
  • Added tests for each peek API covering normal, empty, repeated, and partial read scenarios.

Result:

Developers can now use nonmutating peek APIs to inspect ByteBuffer contents without altering the reader index.

PS: I have focussed on the ByteBuffer-aux get* implementations, so I'm not sure if I am missing any other important/error-prone get* elsewhere, if so, please point me to them and I'll be happy to add respective peek*'s!

Motivation:
Existing get APIs require passing an explicit index and can be misused, leading to verbose and error-prone code.
Adding peek variants that automatically use the current readerIndex improves safety and clarity.

Modifications:
- Introduced peekBytes(length:), peekString(length:), peekNullTerminatedString(), peekUTF8ValidatedString(length:) and peekDispatchData(length:).
- Added tests for each peek API covering normal, empty, repeated, and partial read scenarios.

Result:
Developers can now use nonmutating peek APIs to inspect ByteBuffer contents without altering the reader index.
@glbrntt glbrntt added the 🆕 semver/minor Adds new public API. label Mar 31, 2025
Copy link
Contributor

@glbrntt glbrntt left a comment

Choose a reason for hiding this comment

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

This looks great, thanks @RaghavRoy145!

@RaghavRoy145
Copy link
Contributor Author

This looks great, thanks @RaghavRoy145!

Thanks for the review! Do let me know if there's get methods that I may have missed. I know there's getData and getSlice for example, but if these are not part of the original plan, I can start working on Multiple Integer instead.

@glbrntt
Copy link
Contributor

glbrntt commented Mar 31, 2025

getData and getSlice are absolutely worth doing as well!

@RaghavRoy145
Copy link
Contributor Author

getData and getSlice are absolutely worth doing as well!

Great! Perhaps its better to create a new PR with the ones I find that are defined outside ByteBuffer-aux.

@glbrntt glbrntt merged commit 1d7a946 into apple:main Mar 31, 2025
41 of 42 checks passed
@RaghavRoy145 RaghavRoy145 deleted the peek-friends branch March 31, 2025 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🆕 semver/minor Adds new public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants