mirror of
https://github.com/apple/swift-http-structured-headers
synced 2026-11-23 04:34:21 +00:00
Motivation: In general we should try to be specific about what we're referring to. "Structured headers" is not really an accurate description of what this module works with: "Structured Header Field Values", or "Structured Field Value" is usually better. To that end this change adjusts our naming to be closer to what we want. It also changes our module names to prioritise the use of the Codable-based one. Modifications: - Renamed CodableStructuredHeaders to StructuredFieldValues. - Renamed StructuredHeaders to RawStructuredFieldValues. - Renamed a number of types from Field to FieldValue. - Renamed a number of types from Header to Field or FieldValue. - Renamed some functions along the above lines. Result: Better and more consistent terminology will be used.
112 lines
2.8 KiB
Swift
112 lines
2.8 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the SwiftNIO open source project
|
|
//
|
|
// Copyright (c) 2020-2021 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 RawStructuredFieldValues
|
|
|
|
/// This object translates between the unkeyed coding API and methods on the encoder.
|
|
///
|
|
/// All methods here call back to similar methods on the encoder.
|
|
struct StructuredFieldUnkeyedEncodingContainer {
|
|
private var encoder: _StructuredFieldEncoder
|
|
|
|
init(encoder: _StructuredFieldEncoder) {
|
|
self.encoder = encoder
|
|
}
|
|
}
|
|
|
|
extension StructuredFieldUnkeyedEncodingContainer: UnkeyedEncodingContainer {
|
|
var codingPath: [CodingKey] {
|
|
self.encoder.codingPath
|
|
}
|
|
|
|
var count: Int {
|
|
self.encoder.count
|
|
}
|
|
|
|
func encodeNil() throws {
|
|
try self.encoder.appendNil()
|
|
}
|
|
|
|
func encode(_ value: Bool) throws {
|
|
try self.encoder.append(value)
|
|
}
|
|
|
|
func encode(_ value: String) throws {
|
|
try self.encoder.append(value)
|
|
}
|
|
|
|
func encode(_ value: Double) throws {
|
|
try self.encoder.append(value)
|
|
}
|
|
|
|
func encode(_ value: Float) throws {
|
|
try self.encoder.append(value)
|
|
}
|
|
|
|
func encode(_ value: Int) throws {
|
|
try self.encoder.append(value)
|
|
}
|
|
|
|
func encode(_ value: Int8) throws {
|
|
try self.encoder.append(value)
|
|
}
|
|
|
|
func encode(_ value: Int16) throws {
|
|
try self.encoder.append(value)
|
|
}
|
|
|
|
func encode(_ value: Int32) throws {
|
|
try self.encoder.append(value)
|
|
}
|
|
|
|
func encode(_ value: Int64) throws {
|
|
try self.encoder.append(value)
|
|
}
|
|
|
|
func encode(_ value: UInt) throws {
|
|
try self.encoder.append(value)
|
|
}
|
|
|
|
func encode(_ value: UInt8) throws {
|
|
try self.encoder.append(value)
|
|
}
|
|
|
|
func encode(_ value: UInt16) throws {
|
|
try self.encoder.append(value)
|
|
}
|
|
|
|
func encode(_ value: UInt32) throws {
|
|
try self.encoder.append(value)
|
|
}
|
|
|
|
func encode(_ value: UInt64) throws {
|
|
try self.encoder.append(value)
|
|
}
|
|
|
|
func encode<T>(_ value: T) throws where T: Encodable {
|
|
try self.encoder.append(value)
|
|
}
|
|
|
|
mutating func nestedContainer<NestedKey>(keyedBy keyType: NestedKey.Type) -> KeyedEncodingContainer<NestedKey> where NestedKey: CodingKey {
|
|
return self.encoder.container(keyedBy: keyType)
|
|
}
|
|
|
|
mutating func nestedUnkeyedContainer() -> UnkeyedEncodingContainer {
|
|
self.encoder.unkeyedContainer()
|
|
}
|
|
|
|
mutating func superEncoder() -> Encoder {
|
|
self.encoder
|
|
}
|
|
}
|