Skip to content

Commit 1238e81

Browse files
committed
fix: remove Int128 and UInt128 on Linux
1 parent 2e2eb5e commit 1238e81

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

Sources/ReerJSON/JSONDecoderImpl.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,12 @@ extension JSONDecoderImpl: SingleValueDecodingContainer {
393393
try decodeInteger()
394394
}
395395

396+
#if !os(Linux)
396397
@available(macOS 15.0, iOS 18.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *)
397398
func decode(_: Int128.Type) throws -> Int128 {
398399
try decodeInteger()
399400
}
401+
#endif
400402

401403
func decode(_: UInt.Type) throws -> UInt {
402404
try decodeInteger()
@@ -418,10 +420,12 @@ extension JSONDecoderImpl: SingleValueDecodingContainer {
418420
try decodeInteger()
419421
}
420422

423+
#if !os(Linux)
421424
@available(macOS 15.0, iOS 18.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *)
422425
func decode(_: UInt128.Type) throws -> UInt128 {
423426
try decodeInteger()
424427
}
428+
#endif
425429

426430
func decode<T: Decodable>(_ type: T.Type) throws -> T {
427431
return try unbox(topValue, as: type, for: codingPathNode, _CodingKey?.none)
@@ -603,13 +607,15 @@ private final class DefaultKeyedContainer<K: CodingKey>: KeyedDecodingContainerP
603607
let jsonValue = try getValue(forKey: key)
604608
return try decodeInteger(jsonValue, forKey: key)
605609
}
606-
610+
611+
#if !os(Linux)
607612
@available(macOS 15.0, iOS 18.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *)
608613
func decode(_: Int128.Type, forKey key: K) throws -> Int128 {
609614
let jsonValue = try getValue(forKey: key)
610615
return try decodeInteger(jsonValue, forKey: key)
611616
}
612-
617+
#endif
618+
613619
func decodeIfPresent(_: Int64.Type, forKey key: K) throws -> Int64? {
614620
guard let jsonValue = getValueIfPresent(forKey: key) else {
615621
return nil
@@ -670,11 +676,13 @@ private final class DefaultKeyedContainer<K: CodingKey>: KeyedDecodingContainerP
670676
return try decodeInteger(jsonValue, forKey: key)
671677
}
672678

679+
#if !os(Linux)
673680
@available(macOS 15.0, iOS 18.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *)
674681
func decode(_: UInt128.Type, forKey key: K) throws -> UInt128 {
675682
let jsonValue = try getValue(forKey: key)
676683
return try decodeInteger(jsonValue, forKey: key)
677684
}
685+
#endif
678686

679687
func decodeIfPresent(_: UInt64.Type, forKey key: K) throws -> UInt64? {
680688
guard let jsonValue = getValueIfPresent(forKey: key) else {
@@ -973,11 +981,13 @@ private final class PreTransformKeyedContainer<K: CodingKey>: KeyedDecodingConta
973981
return try decodeInteger(jsonValue, forKey: key)
974982
}
975983

984+
#if !os(Linux)
976985
@available(macOS 15.0, iOS 18.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *)
977986
func decode(_: Int128.Type, forKey key: K) throws -> Int128 {
978987
let jsonValue = try getValue(forKey: key)
979988
return try decodeInteger(jsonValue, forKey: key)
980989
}
990+
#endif
981991

982992
func decodeIfPresent(_: Int64.Type, forKey key: K) throws -> Int64? {
983993
guard let jsonValue = getValueIfPresent(forKey: key) else {
@@ -1039,11 +1049,13 @@ private final class PreTransformKeyedContainer<K: CodingKey>: KeyedDecodingConta
10391049
return try decodeInteger(jsonValue, forKey: key)
10401050
}
10411051

1052+
#if !os(Linux)
10421053
@available(macOS 15.0, iOS 18.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *)
10431054
func decode(_: UInt128.Type, forKey key: K) throws -> UInt128 {
10441055
let jsonValue = try getValue(forKey: key)
10451056
return try decodeInteger(jsonValue, forKey: key)
10461057
}
1058+
#endif
10471059

10481060
func decodeIfPresent(_: UInt64.Type, forKey key: K) throws -> UInt64? {
10491061
guard let jsonValue = getValueIfPresent(forKey: key) else {
@@ -1422,11 +1434,13 @@ private struct UnkeyedContainer: UnkeyedDecodingContainer {
14221434
return try decodeInteger(value)
14231435
}
14241436

1437+
#if !os(Linux)
14251438
@available(macOS 15.0, iOS 18.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *)
14261439
mutating func decode(_: Int128.Type) throws -> Int128 {
14271440
let value = try peekNextValue(ofType: Int128.self)
14281441
return try decodeInteger(value)
14291442
}
1443+
#endif
14301444

14311445
mutating func decodeIfPresent(_: Int64.Type) throws -> Int64? {
14321446
guard let value = peekNextValueIfPresent(ofType: Int64.self), !value.isNull else {
@@ -1493,11 +1507,13 @@ private struct UnkeyedContainer: UnkeyedDecodingContainer {
14931507
return try decodeInteger(value)
14941508
}
14951509

1510+
#if !os(Linux)
14961511
@available(macOS 15.0, iOS 18.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *)
14971512
mutating func decode(_: UInt128.Type) throws -> UInt128 {
14981513
let value = try peekNextValue(ofType: UInt.self)
14991514
return try decodeInteger(value)
15001515
}
1516+
#endif
15011517

15021518
mutating func decodeIfPresent(_: UInt64.Type) throws -> UInt64? {
15031519
guard let value = peekNextValueIfPresent(ofType: UInt.self), !value.isNull else {

Tests/ReerJSONTests/AppleJSONDecoderTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ class TestJSONEncoder : XCTestCase {
355355

356356
// MARK: - Data Strategy Tests
357357
func testEncodingData() {
358-
let data = Data(bytes: [0xDE, 0xAD, 0xBE, 0xEF])
358+
let data = Data([0xDE, 0xAD, 0xBE, 0xEF])
359359

360360
// We can't encode a top-level Data, so it'll be wrapped in a dictionary.
361361
let expectedJSON = "{\"value\":[222,173,190,239]}".data(using: .utf8)!
@@ -372,7 +372,7 @@ class TestJSONEncoder : XCTestCase {
372372
}
373373

374374
func testEncodingDataBase64() {
375-
let data = Data(bytes: [0xDE, 0xAD, 0xBE, 0xEF])
375+
let data = Data([0xDE, 0xAD, 0xBE, 0xEF])
376376

377377
// We can't encode a top-level Data, so it'll be wrapped in a dictionary.
378378
let expectedJSON = "{\"value\":\"3q2+7w==\"}".data(using: .utf8)!

Tests/ReerJSONTests/JSONTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,15 +403,15 @@ final class JSONTests: XCTestCase {
403403

404404
decoder.dataDecodingStrategy = .deferredToData
405405
var datas = try decoder.decode(Datas.self, from: "{\"data\":[1,2,3]}".data(using: .utf8)!)
406-
XCTAssertEqual(datas.data, Data(bytes: [1,2,3]))
406+
XCTAssertEqual(datas.data, Data([1,2,3]))
407407

408408
decoder.dataDecodingStrategy = .custom({ _ in
409-
return Data(bytes: [1, 2, 3])
409+
return Data([1, 2, 3])
410410
})
411411
datas = try decoder.decode(Datas.self, from: "{\"data\":true}".data(using: .utf8)!)
412-
XCTAssertEqual(datas.data, Data(bytes: [1,2,3]))
412+
XCTAssertEqual(datas.data, Data([1,2,3]))
413413

414-
let data = Data(bytes: [0x01, 0x02, 0x03, 0x04, 0x05])
414+
let data = Data([0x01, 0x02, 0x03, 0x04, 0x05])
415415
decoder.dataDecodingStrategy = .base64
416416
datas = try decoder.decode(Datas.self, from: "{\"data\":\"\(data.base64EncodedString())\"}".data(using: .utf8)!)
417417
XCTAssertEqual(datas.data, data)

Tests/ReerJSONTests/StdlibUnittest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ func _parseDottedVersion(_ s: String) -> [Int] {
782782
}
783783

784784
public func _parseDottedVersionTriple(_ s: String) -> (Int, Int, Int) {
785-
var array = _parseDottedVersion(s)
785+
let array = _parseDottedVersion(s)
786786
if array.count >= 4 {
787787
fatalError("unexpected version")
788788
}

0 commit comments

Comments
 (0)