|
| 1 | +// Generated using Sourcery 0.17.0 — https://github.com/krzysztofzablocki/Sourcery |
| 2 | +// DO NOT EDIT |
| 3 | + |
| 4 | + |
| 5 | +import MultipeerConnectivity |
| 6 | +import MultipeerRedux |
| 7 | +extension MessageType: Codable { |
| 8 | + enum CodingKeys: String, CodingKey { |
| 9 | + case type |
| 10 | + case associatedValues |
| 11 | + |
| 12 | + enum IntroductionKeys: String, CodingKey { |
| 13 | + case associatedValue0 |
| 14 | + } |
| 15 | + enum ActionKeys: String, CodingKey { |
| 16 | + case associatedValue0 |
| 17 | + } |
| 18 | + } |
| 19 | + |
| 20 | + public init(from decoder: Decoder) throws { |
| 21 | + let container = try decoder.container(keyedBy: CodingKeys.self) |
| 22 | + switch try container.decode(String.self, forKey: .type) { |
| 23 | + case "introduction": |
| 24 | + let subContainer = try container.nestedContainer(keyedBy: CodingKeys.IntroductionKeys.self, forKey: .associatedValues) |
| 25 | + let associatedValues0 = try subContainer.decode(PeerMetadata.self, forKey: .associatedValue0) |
| 26 | + self = .introduction(associatedValues0) |
| 27 | + case "action": |
| 28 | + let subContainer = try container.nestedContainer(keyedBy: CodingKeys.ActionKeys.self, forKey: .associatedValues) |
| 29 | + let associatedValues0 = try subContainer.decode(ActionMessage.self, forKey: .associatedValue0) |
| 30 | + self = .action(associatedValues0) |
| 31 | + default: |
| 32 | + throw DecodingError.keyNotFound(CodingKeys.type, .init(codingPath: container.codingPath, debugDescription: "Unknown key")) |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + public func encode(to encoder: Encoder) throws { |
| 37 | + var container = encoder.container(keyedBy: CodingKeys.self) |
| 38 | + switch self { |
| 39 | + case let .introduction(associatedValue0): |
| 40 | + try container.encode("introduction", forKey: .type) |
| 41 | + var subContainer = container.nestedContainer(keyedBy: CodingKeys.IntroductionKeys.self, forKey: .associatedValues) |
| 42 | + try subContainer.encode(associatedValue0, forKey: .associatedValue0) |
| 43 | + case let .action(associatedValue0): |
| 44 | + try container.encode("action", forKey: .type) |
| 45 | + var subContainer = container.nestedContainer(keyedBy: CodingKeys.ActionKeys.self, forKey: .associatedValues) |
| 46 | + try subContainer.encode(associatedValue0, forKey: .associatedValue0) |
| 47 | + } |
| 48 | + } |
| 49 | +} |
| 50 | +extension PayloadTree: Codable { |
| 51 | + enum CodingKeys: String, CodingKey { |
| 52 | + case type |
| 53 | + case associatedValues |
| 54 | + |
| 55 | + enum UnkeyedKeys: String, CodingKey { |
| 56 | + case associatedValue0 |
| 57 | + } |
| 58 | + enum KeyedKeys: String, CodingKey { |
| 59 | + case key |
| 60 | + case value |
| 61 | + } |
| 62 | + enum ArrayKeys: String, CodingKey { |
| 63 | + case key |
| 64 | + case values |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + public init(from decoder: Decoder) throws { |
| 69 | + let container = try decoder.container(keyedBy: CodingKeys.self) |
| 70 | + switch try container.decode(String.self, forKey: .type) { |
| 71 | + case "unkeyed": |
| 72 | + let subContainer = try container.nestedContainer(keyedBy: CodingKeys.UnkeyedKeys.self, forKey: .associatedValues) |
| 73 | + let associatedValues0 = try subContainer.decode(String.self, forKey: .associatedValue0) |
| 74 | + self = .unkeyed(associatedValues0) |
| 75 | + case "keyed": |
| 76 | + let subContainer = try container.nestedContainer(keyedBy: CodingKeys.KeyedKeys.self, forKey: .associatedValues) |
| 77 | + let associatedValues0 = try subContainer.decode(String.self, forKey: .key) |
| 78 | + let associatedValues1 = try subContainer.decode(String.self, forKey: .value) |
| 79 | + self = .keyed(key: associatedValues0, value: associatedValues1) |
| 80 | + case "array": |
| 81 | + let subContainer = try container.nestedContainer(keyedBy: CodingKeys.ArrayKeys.self, forKey: .associatedValues) |
| 82 | + let associatedValues0 = try subContainer.decode(String.self, forKey: .key) |
| 83 | + let associatedValues1 = try subContainer.decode([PayloadTree].self, forKey: .values) |
| 84 | + self = .array(key: associatedValues0, values: associatedValues1) |
| 85 | + default: |
| 86 | + throw DecodingError.keyNotFound(CodingKeys.type, .init(codingPath: container.codingPath, debugDescription: "Unknown key")) |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + public func encode(to encoder: Encoder) throws { |
| 91 | + var container = encoder.container(keyedBy: CodingKeys.self) |
| 92 | + switch self { |
| 93 | + case let .unkeyed(associatedValue0): |
| 94 | + try container.encode("unkeyed", forKey: .type) |
| 95 | + var subContainer = container.nestedContainer(keyedBy: CodingKeys.UnkeyedKeys.self, forKey: .associatedValues) |
| 96 | + try subContainer.encode(associatedValue0, forKey: .associatedValue0) |
| 97 | + case let .keyed(key, value): |
| 98 | + try container.encode("keyed", forKey: .type) |
| 99 | + var subContainer = container.nestedContainer(keyedBy: CodingKeys.KeyedKeys.self, forKey: .associatedValues) |
| 100 | + try subContainer.encode(key, forKey: .key) |
| 101 | + try subContainer.encode(value, forKey: .value) |
| 102 | + case let .array(key, values): |
| 103 | + try container.encode("array", forKey: .type) |
| 104 | + var subContainer = container.nestedContainer(keyedBy: CodingKeys.ArrayKeys.self, forKey: .associatedValues) |
| 105 | + try subContainer.encode(key, forKey: .key) |
| 106 | + try subContainer.encode(values, forKey: .values) |
| 107 | + } |
| 108 | + } |
| 109 | +} |
0 commit comments