Files
Rintaro Ishizaki 39606e6269 [refactoring] Rework "add codable implementation" refactoring
* Support extensions including conditional conformance
* Correct access modifiers
* More correct lookup for the synthesized declarations
* Avoid printing decls in nested types (rdar://98025945)
2024-03-13 13:34:32 +09:00

46 lines
1.2 KiB
Plaintext

enum Payload: Codable {
case plain(String)
case pair(key: String, value: String)
}
enum Payload_D: Decodable {
case plain(String)
case pair(key: String, value: String)
}
enum Payload_E: Encodable {
case plain(String)
case pair(key: String, value: String)
private enum CodingKeys: CodingKey {
case plain
case pair
}
private enum PlainCodingKeys: CodingKey {
case _0
}
private enum PairCodingKeys: CodingKey {
case key
case value
}
func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: Payload_E.CodingKeys.self)
switch self {
case .plain(let a0):
var nestedContainer = container.nestedContainer(keyedBy: Payload_E.PlainCodingKeys.self, forKey: Payload_E.CodingKeys.plain)
try nestedContainer.encode(a0, forKey: Payload_E.PlainCodingKeys._0)
case .pair(let key, let value):
var nestedContainer = container.nestedContainer(keyedBy: Payload_E.PairCodingKeys.self, forKey: Payload_E.CodingKeys.pair)
try nestedContainer.encode(key, forKey: Payload_E.PairCodingKeys.key)
try nestedContainer.encode(value, forKey: Payload_E.PairCodingKeys.value)
}
}
}