|
| 1 | +/// Internal `SingleValueDecodingContainer` for `PostgreSQLDataDecoder` |
| 2 | +final class PostgreSQLDataSingleValueDecodingContainer: SingleValueDecodingContainer { |
| 3 | + /// See `SingleValueDecodingContainer.codingPath` |
| 4 | + var codingPath: [CodingKey] |
| 5 | + |
| 6 | + /// Data being encoded. |
| 7 | + let partialData: PartialPostgreSQLData |
| 8 | + |
| 9 | + /// Creates a new internal `PostgreSQLDataSingleValueDecodingContainer`. |
| 10 | + init(partialData: PartialPostgreSQLData, at path: [CodingKey]) { |
| 11 | + self.codingPath = path |
| 12 | + self.partialData = partialData |
| 13 | + } |
| 14 | + |
| 15 | + /// See `SingleValueDecodingContainer.decodeNil` |
| 16 | + func decodeNil() -> Bool { |
| 17 | + return partialData.get(at: codingPath) == nil |
| 18 | + } |
| 19 | + |
| 20 | + /// See `SingleValueDecodingContainer.decode` |
| 21 | + func decode(_ type: Bool.Type) throws -> Bool { |
| 22 | + return try partialData.requireBool(at: codingPath) |
| 23 | + } |
| 24 | + |
| 25 | + /// See `SingleValueDecodingContainer.decode` |
| 26 | + func decode(_ type: Int.Type) throws -> Int { |
| 27 | + return try partialData.requireFixedWidthItenger(at: codingPath) |
| 28 | + } |
| 29 | + |
| 30 | + /// See `SingleValueDecodingContainer.decode` |
| 31 | + func decode(_ type: Int8.Type) throws -> Int8 { |
| 32 | + return try partialData.requireFixedWidthItenger(at: codingPath) |
| 33 | + } |
| 34 | + |
| 35 | + /// See `SingleValueDecodingContainer.decode` |
| 36 | + func decode(_ type: Int16.Type) throws -> Int16 { |
| 37 | + return try partialData.requireFixedWidthItenger(at: codingPath) |
| 38 | + } |
| 39 | + |
| 40 | + /// See `SingleValueDecodingContainer.decode` |
| 41 | + func decode(_ type: Int32.Type) throws -> Int32 { |
| 42 | + return try partialData.requireFixedWidthItenger(at: codingPath) |
| 43 | + } |
| 44 | + |
| 45 | + /// See `SingleValueDecodingContainer.decode` |
| 46 | + func decode(_ type: Int64.Type) throws -> Int64 { |
| 47 | + return try partialData.requireFixedWidthItenger(at: codingPath) |
| 48 | + } |
| 49 | + |
| 50 | + /// See `SingleValueDecodingContainer.decode` |
| 51 | + func decode(_ type: UInt.Type) throws -> UInt { |
| 52 | + return try partialData.requireFixedWidthItenger(at: codingPath) |
| 53 | + } |
| 54 | + |
| 55 | + /// See `SingleValueDecodingContainer.decode` |
| 56 | + func decode(_ type: UInt8.Type) throws -> UInt8 { |
| 57 | + return try partialData.requireFixedWidthItenger(at: codingPath) |
| 58 | + } |
| 59 | + |
| 60 | + /// See `SingleValueDecodingContainer.decode` |
| 61 | + func decode(_ type: UInt16.Type) throws -> UInt16 { |
| 62 | + return try partialData.requireFixedWidthItenger(at: codingPath) |
| 63 | + } |
| 64 | + |
| 65 | + /// See `SingleValueDecodingContainer.decode` |
| 66 | + func decode(_ type: UInt32.Type) throws -> UInt32 { |
| 67 | + return try partialData.requireFixedWidthItenger(at: codingPath) |
| 68 | + } |
| 69 | + |
| 70 | + /// See `SingleValueDecodingContainer.decode` |
| 71 | + func decode(_ type: UInt64.Type) throws -> UInt64 { |
| 72 | + return try partialData.requireFixedWidthItenger(at: codingPath) |
| 73 | + } |
| 74 | + |
| 75 | + /// See `SingleValueDecodingContainer.decode` |
| 76 | + func decode(_ type: Float.Type) throws -> Float { |
| 77 | + return try partialData.requireFloatingPoint(at: codingPath) |
| 78 | + } |
| 79 | + |
| 80 | + /// See `SingleValueDecodingContainer.decode` |
| 81 | + func decode(_ type: Double.Type) throws -> Double { |
| 82 | + return try partialData.requireFloatingPoint(at: codingPath) |
| 83 | + } |
| 84 | + |
| 85 | + /// See `SingleValueDecodingContainer.decode` |
| 86 | + func decode(_ type: String.Type) throws -> String { |
| 87 | + return try partialData.requireString(at: codingPath) |
| 88 | + } |
| 89 | + |
| 90 | + /// See `SingleValueDecodingContainer.decode` |
| 91 | + func decode<T>(_ type: T.Type) throws -> T where T : Decodable { |
| 92 | + let decoder = _PostgreSQLDataDecoder(partialData: partialData, at: codingPath) |
| 93 | + return try T(from: decoder) |
| 94 | + } |
| 95 | + |
| 96 | + /// See `SingleValueDecodingContainer.nestedContainer` |
| 97 | + func nestedContainer<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> |
| 98 | + where Key: CodingKey |
| 99 | + { |
| 100 | + let container = PostgreSQLDataKeyedDecodingContainer<Key>(partialData: partialData, at: codingPath) |
| 101 | + return .init(container) |
| 102 | + } |
| 103 | + |
| 104 | + /// See `SingleValueDecodingContainer.nestedSingleValueContainer` |
| 105 | + func nestedSingleValueContainer() throws -> SingleValueDecodingContainer { |
| 106 | + return PostgreSQLDataSingleValueDecodingContainer(partialData: partialData, at: codingPath) |
| 107 | + } |
| 108 | + |
| 109 | + /// See `SingleValueDecodingContainer.superDecoder` |
| 110 | + func superDecoder() throws -> Decoder { |
| 111 | + return _PostgreSQLDataDecoder(partialData: partialData, at: codingPath) |
| 112 | + } |
| 113 | +} |
| 114 | + |
0 commit comments