Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
swift-urlqueryitem-coder Sources URLQueryItemCoder Decoder Generic Implementation StringlyKeyedDecodingContainerWrapper.swift
5.2 kB · 158 lines
Swift
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159//// StringlyKeyedDecodingContainerWrapper.swift// URLQueryItemCoder//// Created by Kyle Hughes on 2/23/23.//
internal struct StringlyKeyedDecodingContainerWrapper<Key, Base> where Key: CodingKey, Base: KeyedDecodingContainerProtocol, Base.Key == StringCodingKey{ internal let base: Base // MARK: Internal Initialization internal init(_ base: Base) { self.base = base }}
// MARK: - KeyedDecodingContainerProtocol Extension
extension StringlyKeyedDecodingContainerWrapper: KeyedDecodingContainerProtocol { // MARK: Internal Instance Interface @inlinable internal var allKeys: [Key] { base .allKeys .lazy .map(\.stringValue) .compactMap(Key.init) } @inlinable internal var codingPath: [any CodingKey] { base.codingPath } @inlinable internal func contains(_ key: Key) -> Bool { base.contains(StringCodingKey(stringValue: key.stringValue)) } @inlinable internal func decode(_ type: Bool.Type, forKey key: Key) throws -> Bool { try base.decode(type, forKey: StringCodingKey(stringValue: key.stringValue)) } @inlinable internal func decode(_ type: String.Type, forKey key: Key) throws -> String { try base.decode(type, forKey: StringCodingKey(stringValue: key.stringValue)) } @inlinable internal func decode(_ type: Double.Type, forKey key: Key) throws -> Double { try base.decode(type, forKey: StringCodingKey(stringValue: key.stringValue)) } @inlinable internal func decode(_ type: Float.Type, forKey key: Key) throws -> Float { try base.decode(type, forKey: StringCodingKey(stringValue: key.stringValue)) } @inlinable internal func decode(_ type: Int.Type, forKey key: Key) throws -> Int { try base.decode(type, forKey: StringCodingKey(stringValue: key.stringValue)) } @inlinable internal func decode(_ type: Int8.Type, forKey key: Key) throws -> Int8 { try base.decode(type, forKey: StringCodingKey(stringValue: key.stringValue)) } @inlinable internal func decode(_ type: Int16.Type, forKey key: Key) throws -> Int16 { try base.decode(type, forKey: StringCodingKey(stringValue: key.stringValue)) } @inlinable internal func decode(_ type: Int32.Type, forKey key: Key) throws -> Int32 { try base.decode(type, forKey: StringCodingKey(stringValue: key.stringValue)) } @inlinable internal func decode(_ type: Int64.Type, forKey key: Key) throws -> Int64 { try base.decode(type, forKey: StringCodingKey(stringValue: key.stringValue)) } @inlinable internal func decode(_ type: UInt.Type, forKey key: Key) throws -> UInt { try base.decode(type, forKey: StringCodingKey(stringValue: key.stringValue)) } @inlinable internal func decode(_ type: UInt8.Type, forKey key: Key) throws -> UInt8 { try base.decode(type, forKey: StringCodingKey(stringValue: key.stringValue)) } @inlinable internal func decode(_ type: UInt16.Type, forKey key: Key) throws -> UInt16 { try base.decode(type, forKey: StringCodingKey(stringValue: key.stringValue)) } @inlinable internal func decode(_ type: UInt32.Type, forKey key: Key) throws -> UInt32 { try base.decode(type, forKey: StringCodingKey(stringValue: key.stringValue)) } @inlinable internal func decode(_ type: UInt64.Type, forKey key: Key) throws -> UInt64 { try base.decode(type, forKey: StringCodingKey(stringValue: key.stringValue)) } @inlinable internal func decode<T>(_ type: T.Type, forKey key: Key) throws -> T where T: Decodable { try base.decode(type, forKey: StringCodingKey(stringValue: key.stringValue)) } @inlinable internal func decodeNil(forKey key: Key) throws -> Bool { try base.decodeNil(forKey: StringCodingKey(stringValue: key.stringValue)) } @inlinable internal func nestedContainer<NestedKey>( keyedBy type: NestedKey.Type, forKey key: Key ) throws -> KeyedDecodingContainer<NestedKey> where NestedKey: CodingKey { try base.nestedContainer(keyedBy: type, forKey: StringCodingKey(stringValue: key.stringValue)) } @inlinable internal func nestedUnkeyedContainer(forKey key: Key) throws -> UnkeyedDecodingContainer { try base.nestedUnkeyedContainer(forKey: StringCodingKey(stringValue: key.stringValue)) } @inlinable internal func superDecoder() throws -> Decoder { try base.superDecoder() } @inlinable internal func superDecoder(forKey key: Key) throws -> Decoder { try base.superDecoder(forKey: StringCodingKey(stringValue: key.stringValue)) }}
// MARK: - Extension for Stringly-Keyed Decoding Containers
extension KeyedDecodingContainerProtocol where Key == StringCodingKey { // MARK: Internal Instance Interface
internal func wrapped<Key>() -> StringlyKeyedDecodingContainerWrapper<Key, Self> { StringlyKeyedDecodingContainerWrapper(self) }}