2022-04-28 23:19:44 +02:00
|
|
|
import Foundation
|
|
|
|
|
|
|
|
extension UInt32 {
|
|
|
|
|
|
|
|
/**
|
|
|
|
Create a value from a little-endian data representation (MSB first)
|
|
|
|
- Note: The data must contain exactly four bytes.
|
|
|
|
*/
|
2023-12-20 09:25:53 +01:00
|
|
|
init(bytes: [UInt8]) {
|
|
|
|
let value = bytes.convert(to: UInt32.self)
|
2022-04-28 23:19:44 +02:00
|
|
|
self = CFSwapInt32LittleToHost(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The value encoded to a little-endian representation
|
|
|
|
var encoded: Data {
|
|
|
|
Data(from: CFSwapInt32HostToLittle(self))
|
|
|
|
}
|
2023-12-12 17:33:42 +01:00
|
|
|
|
|
|
|
/// The size of a `UInt32` when converted to data
|
|
|
|
static let byteSize = MemoryLayout<UInt32>.size
|
2022-04-28 23:19:44 +02:00
|
|
|
}
|