mirror of
https://github.com/apple/swift-nio
synced 2026-11-29 05:24:21 +00:00
### 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 https://github.com/apple/swift-nio/issues/2034 and https://github.com/apple/swift-nio/issues/2736, and is a continuation of PR https://github.com/apple/swift-nio/pull/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!*