mirror of
https://github.com/apple/swift-http-structured-headers
synced 2026-11-24 04:37:50 +00:00
Split Codable to its own module
This commit is contained in:
1 parent
8cd792800c
commit
5aaca631da
17 files changed
+28
-9
No files matched your search
@@ -0,0 +1,114 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftNIO open source project
|
||||
//
|
||||
// Copyright (c) 2020 Apple Inc. and the SwiftNIO project authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
import StructuredHeaders
|
||||
|
||||
/// This object translates between the keys used by the encoder and the keys used by the encoding object.
|
||||
///
|
||||
/// All methods here call back to similar methods on the encoder.
|
||||
struct StructuredFieldKeyedEncodingContainer<Key: CodingKey> {
|
||||
private var encoder: _StructuredFieldEncoder
|
||||
|
||||
init(encoder: _StructuredFieldEncoder) {
|
||||
self.encoder = encoder
|
||||
}
|
||||
}
|
||||
|
||||
extension StructuredFieldKeyedEncodingContainer: KeyedEncodingContainerProtocol {
|
||||
var codingPath: [CodingKey] {
|
||||
return self.encoder.codingPath
|
||||
}
|
||||
|
||||
mutating func encodeNil(forKey key: Key) throws {
|
||||
// Nil has no representation in structured headers
|
||||
return
|
||||
}
|
||||
|
||||
mutating func encode(_ value: Bool, forKey key: Key) throws {
|
||||
try self.encoder.encode(value, forKey: key.stringValue)
|
||||
}
|
||||
|
||||
mutating func encode(_ value: String, forKey key: Key) throws {
|
||||
try self.encoder.encode(value, forKey: key.stringValue)
|
||||
}
|
||||
|
||||
mutating func encode(_ value: Double, forKey key: Key) throws {
|
||||
try self.encoder.encode(value, forKey: key.stringValue)
|
||||
}
|
||||
|
||||
mutating func encode(_ value: Float, forKey key: Key) throws {
|
||||
try self.encoder.encode(value, forKey: key.stringValue)
|
||||
}
|
||||
|
||||
mutating func encode(_ value: Int, forKey key: Key) throws {
|
||||
try self.encoder.encode(value, forKey: key.stringValue)
|
||||
}
|
||||
|
||||
mutating func encode(_ value: Int8, forKey key: Key) throws {
|
||||
try self.encoder.encode(value, forKey: key.stringValue)
|
||||
}
|
||||
|
||||
mutating func encode(_ value: Int16, forKey key: Key) throws {
|
||||
try self.encoder.encode(value, forKey: key.stringValue)
|
||||
}
|
||||
|
||||
mutating func encode(_ value: Int32, forKey key: Key) throws {
|
||||
try self.encoder.encode(value, forKey: key.stringValue)
|
||||
}
|
||||
|
||||
mutating func encode(_ value: Int64, forKey key: Key) throws {
|
||||
try self.encoder.encode(value, forKey: key.stringValue)
|
||||
}
|
||||
|
||||
mutating func encode(_ value: UInt, forKey key: Key) throws {
|
||||
try self.encoder.encode(value, forKey: key.stringValue)
|
||||
}
|
||||
|
||||
mutating func encode(_ value: UInt8, forKey key: Key) throws {
|
||||
try self.encoder.encode(value, forKey: key.stringValue)
|
||||
}
|
||||
|
||||
mutating func encode(_ value: UInt16, forKey key: Key) throws {
|
||||
try self.encoder.encode(value, forKey: key.stringValue)
|
||||
}
|
||||
|
||||
mutating func encode(_ value: UInt32, forKey key: Key) throws {
|
||||
try self.encoder.encode(value, forKey: key.stringValue)
|
||||
}
|
||||
|
||||
mutating func encode(_ value: UInt64, forKey key: Key) throws {
|
||||
try self.encoder.encode(value, forKey: key.stringValue)
|
||||
}
|
||||
|
||||
mutating func encode<T>(_ value: T, forKey key: Key) throws where T : Encodable {
|
||||
try self.encoder.encode(value, forKey: key.stringValue)
|
||||
}
|
||||
|
||||
mutating func nestedContainer<NestedKey>(keyedBy keyType: NestedKey.Type, forKey key: Key) -> KeyedEncodingContainer<NestedKey> where NestedKey : CodingKey {
|
||||
return self.encoder.container(keyedBy: keyType)
|
||||
}
|
||||
|
||||
mutating func nestedUnkeyedContainer(forKey key: Key) -> UnkeyedEncodingContainer {
|
||||
return self.encoder.unkeyedContainer()
|
||||
}
|
||||
|
||||
mutating func superEncoder() -> Encoder {
|
||||
return self.encoder
|
||||
}
|
||||
|
||||
mutating func superEncoder(forKey key: Key) -> Encoder {
|
||||
return self.encoder
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user