Skip to content

Commit

Permalink
shame on me
Browse files Browse the repository at this point in the history
  • Loading branch information
nicarq committed Jul 2, 2016
1 parent 6f17513 commit b44b9fe
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Genome/Source/JsonConvertibleType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,24 @@ extension Int16 : JsonConvertibleType {}
extension Int32 : JsonConvertibleType {}
extension Int64 : JsonConvertibleType {}

extension Json {
public var longLongValue: CLongLong? {
guard case let .NumberValue(double) = self where double % 1 == 0 else {
return nil
}

return CLongLong(double)
}
}

extension SignedIntegerType {
public func jsonRepresentation() throws -> Json {
let double = Double(IntMax(self.toIntMax()))
return .from(double)
}

public static func newInstance(json: Json, context: Context = EmptyJson) throws -> Self {
guard let int = json.intValue else {
guard let int = json.longLongValue else {
throw logError(JsonConvertibleError.UnableToConvert(json: json, toType: "\(self)"))
}

Expand Down

0 comments on commit b44b9fe

Please sign in to comment.