added iOS source code
[wl-app.git] / iOS / Pods / OAuthSwift / Sources / Int+OAuthSwift.swift
diff --git a/iOS/Pods/OAuthSwift/Sources/Int+OAuthSwift.swift b/iOS/Pods/OAuthSwift/Sources/Int+OAuthSwift.swift
new file mode 100644 (file)
index 0000000..022aff2
--- /dev/null
@@ -0,0 +1,33 @@
+//
+//  Int+OAuthSwift.swift
+//  OAuthSwift
+//
+//  Created by Dongri Jin on 1/28/15.
+//  Copyright (c) 2015 Dongri Jin. All rights reserved.
+//
+
+import Foundation
+
+extension Int {
+    public func bytes(_ totalBytes: Int = MemoryLayout<Int>.size) -> [UInt8] {
+        return arrayOfBytes(self, length: totalBytes)
+    }
+}
+
+private func arrayOfBytes<T>(_ value: T, length: Int? = nil) -> [UInt8] {
+    let totalBytes = length ?? MemoryLayout<T>.size
+
+    let valuePointer = UnsafeMutablePointer<T>.allocate(capacity: 1)
+    valuePointer.pointee = value
+
+    let bytesPointer = UnsafeMutablePointer<UInt8>(OpaquePointer(valuePointer))
+    var bytes = [UInt8](repeating: 0, count: totalBytes)
+    for j in 0..<min(MemoryLayout<T>.size, totalBytes) {
+        bytes[totalBytes - 1 - j] = (bytesPointer + j).pointee
+    }
+
+    valuePointer.deinitialize(count: 1)
+    valuePointer.deallocate()
+
+    return bytes
+}