mirror of
https://github.com/apple/swift-nio
synced 2026-11-27 05:04:22 +00:00
### Motivation: Makes it possible to make integers out of ByteBuffers directly with an initializer. I.e. `UInt32(buffer: ByteBuffer(bytes: [0, 1, 2, 3]))`. Closes #3012. ### Modifications: - Adds the `Int(buffer:)` initializer in `ByteBuffer-int.swift` - Adds tests in `ByteBufferTest.swift`. _Holy hell this file is huge._ - Note that `Int(buffer:)` will crash if the buffer does not have enough bytes in it to represent the desired integer type. - It also does _not_ expose endianness and uses `Endianness.host`, to keep the public API clean and simple. It's a convenience initializer, so I thought keeping it minimal is a good idea. ### Result: Nicer direct initializer for integers from ByteBuffers. --------- Co-authored-by: Johannes Weiss <johannesweiss@apple.com> Co-authored-by: Cory Benfield <lukasa@apple.com>