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) } } }