Skip to content

Commit c72516d

Browse files
authored
Use Int(exactly:) instead of restricting to 64 bit platforms (#267)
1 parent 33fc957 commit c72516d

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

Sources/PostgresNIO/Data/PostgresData+Int.swift

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
extension PostgresData {
22
public init(int value: Int) {
3-
assert(Int.bitWidth == 64)
4-
self.init(type: .int8, value: .init(integer: value))
3+
self.init(type: .int8, value: .init(integer: Int64(value)))
54
}
65

76
public init(uint8 value: UInt8) {
@@ -32,25 +31,19 @@ extension PostgresData {
3231
guard value.readableBytes == 1 else {
3332
return nil
3433
}
35-
return value.readInteger(as: UInt8.self)
36-
.flatMap(Int.init)
34+
return value.readInteger(as: UInt8.self).flatMap(Int.init)
3735
case .int2:
3836
assert(value.readableBytes == 2)
39-
return value.readInteger(as: Int16.self)
40-
.flatMap(Int.init)
37+
return value.readInteger(as: Int16.self).flatMap(Int.init)
4138
case .int4, .regproc:
4239
assert(value.readableBytes == 4)
43-
return value.readInteger(as: Int32.self)
44-
.flatMap(Int.init)
40+
return value.readInteger(as: Int32.self).flatMap(Int.init)
4541
case .oid:
4642
assert(value.readableBytes == 4)
47-
assert(Int.bitWidth == 64) // or else overflow is possible
48-
return value.readInteger(as: UInt32.self)
49-
.flatMap(Int.init)
43+
return value.readInteger(as: UInt32.self).flatMap { Int(exactly: $0) }
5044
case .int8:
5145
assert(value.readableBytes == 8)
52-
assert(Int.bitWidth == 64)
53-
return value.readInteger(as: Int.self)
46+
return value.readInteger(as: Int64.self).flatMap { Int(exactly: $0) }
5447
default:
5548
return nil
5649
}

0 commit comments

Comments
 (0)