@@ -406,29 +406,17 @@ extension Range: Hashable where Bound: Hashable {
406
406
}
407
407
408
408
extension Range : Codable where Bound: Codable {
409
- private enum CodingKeys : String , CodingKey {
410
- case lowerBound = " from "
411
- case upperBound = " upTo "
412
- }
413
-
414
409
public init ( from decoder: Decoder ) throws {
415
- let container = try decoder. container ( keyedBy: CodingKeys . self)
416
- let lowerBound = try container. decode ( Bound . self, forKey: . lowerBound)
417
- let upperBound = try container. decode ( Bound . self, forKey: . upperBound)
418
- guard lowerBound <= upperBound else {
419
- throw DecodingError . dataCorruptedError (
420
- forKey: CodingKeys . upperBound,
421
- in: container,
422
- debugDescription: " upperBound (upTo) cannot be less than lowerBound (from) "
423
- )
424
- }
410
+ var container = try decoder. unkeyedContainer ( )
411
+ let lowerBound = try container. decode ( Bound . self)
412
+ let upperBound = try container. decode ( Bound . self)
425
413
self = lowerBound..< upperBound
426
414
}
427
415
428
416
public func encode( to encoder: Encoder ) throws {
429
- var container = encoder. container ( keyedBy : CodingKeys . self )
430
- try container. encode ( self . lowerBound, forKey : . lowerBound )
431
- try container. encode ( self . upperBound, forKey : . upperBound )
417
+ var container = encoder. unkeyedContainer ( )
418
+ try container. encode ( self . lowerBound)
419
+ try container. encode ( self . upperBound)
432
420
}
433
421
}
434
422
@@ -475,18 +463,14 @@ extension PartialRangeUpTo: RangeExpression {
475
463
}
476
464
477
465
extension PartialRangeUpTo : Codable where Bound: Codable {
478
- private enum CodingKeys : String , CodingKey {
479
- case upperBound = " fromStartUpTo "
480
- }
481
-
482
466
public init ( from decoder: Decoder ) throws {
483
- let container = try decoder. container ( keyedBy : CodingKeys . self )
484
- self = try ( ..< container. decode ( Bound . self, forKey : . upperBound ) )
467
+ var container = try decoder. unkeyedContainer ( )
468
+ self = try ( ..< container. decode ( Bound . self) )
485
469
}
486
470
487
471
public func encode( to encoder: Encoder ) throws {
488
- var container = encoder. container ( keyedBy : CodingKeys . self )
489
- try container. encode ( self . upperBound, forKey : . upperBound )
472
+ var container = encoder. unkeyedContainer ( )
473
+ try container. encode ( self . upperBound)
490
474
}
491
475
}
492
476
@@ -532,18 +516,14 @@ extension PartialRangeThrough: RangeExpression {
532
516
}
533
517
534
518
extension PartialRangeThrough : Codable where Bound: Codable {
535
- private enum CodingKeys : String , CodingKey {
536
- case upperBound = " fromStartThrough "
537
- }
538
-
539
519
public init ( from decoder: Decoder ) throws {
540
- let container = try decoder. container ( keyedBy : CodingKeys . self )
541
- self = try ( ... container. decode ( Bound . self, forKey : . upperBound ) )
520
+ var container = try decoder. unkeyedContainer ( )
521
+ self = try ( ... container. decode ( Bound . self) )
542
522
}
543
523
544
524
public func encode( to encoder: Encoder ) throws {
545
- var container = encoder. container ( keyedBy : CodingKeys . self )
546
- try container. encode ( self . upperBound, forKey : . upperBound )
525
+ var container = encoder. unkeyedContainer ( )
526
+ try container. encode ( self . upperBound)
547
527
}
548
528
}
549
529
@@ -684,18 +664,14 @@ extension PartialRangeFrom: Sequence
684
664
}
685
665
686
666
extension PartialRangeFrom : Codable where Bound: Codable {
687
- private enum CodingKeys : String , CodingKey {
688
- case lowerBound = " toEndFrom "
689
- }
690
-
691
667
public init ( from decoder: Decoder ) throws {
692
- let container = try decoder. container ( keyedBy : CodingKeys . self )
693
- self = try container. decode ( Bound . self, forKey : . lowerBound ) ...
668
+ var container = try decoder. unkeyedContainer ( )
669
+ self = try container. decode ( Bound . self) ...
694
670
}
695
671
696
672
public func encode( to encoder: Encoder ) throws {
697
- var container = encoder. container ( keyedBy : CodingKeys . self )
698
- try container. encode ( self . lowerBound, forKey : . lowerBound )
673
+ var container = encoder. unkeyedContainer ( )
674
+ try container. encode ( self . lowerBound)
699
675
}
700
676
}
701
677
0 commit comments