19 lines
453 B
Swift
19 lines
453 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(data: Data) {
|
||
|
let value = data.convert(into: UInt32.zero)
|
||
|
self = CFSwapInt32LittleToHost(value)
|
||
|
}
|
||
|
|
||
|
/// The value encoded to a little-endian representation
|
||
|
var encoded: Data {
|
||
|
Data(from: CFSwapInt32HostToLittle(self))
|
||
|
}
|
||
|
}
|