mirror of
https://github.com/apple/swift-nio
synced 2026-11-25 04:47:49 +00:00
### Motivation: Useful for parsing packets, for example `ipv4: InlineArray<4, UInt8>` and `ipv6: InlineArray<16, UInt8>`. ### Modifications: For now I've only added a `readInlineArray` function. I know some other functions are missing, such as `writeInlineArray`. I wanted to first open up a discussion and see if these changes are acceptable. I can add those functions too if required, in this PR or other PRs. ### Result: Users can read `ByteBuffer` into stack-allocated memory, which can be more performant than the other alternatives like `Array`, or more convenient than reading as a tuple like `(UInt8, UInt8, UInt8, UInt8)`. ### Caveats: Swift 6.2 is required so I've used `#if compiler(>=6.2)`. Furthermore, `InlineArray` is marked as available on `macOS(9999)` since the Swift team have yet to update that mark, although `InlineArray` is planned for Swift 6.2 per the [proposal](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0453-vector.md). Edit: to be clear things work fine on Linux and that's where I've been using this same `readInlineArray` function that I've proposed. --------- Co-authored-by: Cory Benfield <lukasa@apple.com>