mirror of
https://github.com/apple/swift-http-structured-headers
synced 2026-11-25 04:47:48 +00:00
Apply formatting
This commit is contained in:
1 parent
89ef2cf73d
commit
3f73125a0d
28 files changed
+198
-184
No files matched your search
@@ -19,7 +19,7 @@ import StructuredHeaders
|
||||
public struct StructuredFieldEncoder {
|
||||
public var keyEncodingStrategy: KeyEncodingStrategy?
|
||||
|
||||
public init() { }
|
||||
public init() {}
|
||||
}
|
||||
|
||||
extension StructuredFieldEncoder {
|
||||
@@ -90,7 +90,7 @@ class _StructuredFieldEncoder {
|
||||
self.serializer = serializer
|
||||
self._codingPath = []
|
||||
self.keyEncodingStrategy = keyEncodingStrategy
|
||||
self.currentStackEntry = CodingStackEntry(key: .init(stringValue: ""), storage: .itemHeader) // This default doesn't matter right now.
|
||||
self.currentStackEntry = CodingStackEntry(key: .init(stringValue: ""), storage: .itemHeader) // This default doesn't matter right now.
|
||||
}
|
||||
|
||||
fileprivate func encodeDictionaryField<StructuredField: Encodable>(_ data: StructuredField) throws -> [UInt8] {
|
||||
@@ -157,10 +157,10 @@ class _StructuredFieldEncoder {
|
||||
|
||||
extension _StructuredFieldEncoder: Encoder {
|
||||
var codingPath: [CodingKey] {
|
||||
return self._codingPath.map { $0.key as CodingKey }
|
||||
self._codingPath.map { $0.key as CodingKey }
|
||||
}
|
||||
|
||||
var userInfo: [CodingUserInfoKey : Any] {
|
||||
var userInfo: [CodingUserInfoKey: Any] {
|
||||
[:]
|
||||
}
|
||||
|
||||
@@ -184,11 +184,11 @@ extension _StructuredFieldEncoder: Encoder {
|
||||
}
|
||||
|
||||
func unkeyedContainer() -> UnkeyedEncodingContainer {
|
||||
return StructuredFieldUnkeyedEncodingContainer(encoder: self)
|
||||
StructuredFieldUnkeyedEncodingContainer(encoder: self)
|
||||
}
|
||||
|
||||
func singleValueContainer() -> SingleValueEncodingContainer {
|
||||
return self
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ extension _StructuredFieldEncoder: SingleValueEncodingContainer {
|
||||
}
|
||||
|
||||
func encode(_ data: Decimal) throws {
|
||||
let significand = (data.significand as NSNumber).intValue // Yes, really.
|
||||
let significand = (data.significand as NSNumber).intValue // Yes, really.
|
||||
guard let exponent = Int8(exactly: data.exponent) else {
|
||||
throw StructuredHeaderError.invalidIntegerOrDecimal
|
||||
}
|
||||
@@ -273,7 +273,7 @@ extension _StructuredFieldEncoder: SingleValueEncodingContainer {
|
||||
try self.currentStackEntry.storage.insertBareItem(.decimal(pd))
|
||||
}
|
||||
|
||||
func encode<T>(_ value: T) throws where T : Encodable {
|
||||
func encode<T>(_ value: T) throws where T: Encodable {
|
||||
switch value {
|
||||
case let value as UInt8:
|
||||
try self.encode(value)
|
||||
@@ -421,7 +421,7 @@ extension _StructuredFieldEncoder {
|
||||
}
|
||||
|
||||
func append(_ value: Decimal) throws {
|
||||
let significand = (value.significand as NSNumber).intValue // Yes, really.
|
||||
let significand = (value.significand as NSNumber).intValue // Yes, really.
|
||||
guard let exponent = Int8(exactly: value.exponent) else {
|
||||
throw StructuredHeaderError.invalidIntegerOrDecimal
|
||||
}
|
||||
@@ -430,7 +430,7 @@ extension _StructuredFieldEncoder {
|
||||
try self.currentStackEntry.storage.appendBareItem(.decimal(pd))
|
||||
}
|
||||
|
||||
func append<T>(_ value: T) throws where T : Encodable {
|
||||
func append<T>(_ value: T) throws where T: Encodable {
|
||||
switch value {
|
||||
case let value as UInt8:
|
||||
try self.append(value)
|
||||
@@ -588,7 +588,7 @@ extension _StructuredFieldEncoder {
|
||||
}
|
||||
|
||||
func encode(_ value: Decimal, forKey key: String) throws {
|
||||
let significand = (value.significand as NSNumber).intValue // Yes, really.
|
||||
let significand = (value.significand as NSNumber).intValue // Yes, really.
|
||||
guard let exponent = Int8(exactly: value.exponent) else {
|
||||
throw StructuredHeaderError.invalidIntegerOrDecimal
|
||||
}
|
||||
@@ -686,7 +686,6 @@ extension _StructuredFieldEncoder {
|
||||
throw StructuredHeaderError.invalidTypeForItem
|
||||
}
|
||||
|
||||
|
||||
case .listHeader, .list, .itemHeader, .bareInnerList,
|
||||
.parameters:
|
||||
throw StructuredHeaderError.invalidTypeForItem
|
||||
@@ -896,7 +895,6 @@ extension _StructuredFieldEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension Item where BaseData == _StructuredFieldEncoder.NodeType.DataType {
|
||||
fileprivate init(_ partialItem: _StructuredFieldEncoder.NodeType.PartialItem) {
|
||||
self.init(bareItem: partialItem.bareItem!, parameters: partialItem.parameters)
|
||||
|
||||
+6
-9
@@ -26,12 +26,11 @@ struct StructuredFieldKeyedEncodingContainer<Key: CodingKey> {
|
||||
|
||||
extension StructuredFieldKeyedEncodingContainer: KeyedEncodingContainerProtocol {
|
||||
var codingPath: [CodingKey] {
|
||||
return self.encoder.codingPath
|
||||
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 {
|
||||
@@ -90,25 +89,23 @@ extension StructuredFieldKeyedEncodingContainer: KeyedEncodingContainerProtocol
|
||||
try self.encoder.encode(value, forKey: key.stringValue)
|
||||
}
|
||||
|
||||
mutating func encode<T>(_ value: T, forKey key: Key) throws where T : Encodable {
|
||||
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 {
|
||||
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()
|
||||
self.encoder.unkeyedContainer()
|
||||
}
|
||||
|
||||
mutating func superEncoder() -> Encoder {
|
||||
return self.encoder
|
||||
self.encoder
|
||||
}
|
||||
|
||||
mutating func superEncoder(forKey key: Key) -> Encoder {
|
||||
return self.encoder
|
||||
self.encoder
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+6
-8
@@ -26,11 +26,11 @@ struct StructuredFieldUnkeyedEncodingContainer {
|
||||
|
||||
extension StructuredFieldUnkeyedEncodingContainer: UnkeyedEncodingContainer {
|
||||
var codingPath: [CodingKey] {
|
||||
return self.encoder.codingPath
|
||||
self.encoder.codingPath
|
||||
}
|
||||
|
||||
var count: Int {
|
||||
return self.encoder.count
|
||||
self.encoder.count
|
||||
}
|
||||
|
||||
func encodeNil() throws {
|
||||
@@ -93,21 +93,19 @@ extension StructuredFieldUnkeyedEncodingContainer: UnkeyedEncodingContainer {
|
||||
try self.encoder.append(value)
|
||||
}
|
||||
|
||||
func encode<T>(_ value: T) throws where T : Encodable {
|
||||
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 {
|
||||
mutating func nestedContainer<NestedKey>(keyedBy keyType: NestedKey.Type) -> KeyedEncodingContainer<NestedKey> where NestedKey: CodingKey {
|
||||
return self.encoder.container(keyedBy: keyType)
|
||||
}
|
||||
|
||||
mutating func nestedUnkeyedContainer() -> UnkeyedEncodingContainer {
|
||||
return self.encoder.unkeyedContainer()
|
||||
self.encoder.unkeyedContainer()
|
||||
}
|
||||
|
||||
mutating func superEncoder() -> Encoder {
|
||||
return self.encoder
|
||||
self.encoder
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user