Fix encoding error
This commit is contained in:
@ -2,12 +2,6 @@ import Foundation
|
||||
|
||||
extension Data {
|
||||
|
||||
func convert<T>(into value: T) -> T {
|
||||
withUnsafeBytes {
|
||||
$0.baseAddress!.load(as: T.self)
|
||||
}
|
||||
}
|
||||
|
||||
init<T>(from value: T) {
|
||||
var target = value
|
||||
self = Swift.withUnsafeBytes(of: &target) {
|
||||
|
@ -6,8 +6,8 @@ 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)
|
||||
init(bytes: [UInt8]) {
|
||||
let value = bytes.convert(to: UInt32.self)
|
||||
self = CFSwapInt32LittleToHost(value)
|
||||
}
|
||||
|
||||
|
12
Sesame/API/Extensions/UInt8+Extensions.swift
Normal file
12
Sesame/API/Extensions/UInt8+Extensions.swift
Normal file
@ -0,0 +1,12 @@
|
||||
import Foundation
|
||||
|
||||
extension Array where Element == UInt8 {
|
||||
|
||||
func convert<T>(to _: T.Type) -> T {
|
||||
withUnsafeBufferPointer {
|
||||
$0.baseAddress!.withMemoryRebound(to: T.self, capacity: 1) {
|
||||
$0.pointee
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user