mirror of
https://github.com/apple/swift-nio
synced 2026-11-25 04:47:49 +00:00
### Motivation: The existing getInteger API is often used incorrectly, leading to verbose or error-prone code as mentioned in https://github.com/apple/swift-nio/issues/2034 and https://github.com/apple/swift-nio/issues/2736. Users may unintentionally access data without correctly managing the reader index. To address this, I added a peekInteger API that reads integers using the current readerIndex without modifying it. ### Modifications: * Added a peekInteger method to ByteBuffer, which provides a nonmutating way to read integers using the current readerIndex. * Implemented peekInteger using the existing getInteger function. * Added comprehensive unit tests to validate correct behavior, including scenarios for different integer types, insufficient bytes, and multi-write scenarios. ### Result: * Users now have access to a safer API for inspecting integers in a buffer without modifying state. * Added tests for integer reading scenarios. --------- Co-authored-by: George Barnett <gbarnett@apple.com>