Sesame-Server/Sources/App/API/Extensions/Data+Coding.swift

18 lines
314 B
Swift
Raw Permalink Normal View History

2023-12-08 12:39:10 +01:00
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) {
Data($0)
}
}
}