Skip to content

Commit 904aa70

Browse files
committed
add manual codable conformance
1 parent d3ce3b4 commit 904aa70

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

Sources/FoundationInternationalization/ProgressReporter/ProgressReporter+FileFormatStyle.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ extension ProgressReporter {
2020

2121
internal struct Option: Sendable, Codable, Equatable, Hashable {
2222

23+
enum CodingKeys: String, CodingKey {
24+
case rawOption
25+
}
26+
27+
init(from decoder: any Decoder) throws {
28+
let container = try decoder.container(keyedBy: CodingKeys.self)
29+
rawOption = try container.decode(RawOption.self, forKey: .rawOption)
30+
}
31+
32+
func encode(to encoder: any Encoder) throws {
33+
var container = encoder.container(keyedBy: CodingKeys.self)
34+
try container.encode(rawOption, forKey: .rawOption)
35+
}
36+
2337
internal static var file: Option { Option(.file) }
2438

2539
fileprivate enum RawOption: Codable, Equatable, Hashable {
@@ -32,6 +46,22 @@ extension ProgressReporter {
3246
self.rawOption = rawOption
3347
}
3448
}
49+
enum CodingKeys: String, CodingKey {
50+
case locale
51+
case option
52+
}
53+
54+
public init(from decoder: any Decoder) throws {
55+
let container = try decoder.container(keyedBy: CodingKeys.self)
56+
locale = try container.decode(Locale.self, forKey: .locale)
57+
option = try container.decode(Option.self, forKey: .option)
58+
}
59+
60+
public func encode(to encoder: any Encoder) throws {
61+
var container = encoder.container(keyedBy: CodingKeys.self)
62+
try container.encode(locale, forKey: .locale)
63+
try container.encode(option, forKey: .option)
64+
}
3565

3666
public var locale: Locale
3767
let option: Option

Sources/FoundationInternationalization/ProgressReporter/ProgressReporter+FormatStyle.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ extension ProgressReporter {
2121
// Outlines the options available to format ProgressReporter
2222
internal struct Option: Sendable, Codable, Hashable, Equatable {
2323

24+
enum CodingKeys: String, CodingKey {
25+
case rawOption
26+
}
27+
28+
init(from decoder: any Decoder) throws {
29+
let container = try decoder.container(keyedBy: CodingKeys.self)
30+
rawOption = try container.decode(RawOption.self, forKey: .rawOption)
31+
}
32+
33+
func encode(to encoder: any Encoder) throws {
34+
var container = encoder.container(keyedBy: CodingKeys.self)
35+
try container.encode(rawOption, forKey: .rawOption)
36+
}
37+
2438
/// Option specifying `fractionCompleted`.
2539
///
2640
/// For example, 20% completed.
@@ -53,6 +67,23 @@ extension ProgressReporter {
5367
}
5468
}
5569

70+
enum CodingKeys: String, CodingKey {
71+
case locale
72+
case option
73+
}
74+
75+
public init(from decoder: any Decoder) throws {
76+
let container = try decoder.container(keyedBy: CodingKeys.self)
77+
locale = try container.decode(Locale.self, forKey: .locale)
78+
option = try container.decode(Option.self, forKey: .option)
79+
}
80+
81+
public func encode(to encoder: any Encoder) throws {
82+
var container = encoder.container(keyedBy: CodingKeys.self)
83+
try container.encode(locale, forKey: .locale)
84+
try container.encode(option, forKey: .option)
85+
}
86+
5687
public var locale: Locale
5788
let option: Option
5889

0 commit comments

Comments
 (0)