Add `InlineArray` helpers to `ByteBuffer`
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.
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.
I'd highly assume a 6.2 snapshot with InlineArray available on macOS would be released before the WWDC. We can wait till then just so the PR is not "weird" in the sense that it works on Linux and not Darwin. We can also merge this and I'll modify the availability checks in another PR as soon as I can confirm the 6.2 macOS snapshots have InlineArray available.
@MahdiBM and @Lukasa is this ready for prime time?
I'l need to add the availability annotations and we should be good. Currently on a mini vacation, I'll see if I find some spare time to do this.
@Lukasa Review please 🙂.
@Lukasa anything I can help with? 🙂
No, this got delayed because of the CI hiccups that caused the prior two jobs to fail.