mirror of
https://github.com/apple/swift-http-structured-headers
synced 2026-11-23 04:34:21 +00:00
43 lines
1.2 KiB
Swift
43 lines
1.2 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// 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
|
|
|
|
struct _StructuredHeaderCodingKey : CodingKey {
|
|
var stringValue: String
|
|
var intValue: Int?
|
|
|
|
init(stringValue: String) {
|
|
self.stringValue = stringValue
|
|
self.intValue = nil
|
|
}
|
|
|
|
init(intValue: Int) {
|
|
self.stringValue = "\(intValue)"
|
|
self.intValue = intValue
|
|
}
|
|
|
|
init<Key: CodingKey>(_ key: Key, keyDecodingStrategy: StructuredFieldDecoder.KeyDecodingStrategy?) {
|
|
switch keyDecodingStrategy {
|
|
case .none:
|
|
self.stringValue = key.stringValue
|
|
case .some(.lowercase):
|
|
self.stringValue = key.stringValue.lowercased()
|
|
default:
|
|
preconditionFailure("Invalid key decoding strategy")
|
|
}
|
|
|
|
self.intValue = key.intValue
|
|
}
|
|
}
|