Skip to content

Commit 4cbc68d

Browse files
Delete unused hexDecode methods for KeyedDecodingContainer.
1 parent 79bb291 commit 4cbc68d

File tree

1 file changed

+0
-122
lines changed

1 file changed

+0
-122
lines changed

Sources/web3swift/Convenience/Decodable+Extensions.swift

Lines changed: 0 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -23,78 +23,6 @@ struct AnyCodingKey: CodingKey {
2323
}
2424

2525
extension KeyedDecodingContainer {
26-
/// Decodes a value of the given type for the given key.
27-
///
28-
/// - parameter type: The type of value to decode.
29-
/// - parameter key: The key that the decoded value is associated with.
30-
/// - returns: A value of the requested type, if present for the given key
31-
/// and convertible to the requested type.
32-
/// - throws: `DecodingError.typeMismatch` if the encountered encoded value
33-
/// is not convertible to the requested type.
34-
/// - throws: `DecodingError.keyNotFound` if `self` does not have an entry
35-
/// for the given key.
36-
/// - throws: `DecodingError.valueNotFound` if `self` has a null entry for
37-
/// the given key.
38-
public func decode(_ type: [Any].Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> [Any] {
39-
var values = try nestedUnkeyedContainer(forKey: key)
40-
return try values.decode(type)
41-
}
42-
43-
/// Decodes a value of the given type for the given key.
44-
///
45-
/// - parameter type: The type of value to decode.
46-
/// - parameter key: The key that the decoded value is associated with.
47-
/// - returns: A value of the requested type, if present for the given key
48-
/// and convertible to the requested type.
49-
/// - throws: `DecodingError.typeMismatch` if the encountered encoded value
50-
/// is not convertible to the requested type.
51-
/// - throws: `DecodingError.keyNotFound` if `self` does not have an entry
52-
/// for the given key.
53-
/// - throws: `DecodingError.valueNotFound` if `self` has a null entry for
54-
/// the given key.
55-
public func decode(_ type: [String: Any].Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> [String: Any] {
56-
let values = try nestedContainer(keyedBy: AnyCodingKey.self, forKey: key)
57-
return try values.decode(type)
58-
}
59-
60-
/// Decodes a value of the given type for the given key, if present.
61-
///
62-
/// This method returns `nil` if the container does not have a value
63-
/// associated with `key`, or if the value is null. The difference between
64-
/// these states can be distinguished with a `contains(_:)` call.
65-
///
66-
/// - parameter type: The type of value to decode.
67-
/// - parameter key: The key that the decoded value is associated with.
68-
/// - returns: A decoded value of the requested type, or `nil` if the
69-
/// `Decoder` does not have an entry associated with the given key, or if
70-
/// the value is a null value.
71-
/// - throws: `DecodingError.typeMismatch` if the encountered encoded value
72-
/// is not convertible to the requested type.
73-
public func decodeIfPresent(_ type: [Any].Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> [Any]? {
74-
guard contains(key),
75-
try decodeNil(forKey: key) == false else { return nil }
76-
return try decode(type, forKey: key)
77-
}
78-
79-
/// Decodes a value of the given type for the given key, if present.
80-
///
81-
/// This method returns `nil` if the container does not have a value
82-
/// associated with `key`, or if the value is null. The difference between
83-
/// these states can be distinguished with a `contains(_:)` call.
84-
///
85-
/// - parameter type: The type of value to decode.
86-
/// - parameter key: The key that the decoded value is associated with.
87-
/// - returns: A decoded value of the requested type, or `nil` if the
88-
/// `Decoder` does not have an entry associated with the given key, or if
89-
/// the value is a null value.
90-
/// - throws: `DecodingError.typeMismatch` if the encountered encoded value
91-
/// is not convertible to the requested type.
92-
public func decodeIfPresent(_ type: [String: Any].Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> [String: Any]? {
93-
guard contains(key),
94-
try decodeNil(forKey: key) == false else { return nil }
95-
return try decode(type, forKey: key)
96-
}
97-
9826
/// Decodes a value of the given key from Hex to `DecodableFromHex`
9927
///
10028
/// Currently this method supports only `Data.Type`, `BigUInt.Type`, `Date.Type`
@@ -170,53 +98,3 @@ extension EthereumAddress: DecodableFromHex {
17098
self.init(hexString, ignoreChecksum: true)
17199
}
172100
}
173-
174-
private extension KeyedDecodingContainer {
175-
func decode(_ type: [String: Any].Type) throws -> [String: Any] {
176-
var dictionary: [String: Any] = [:]
177-
for key in allKeys {
178-
if try decodeNil(forKey: key) {
179-
dictionary[key.stringValue] = NSNull()
180-
} else if let bool = try? decode(Bool.self, forKey: key) {
181-
dictionary[key.stringValue] = bool
182-
} else if let string = try? decode(String.self, forKey: key) {
183-
dictionary[key.stringValue] = string
184-
} else if let int = try? decode(Int.self, forKey: key) {
185-
dictionary[key.stringValue] = int
186-
} else if let double = try? decode(Double.self, forKey: key) {
187-
dictionary[key.stringValue] = double
188-
} else if let dict = try? decode([String: Any].self, forKey: key) {
189-
dictionary[key.stringValue] = dict
190-
} else if let array = try? decode([Any].self, forKey: key) {
191-
dictionary[key.stringValue] = array
192-
}
193-
}
194-
return dictionary
195-
}
196-
}
197-
198-
private extension UnkeyedDecodingContainer {
199-
mutating func decode(_ type: [Any].Type) throws -> [Any] {
200-
var elements: [Any] = []
201-
while !isAtEnd {
202-
if try decodeNil() {
203-
elements.append(NSNull())
204-
} else if let int = try? decode(Int.self) {
205-
elements.append(int)
206-
} else if let bool = try? decode(Bool.self) {
207-
elements.append(bool)
208-
} else if let double = try? decode(Double.self) {
209-
elements.append(double)
210-
} else if let string = try? decode(String.self) {
211-
elements.append(string)
212-
} else if let values = try? nestedContainer(keyedBy: AnyCodingKey.self),
213-
let element = try? values.decode([String: Any].self) {
214-
elements.append(element)
215-
} else if var values = try? nestedUnkeyedContainer(),
216-
let element = try? values.decode([Any].self) {
217-
elements.append(element)
218-
}
219-
}
220-
return elements
221-
}
222-
}

0 commit comments

Comments
 (0)