1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-28 02:54:31 +03:00
This commit is contained in:
Tae Won Ha 2020-12-10 21:47:25 +01:00
parent 5afb0cf9e1
commit 87436c1057
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44

View File

@ -7,33 +7,29 @@ import Foundation
import MessagePack
extension MessagePackValue {
var intValue: Int? {
guard let i64 = self.int64Value else {
return nil
}
guard let i64 = self.int64Value else { return nil }
return Int(i64)
}
}
class MessagePackUtils {
enum MessagePackUtils {
static func value<T>(from data: Data?, conversion: (MessagePackValue) -> T?) -> T? {
guard let d = data else { return nil }
do {
return conversion(try unpack(d).value)
} catch {
return nil
}
do { return conversion(try unpack(d).value) }
catch { return nil }
}
static func value<T>(from v: MessagePackValue, conversion: (MessagePackValue) -> T?) -> T? {
return conversion(v)
conversion(v)
}
static func array<T>(from value: MessagePackValue, ofSize size: Int, conversion: (MessagePackValue) -> T?) -> [T]? {
static func array<T>(
from value: MessagePackValue, ofSize size: Int,
conversion: (MessagePackValue) -> T?
) -> [T]? {
guard let array = value.arrayValue else { return nil }
guard array.count == size else { return nil }
@ -43,10 +39,7 @@ class MessagePackUtils {
static func value(from data: Data?) -> MessagePackValue? {
guard let d = data else { return nil }
do {
return try unpack(d).value
} catch {
return nil
}
do { return try unpack(d).value }
catch { return nil }
}
}