Skip to content

Commit 4858028

Browse files
authored
Merge branch 'main' into enable_MemberImportVisibility_check
2 parents a53672d + 847a630 commit 4858028

File tree

7 files changed

+36
-28
lines changed

7 files changed

+36
-28
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ Provides parsing and serialization facilities for structured header field values
66

77
## About Structured Header Field Values
88

9-
HTTP Structured Header Field Values are a HTTP extension recorded in [RFC 8941](https://www.rfc-editor.org/rfc/rfc8941.html). They provide a set of data types and algorithms for handling HTTP header field values in a consistent way, allowing a single parser and serializer to handle a wide range of header field values.
9+
HTTP Structured Header Field Values are a HTTP extension recorded in [RFC 9651](https://www.ietf.org/rfc/rfc9651.html). They provide a set of data types and algorithms for handling HTTP header field values in a consistent way, allowing a single parser and serializer to handle a wide range of header field values.
1010

1111
## Swift HTTP Structured Header Field Values
1212

13-
This package provides a parser and serializer that implement RFC 8941. They are entirely complete, able to handle all valid HTTP structured header field values. This package also provides `Encoder` and `Decoder` objects for working with Codable in Swift. This allows rapid prototyping and experimentation with HTTP structured header field values, as well as interaction with the wider Swift Codable community.
13+
This package provides a parser and serializer that implement RFC 9651. They are entirely complete, able to handle all valid HTTP structured header field values. This package also provides `Encoder` and `Decoder` objects for working with Codable in Swift. This allows rapid prototyping and experimentation with HTTP structured header field values, as well as interaction with the wider Swift Codable community.
1414

1515
This package provides two top-level modules: `StructuredFieldValues` and `RawStructuredFieldValues`.
1616

1717
The base module, `RawStructuredFieldValues`, provides a low-level implementation of a serializer and parser. Both of these have been written to avoid using Foundation, making them suitable for a range of use-cases where Foundation is not available. They rely entirely on the Swift standard library and are implemented as generically as possible. One of the limitations due to the absence of Foundation is that this interface is not capable of performing Base64 encoding or decoding: users are free to bring whatever encoder and decoder they choose to use.
1818

1919
This API is low-level, exposing the raw parse tree as the format for the serializer and parser. This allows high-performance and high-flexibility parsing and serialization, at the cost of being verbose and complex. Users are required to understand the structured header format and to operate the slightly awkward types, but maximal fidelity is retained and the performance overhead is low.
2020

21-
The upper-level module, `StructuredFieldValues`, brings along the `Encoder` and `Decoder` and also adds a dependency on Foundation. This Foundation dependency is necessary to correctly handle the base64 formatting, as well as to provide a good natural container for binary data: `Data`. This interface is substantially friendlier and easier to work with, using Swift's `Codable` support to provide a great user experience.
21+
The upper-level module, `StructuredFieldValues`, brings along the `Encoder` and `Decoder` and also adds a dependency on Foundation. This Foundation dependency is necessary to correctly handle the base64 formatting, as well as to provide a good natural container for binary data: `Data`, and for dates: `Date`. This interface is substantially friendlier and easier to work with, using Swift's `Codable` support to provide a great user experience.
2222

2323
In most cases users should prefer to use `StructuredFieldValues` unless they know they need the performance advantages of `RawStructuredFieldValues`. The experience will be much better.
2424

@@ -56,12 +56,12 @@ let encoder = StructuredFieldValueEncoder()
5656
let serialized = try encoder.encode(AcceptCH(items: ["Sec-CH-Example", "Sec-CH-Example-2"]))
5757
```
5858

59-
However, structured header field values can be substantially more complex. Structured header fields can make use of 4 containers and 6 base item types. The containers are:
59+
However, structured header field values can be substantially more complex. Structured header fields can make use of 4 containers and 8 base item types. The containers are:
6060

6161
1. Dictionaries. These are top-level elements and associate token keys with values. The values may be items, or may be inner lists, and each value may also have parameters associated with them. `StructuredFieldValues` can model dictionaries as either Swift objects (where the property names are dictionary keys).
6262
2. Lists. These are top-level elements, providing a sequence of items or inner lists. Each item or inner list may have parameters associated with them. `StructuredFieldValues` models these as Swift objects with one key, `items`, that must be a collection of entries.
6363
3. Inner Lists. These are lists that may be sub-entries of a dictionary or a list. The list entries are items, which may have parameters associated with them: additionally, an inner list may have parameters associated with itself as well. `StructuredFieldValues` models these as either Swift `Array`s _or_, if it's important to extract parameters, as a two-field Swift `struct` where one field is called `items` and contains an `Array`, and other field is called `parameters` and contains a dictionary.
64-
4. Parameters. Parameters associated token keys with items without parameters. These are used to store metadata about objects within a field. `StructuredFieldValues` models these as either Swift objects (where the property names are the parameter keys) or as Swift dictionaries.
64+
4. Parameters. Parameters associate token keys with items without parameters. These are used to store metadata about objects within a field. `StructuredFieldValues` models these as either Swift objects (where the property names are the parameter keys) or as Swift dictionaries.
6565

6666
The base types are:
6767

@@ -71,6 +71,8 @@ The base types are:
7171
4. Tokens. `StructuredFieldValues` models these as Swift's `String` type, where the range of characters is restricted.
7272
5. Strings. `StructuredFieldValues` models these as Swift's `String` type.
7373
6. Binary data. `StructuredFieldValues` models this as Foundation's `Data` type.
74+
7. Dates. `StructuredFieldValues` models these as Foundation's `Date` type.
75+
8. Display strings. `StructuredFieldValues` models these as the `DisplayString` type which it provides.
7476

7577
For any Structured Header Field Value Item, the item may either be represented directly by the appropriate type, or by a Swift struct with two properties: `item` and `parameters`. This latter mode is how parameters on a given item may be captured.
7678

Sources/RawStructuredFieldValues/ComponentTypes.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ extension BareItem {
9494
self = .bool(b)
9595

9696
case .integer(let i):
97-
self = .integer(i)
97+
self = .integer(Int(i))
9898

9999
case .decimal(let d):
100100
self = .decimal(d)
@@ -126,7 +126,7 @@ public enum RFC9651BareItem: Sendable {
126126
case bool(Bool)
127127

128128
/// An integer item.
129-
case integer(Int)
129+
case integer(Int64)
130130

131131
/// A decimal item.
132132
case decimal(PseudoDecimal)
@@ -142,7 +142,7 @@ public enum RFC9651BareItem: Sendable {
142142
case token(String)
143143

144144
/// A date item.
145-
case date(Int)
145+
case date(Int64)
146146

147147
/// A display string item.
148148
case displayString(String)
@@ -155,7 +155,7 @@ extension RFC9651BareItem: ExpressibleByBooleanLiteral {
155155
}
156156

157157
extension RFC9651BareItem: ExpressibleByIntegerLiteral {
158-
public init(integerLiteral value: Int) {
158+
public init(integerLiteral value: Int64) {
159159
self = .integer(value)
160160
}
161161
}
@@ -184,7 +184,7 @@ extension RFC9651BareItem {
184184
self = .bool(b)
185185

186186
case .integer(let i):
187-
self = .integer(i)
187+
self = .integer(Int64(i))
188188

189189
case .decimal(let d):
190190
self = .decimal(d)

Sources/RawStructuredFieldValues/Docs.docc/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ Provides parsing and serialization facilities for structured header field values
88

99
### About Structured Header Field Values
1010

11-
HTTP Structured Header Field Values are a HTTP extension recorded in [RFC 8941](https://www.rfc-editor.org/rfc/rfc8941.html). They provide a set of data types and algorithms for handling HTTP header field values in a consistent way, allowing a single parser and serializer to handle a wide range of header field values.
11+
HTTP Structured Header Field Values are a HTTP extension recorded in [RFC 9651](https://www.ietf.org/rfc/rfc9651.html). They provide a set of data types and algorithms for handling HTTP header field values in a consistent way, allowing a single parser and serializer to handle a wide range of header field values.
1212

1313
### Swift HTTP Structured Header Field Values
1414

15-
This package provides a parser and serializer that implement RFC 8941. They are entirely complete, able to handle all valid HTTP structured header field values.
15+
This package provides a parser and serializer that implement RFC 9651. They are entirely complete, able to handle all valid HTTP structured header field values.
1616

1717
This package provides two top-level modules: `StructuredFieldValues` and `RawStructuredFieldValues`.
1818

1919
This module, `RawStructuredFieldValues`, provides a low-level implementation of a serializer and parser. Both of these have been written to avoid using Foundation, making them suitable for a range of use-cases where Foundation is not available. They rely entirely on the Swift standard library and are implemented as generically as possible. One of the limitations due to the absence of Foundation is that this interface is not capable of performing Base64 encoding or decoding: users are free to bring whatever encoder and decoder they choose to use.
2020

2121
This API is low-level, exposing the raw parse tree as the format for the serializer and parser. This allows high-performance and high-flexibility parsing and serialization, at the cost of being verbose and complex. Users are required to understand the structured header format and to operate the slightly awkward types, but maximal fidelity is retained and the performance overhead is low.
2222

23-
The upper-level module, `StructuredFieldValues`, brings along the `Encoder` and `Decoder` and also adds a dependency on Foundation. This Foundation dependency is necessary to correctly handle the base64 formatting, as well as to provide a good natural container for binary data: `Data`. This interface is substantially friendlier and easier to work with, using Swift's `Codable` support to provide a great user experience.
23+
The upper-level module, `StructuredFieldValues`, brings along the `Encoder` and `Decoder` and also adds a dependency on Foundation. This Foundation dependency is necessary to correctly handle the base64 formatting, as well as to provide a good natural container for binary data: `Data`, and for dates: `Date`. This interface is substantially friendlier and easier to work with, using Swift's `Codable` support to provide a great user experience.
2424

2525
In most cases users should prefer to use `StructuredFieldValues` unless they know they need the performance advantages of `RawStructuredFieldValues`. The experience will be much better.
2626

Sources/RawStructuredFieldValues/FieldParser.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ extension StructuredFieldValueParser {
232232
}
233233

234234
private mutating func _parseAnIntegerOrDecimal(isDate: Bool) throws -> RFC9651BareItem {
235-
var sign = 1
235+
var sign = Int64(1)
236236
var type = IntegerOrDecimal.integer
237237

238238
if let first = self.underlyingData.first, first == asciiDash {
@@ -304,7 +304,7 @@ extension StructuredFieldValueParser {
304304
case .integer:
305305
// This intermediate string is sad, we should rewrite this manually to avoid it.
306306
// This force-unwrap is safe, as we have validated that all characters are ascii digits.
307-
let baseInt = Int(String(decoding: integerBytes, as: UTF8.self), radix: 10)!
307+
let baseInt = Int64(String(decoding: integerBytes, as: UTF8.self), radix: 10)!
308308
let resultingInt = baseInt * sign
309309

310310
if isDate {

Sources/StructuredFieldValues/Docs.docc/index.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ Provides parsing and serialization facilities for structured header field values
88

99
### About Structured Header Field Values
1010

11-
HTTP Structured Header Field Values are a HTTP extension recorded in [RFC 8941](https://www.rfc-editor.org/rfc/rfc8941.html). They provide a set of data types and algorithms for handling HTTP header field values in a consistent way, allowing a single parser and serializer to handle a wide range of header field values.
11+
HTTP Structured Header Field Values are a HTTP extension recorded in [RFC 9651](https://www.ietf.org/rfc/rfc9651.html). They provide a set of data types and algorithms for handling HTTP header field values in a consistent way, allowing a single parser and serializer to handle a wide range of header field values.
1212

1313
### Swift HTTP Structured Header Field Values
1414

15-
This package provides a parser and serializer that implement RFC 8941. They are entirely complete, able to handle all valid HTTP structured header field values. This package also provides `Encoder` and `Decoder` objects for working with Codable in Swift. This allows rapid prototyping and experimentation with HTTP structured header field values, as well as interaction with the wider Swift Codable community.
15+
This package provides a parser and serializer that implement RFC 9651. They are entirely complete, able to handle all valid HTTP structured header field values. This package also provides `Encoder` and `Decoder` objects for working with Codable in Swift. This allows rapid prototyping and experimentation with HTTP structured header field values, as well as interaction with the wider Swift Codable community.
1616

1717
This package provides two top-level modules: `StructuredFieldValues` and `RawStructuredFieldValues`.
1818

19-
This module, `StructuredFieldValues`, use the related module `RawStructuredFieldValues` to implement `Encoder` and `Decoder`. This interface is friendly and easy to work with.
19+
This module, `StructuredFieldValues`, uses the related module `RawStructuredFieldValues` to implement `Encoder` and `Decoder`. This interface is friendly and easy to work with.
2020

2121
Users who have performance problems with this solution or have specific representational needs should investigate `RawStructuredFieldValues`.
2222

@@ -56,12 +56,12 @@ let encoder = StructuredFieldValueEncoder()
5656
let serialized = try encoder.encode(AcceptCH(items: ["Sec-CH-Example", "Sec-CH-Example-2"]))
5757
```
5858

59-
However, structured header field values can be substantially more complex. Structured header fields can make use of 4 containers and 6 base item types. The containers are:
59+
However, structured header field values can be substantially more complex. Structured header fields can make use of 4 containers and 8 base item types. The containers are:
6060

6161
1. Dictionaries. These are top-level elements and associate token keys with values. The values may be items, or may be inner lists, and each value may also have parameters associated with them. `StructuredFieldValues` can model dictionaries as either Swift objects (where the property names are dictionary keys).
6262
2. Lists. These are top-level elements, providing a sequence of items or inner lists. Each item or inner list may have parameters associated with them. `StructuredFieldValues` models these as Swift objects with one key, `items`, that must be a collection of entries.
6363
3. Inner Lists. These are lists that may be sub-entries of a dictionary or a list. The list entries are items, which may have parameters associated with them: additionally, an inner list may have parameters associated with itself as well. `StructuredFieldValues` models these as either Swift `Array`s _or_, if it's important to extract parameters, as a two-field Swift `struct` where one field is called `items` and contains an `Array`, and other field is called `parameters` and contains a dictionary.
64-
4. Parameters. Parameters associated token keys with items without parameters. These are used to store metadata about objects within a field. `StructuredFieldValues` models these as either Swift objects (where the property names are the parameter keys) or as Swift dictionaries.
64+
4. Parameters. Parameters associate token keys with items without parameters. These are used to store metadata about objects within a field. `StructuredFieldValues` models these as either Swift objects (where the property names are the parameter keys) or as Swift dictionaries.
6565

6666
The base types are:
6767

@@ -71,6 +71,8 @@ The base types are:
7171
4. Tokens. `StructuredFieldValues` models these as Swift's `String` type, where the range of characters is restricted.
7272
5. Strings. `StructuredFieldValues` models these as Swift's `String` type.
7373
6. Binary data. `StructuredFieldValues` models this as Foundation's `Data` type.
74+
7. Dates. `StructuredFieldValues` models these as Foundation's `Date` type.
75+
8. Display strings. `StructuredFieldValues` models these as the `DisplayString` type which it provides.
7476

7577
For any Structured Header Field Value Item, the item may either be represented directly by the appropriate type, or by a Swift struct with two properties: `item` and `parameters`. This latter mode is how parameters on a given item may be captured.
7678

@@ -83,6 +85,10 @@ The top-level Structured Header Field Value must identify what kind of header fi
8385
- ``StructuredFieldValue``
8486
- ``StructuredFieldType``
8587

88+
### Helper Types
89+
90+
- ``DisplayString``
91+
8692
### Encoding and Decoding
8793

8894
- ``StructuredFieldValueEncoder``

Sources/StructuredFieldValues/Encoder/StructuredFieldValueEncoder.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ extension _StructuredFieldEncoder: SingleValueEncodingContainer {
313313
}
314314

315315
func encode(_ data: Date) throws {
316-
let date = Int(data.timeIntervalSince1970)
316+
let date = Int64(data.timeIntervalSince1970)
317317
try self.currentStackEntry.storage.insertBareItem(.date(date))
318318
}
319319

@@ -371,7 +371,7 @@ extension _StructuredFieldEncoder: SingleValueEncodingContainer {
371371
}
372372

373373
private func _encodeFixedWidthInteger<T: FixedWidthInteger>(_ value: T) throws {
374-
guard let base = Int(exactly: value) else {
374+
guard let base = Int64(exactly: value) else {
375375
throw StructuredHeaderError.integerOutOfRange
376376
}
377377
try self.currentStackEntry.storage.insertBareItem(.integer(base))
@@ -483,7 +483,7 @@ extension _StructuredFieldEncoder {
483483
}
484484

485485
func append(_ value: Date) throws {
486-
let date = Int(value.timeIntervalSince1970)
486+
let date = Int64(value.timeIntervalSince1970)
487487
try self.currentStackEntry.storage.appendBareItem(.date(date))
488488
}
489489

@@ -562,7 +562,7 @@ extension _StructuredFieldEncoder {
562562
}
563563

564564
private func _appendFixedWidthInteger<T: FixedWidthInteger>(_ value: T) throws {
565-
guard let base = Int(exactly: value) else {
565+
guard let base = Int64(exactly: value) else {
566566
throw StructuredHeaderError.integerOutOfRange
567567
}
568568
try self.currentStackEntry.storage.appendBareItem(.integer(base))
@@ -667,7 +667,7 @@ extension _StructuredFieldEncoder {
667667

668668
func encode(_ value: Date, forKey key: String) throws {
669669
let key = self.sanitizeKey(key)
670-
let date = Int(value.timeIntervalSince1970)
670+
let date = Int64(value.timeIntervalSince1970)
671671
try self.currentStackEntry.storage.insertBareItem(.date(date), atKey: key)
672672
}
673673

@@ -789,7 +789,7 @@ extension _StructuredFieldEncoder {
789789
}
790790

791791
private func _encodeFixedWidthInteger<T: FixedWidthInteger>(_ value: T, forKey key: String) throws {
792-
guard let base = Int(exactly: value) else {
792+
guard let base = Int64(exactly: value) else {
793793
throw StructuredHeaderError.integerOutOfRange
794794
}
795795
try self.currentStackEntry.storage.insertBareItem(.integer(base), atKey: key)

0 commit comments

Comments
 (0)