22 lines
567 B
Swift
22 lines
567 B
Swift
import Foundation
|
|
|
|
extension UInt32 {
|
|
|
|
/**
|
|
Create a value from a little-endian data representation (MSB first)
|
|
- Note: The data must contain exactly four bytes.
|
|
*/
|
|
init(bytes: [UInt8]) {
|
|
let value = bytes.convert(to: UInt32.self)
|
|
self = CFSwapInt32LittleToHost(value)
|
|
}
|
|
|
|
/// The value encoded to a little-endian representation
|
|
var encoded: Data {
|
|
Data(from: CFSwapInt32HostToLittle(self))
|
|
}
|
|
|
|
/// The size of a `UInt32` when converted to data
|
|
static let byteSize = MemoryLayout<UInt32>.size
|
|
}
|