Skip to content

Commit 122b945

Browse files
authored
Move to swift-extras (#67)
1 parent a5c49df commit 122b945

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+117
-117
lines changed

.github/workflows/ci.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
- name: Test
3838
run: swift test --enable-code-coverage --enable-test-discovery
3939
- name: Convert coverage files
40-
run: llvm-cov export -format="lcov" .build/debug/pure-swift-jsonPackageTests.xctest -instr-profile .build/debug/codecov/default.profdata > info.lcov
40+
run: llvm-cov export -format="lcov" .build/debug/swift-extras-jsonPackageTests.xctest -instr-profile .build/debug/codecov/default.profdata > info.lcov
4141
- name: Install curl
4242
run: apt-get update && apt-get install -y curl # required by the codecov action.
4343
- name: Upload to codecov.io
@@ -94,7 +94,7 @@ jobs:
9494
fail-fast: false
9595
matrix:
9696
xcode:
97-
- Xcode_11.1.app
97+
- Xcode_11.2.app
9898
- Xcode_11.6.app
9999
- Xcode_12.2.app
100100
steps:
@@ -109,7 +109,7 @@ jobs:
109109
- name: Xcode Tests
110110
run: |
111111
swift package generate-xcodeproj --skip-extra-files --enable-code-coverage
112-
xcodebuild -quiet -parallel-testing-enabled YES -scheme pure-swift-json-Package -enableCodeCoverage YES build test
112+
xcodebuild -quiet -parallel-testing-enabled YES -scheme swift-extras-json-Package -enableCodeCoverage YES build test
113113
- name: Codecov
114114
run: bash <(curl -s https://codecov.io/bash) -t ${{secrets.CODECOV_TOKEN}} -f *.coverage.txt
115115

@@ -119,7 +119,7 @@ jobs:
119119
fail-fast: false
120120
matrix:
121121
xcode:
122-
- Xcode_11.1.app
122+
- Xcode_11.2.app
123123
- Xcode_11.6.app
124124
- Xcode_12.2.app
125125
steps:

IntegrationTests/allocation-counter-tests-framework/run-allocation-counter.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ for f in "${files[@]}"; do
259259
test -f "$f" || die "file '$f' not a file"
260260
done
261261

262-
working_dir=$(mktemp -d "$tmp_dir/.pure-swift-json-alloc-counter-tests-XXXXXX")
262+
working_dir=$(mktemp -d "$tmp_dir/.swift-extras-json-alloc-counter-tests-XXXXXX")
263263

264264
selected_hooked_functions="HookedFunctionsDoHook"
265265
selected_bootstrap="bootstrapDoHook"

IntegrationTests/run-tests.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ set -eu
1818
shopt -s nullglob
1919

2020
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
21-
tmp=$(mktemp -d /tmp/.pure-swift-json-sh-tests_XXXXXX)
21+
tmp=$(mktemp -d /tmp/.swift-extras-json-sh-tests_XXXXXX)
2222

2323
# start_time
2424
function time_diff_to_now() {

IntegrationTests/tests_04_performance/test_01_resources/run-nio-alloc-counter-tests.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fi
3939

4040
"$here/../../allocation-counter-tests-framework/run-allocation-counter.sh" \
4141
-p "$here/../../.." \
42-
-m PureSwiftJSON \
42+
-m ExtrasJSON \
4343
-s "$here/shared.swift" \
4444
-t "$tmp_dir" \
4545
"${tests_to_run[@]}"

IntegrationTests/tests_04_performance/test_01_resources/test_jsonvalue_to_bytes.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import PureSwiftJSON
1+
import ExtrasJSON
22

33
func run(identifier: String) {
44
let sampleString = SampleStructure.sampleJSON

Package.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
import PackageDescription
55

66
var package = Package(
7-
name: "pure-swift-json",
7+
name: "swift-extras-json",
88
products: [
9-
.library(name: "PureSwiftJSON", targets: ["PureSwiftJSON"]),
9+
.library(name: "ExtrasJSON", targets: ["ExtrasJSON"]),
1010
],
1111
targets: [
12-
.target(name: "PureSwiftJSON"),
13-
.testTarget(name: "PureSwiftJSONTests", dependencies: [
14-
.byName(name: "PureSwiftJSON"),
12+
.target(name: "ExtrasJSON"),
13+
.testTarget(name: "ExtrasJSONTests", dependencies: [
14+
.byName(name: "ExtrasJSON"),
1515
]),
1616
.testTarget(name: "LearningTests", dependencies: [
17-
.byName(name: "PureSwiftJSON"),
17+
.byName(name: "ExtrasJSON"),
1818
]),
1919
]
2020
)

PerfTests/Package.resolved

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"repositoryURL": "https://github.com/apple/swift-nio.git",
1616
"state": {
1717
"branch": null,
18-
"revision": "4409b57d4c0c40d41ac2b320fccf02e4d451e3db",
19-
"version": "2.13.0"
18+
"revision": "c3e2359c55cd8b47207ab7363b77c9c398a95294",
19+
"version": "2.23.0"
2020
}
2121
},
2222
{

PerfTests/Package.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import PackageDescription
55

66
var package = Package(
7-
name: "pure-swift-json-performance",
7+
name: "swift-extras-json-performance",
88
products: [
99
.executable(name: "CodingPerfTests", targets: ["CodingPerfTests"]),
1010
],
@@ -17,7 +17,7 @@ var package = Package(
1717
.target(
1818
name: "CodingPerfTests",
1919
dependencies: [
20-
.product(name: "PureSwiftJSON", package: "pure-swift-json"),
20+
.product(name: "ExtrasJSON", package: "swift-extras-json"),
2121
.product(name: "NIO", package: "swift-nio"),
2222
.product(name: "NIOFoundationCompat", package: "swift-nio"),
2323
.product(name: "IkigaJSON", package: "IkigaJSON"),

PerfTests/Sources/CodingPerfTests/main.swift

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import ExtrasJSON
12
import Foundation
2-
import PureSwiftJSON
33
#if os(macOS)
44
import SwiftyJSON
55
#endif
@@ -20,15 +20,15 @@ func timing(name: String, execute: () throws -> Void) rethrows -> TimeInterval {
2020

2121
let sampleString = SampleStructure.sampleJSON
2222
let sampleBytes = [UInt8](sampleString.utf8)
23-
let sampleStruct = try PSJSONDecoder().decode([SampleStructure].self, from: sampleBytes)
23+
let sampleStruct = try XJSONDecoder().decode([SampleStructure].self, from: sampleBytes)
2424
let sampleJSON = try JSONParser().parse(bytes: sampleBytes)
2525

2626
print("Number of invocations: \(runs)")
2727

2828
print("------------------------------------------")
2929
print("JSONValue to bytes")
3030

31-
let toBytes = timing(name: "PureSwift ") {
31+
let toBytes = timing(name: "ExtrasJSON ") {
3232
for _ in 1 ... runs {
3333
var bytes = [UInt8]()
3434
bytes.reserveCapacity(2000)
@@ -53,10 +53,10 @@ let ikigaEncoding = try timing(name: "Ikiga ") {
5353
}
5454
}
5555

56-
let pureEncoder = PSJSONEncoder()
57-
let pureEncoding = try timing(name: "PureSwift ") {
56+
let xjsonEncoder = XJSONEncoder()
57+
let xjsonEncoding = try timing(name: "ExtrasJSON ") {
5858
for _ in 1 ... runs {
59-
_ = try pureEncoder.encode(sampleStruct)
59+
_ = try xjsonEncoder.encode(sampleStruct)
6060
}
6161
}
6262

@@ -65,21 +65,21 @@ print("Reading")
6565

6666
let sampleData = sampleString.data(using: .utf8)!
6767

68-
let reading = timing(name: "PureSwift on [UInt8] ") {
68+
let reading = timing(name: "ExtrasJSON on [UInt8] ") {
6969
for _ in 1 ... runs {
7070
var iterator = sampleBytes.makeIterator()
7171
while let _ = iterator.next() {}
7272
}
7373
}
7474

75-
let readingFoundationData = timing(name: "PureSwift on Foundation.Data ") {
75+
let readingFoundationData = timing(name: "ExtrasJSON on Foundation.Data") {
7676
for _ in 1 ... runs {
7777
var iterator = sampleData.makeIterator()
7878
while let _ = iterator.next() {}
7979
}
8080
}
8181

82-
let readingNIOByteBuffer = timing(name: "PureSwift on NIO.ByteBuffer ") {
82+
let readingNIOByteBuffer = timing(name: "ExtrasJSON on NIO.ByteBuffer ") {
8383
for _ in 1 ... runs {
8484
var buffer = ByteBufferAllocator().buffer(capacity: sampleBytes.count)
8585
buffer.writeBytes(sampleBytes)
@@ -98,19 +98,19 @@ let foundationParsing = try timing(name: "Foundation on Foundation.Data") {
9898
}
9999
}
100100

101-
let pureParsing = try timing(name: "PureSwift on [UInt8] ") {
101+
let xjsonParsing = try timing(name: "ExtrasJSON on [UInt8] ") {
102102
for _ in 1 ... runs {
103103
_ = try JSONParser().parse(bytes: sampleBytes)
104104
}
105105
}
106106

107-
let pureParsingData = try timing(name: "PureSwift on Foundation.Data ") {
107+
let xjsonParsingData = try timing(name: "ExtrasJSON on Foundation.Data") {
108108
for _ in 1 ... runs {
109109
_ = try JSONParser().parse(bytes: sampleData)
110110
}
111111
}
112112

113-
let pureParsingBuffer = try timing(name: "PureSwift on NIO.ByteBuffer ") {
113+
let xjsonParsingBuffer = try timing(name: "ExtrasJSON on NIO.ByteBuffer ") {
114114
for _ in 1 ... runs {
115115
var buffer = ByteBufferAllocator().buffer(capacity: sampleBytes.count)
116116
buffer.writeBytes(sampleBytes)
@@ -166,24 +166,24 @@ let ikigaDecodingBuffer = try timing(name: "IkigaJSON on NIO.ByteBuffer ") {
166166
}
167167
}
168168

169-
let pureDecoder = PSJSONDecoder()
170-
let pureDecoding = try timing(name: "PureSwift on [UInt8] ") {
169+
let xjsonDecoder = XJSONDecoder()
170+
let xjsonDecoding = try timing(name: "ExtrasJSON on [UInt8] ") {
171171
for _ in 1 ... runs {
172-
_ = try pureDecoder.decode([SampleStructure].self, from: sampleBytes)
172+
_ = try xjsonDecoder.decode([SampleStructure].self, from: sampleBytes)
173173
}
174174
}
175175

176-
let pureDecodingOnData = try timing(name: "PureSwift on Foundation.Data ") {
176+
let xjsonDecodingOnData = try timing(name: "ExtrasJSON on Foundation.Data") {
177177
for _ in 1 ... runs {
178-
_ = try pureDecoder.decode([SampleStructure].self, from: sampleData)
178+
_ = try xjsonDecoder.decode([SampleStructure].self, from: sampleData)
179179
}
180180
}
181181

182-
let pureDecodingOnByteBuffer = try timing(name: "PureSwift on NIO.ByteBuffer ") {
182+
let xjsonDecodingOnByteBuffer = try timing(name: "ExtrasJSON on NIO.ByteBuffer ") {
183183
for _ in 1 ... runs {
184184
var buffer = ByteBufferAllocator().buffer(capacity: sampleBytes.count)
185185
buffer.writeBytes(sampleBytes)
186-
_ = try pureDecoder.decode(
186+
_ = try xjsonDecoder.decode(
187187
[SampleStructure].self,
188188
from: buffer.readBytes(length: buffer.readableBytes)!
189189
)

README.md

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# pure-swift-json
1+
# swift-extras-json
22

33
[![Swift 5.1](https://img.shields.io/badge/Swift-5.1-blue.svg)](https://swift.org/download/)
4-
[![github-actions](https://github.com/fabianfett/pure-swift-json/workflows/CI/badge.svg)](https://github.com/fabianfett/pure-swift-json/actions)
5-
[![codecov](https://codecov.io/gh/fabianfett/pure-swift-json/branch/main/graph/badge.svg)](https://codecov.io/gh/fabianfett/pure-swift-json)
4+
[![github-actions](https://github.com/swift-extras/swift-extras-json/workflows/CI/badge.svg)](https://github.com/swift-extras/swift-extras-json/actions)
5+
[![codecov](https://codecov.io/gh/swift-extras/swift-extras-json/branch/main/graph/badge.svg)](https://codecov.io/gh/swift-extras/swift-extras-json)
66

7-
This package provides a json encoder and decoder in pure Swift (without the use of Foundation or any other dependency).
7+
This package provides a json encoder and decoder in Swift (without the use of Foundation or any other dependency).
88
The implementation is [RFC8259](https://tools.ietf.org/html/rfc8259) compliant. It offers a significant performance improvement compared to the Foundation implementation on Linux.
99

10-
If you like the idea of using pure Swift without any dependencies, you might also like my reimplementation of Base64 in pure Swift: [`swift-base64-kit`](https://github.com/fabianfett/swift-base64-kit)
10+
If you like the idea of using Swift without any dependencies, you might also like our reimplementation of Base64 in Swift: [`swift-extras-base64`](https://github.com/swift-extras/swift-extras-base64)
1111

1212
## Goals
1313

@@ -29,59 +29,59 @@ If you like the idea of using pure Swift without any dependencies, you might als
2929

3030
## Usage
3131

32-
Add `pure-swift-json` as dependency to your `Package.swift`:
32+
Add `swift-extras-json` as dependency to your `Package.swift`:
3333

3434
```swift
3535
dependencies: [
36-
.package(url: "https://github.com/fabianfett/pure-swift-json.git", .upToNextMajor(from: "0.2.1")),
36+
.package(url: "https://github.com/swift-extras/swift-extras-json.git", .upToNextMajor(from: "0.6.0")),
3737
],
3838
```
3939

40-
Add `PureSwiftJSON` to the target you want to use it in.
40+
Add `ExtrasJSON` to the target you want to use it in.
4141

4242
```swift
4343
targets: [
4444
.target(name: "MyFancyTarget", dependencies: [
45-
.product(name: "PureSwiftJSON", package: "pure-swift-json"),
45+
.product(name: "ExtrasJSON", package: "swift-extras-json"),
4646
])
4747
]
4848
```
4949

5050
Use it as you would use the Foundation encoder and decoder.
5151

5252
```swift
53-
import PureSwiftJSON
53+
import ExtrasJSON
5454

55-
let bytesArray = try PSJSONEncoder().encode(myEncodable)
56-
let myDecodable = try PSJSONDecoder().decode(MyDecodable.self, from: bytes)
55+
let bytesArray = try XJSONEncoder().encode(myEncodable)
56+
let myDecodable = try XJSONDecoder().decode(MyDecodable.self, from: bytes)
5757
```
5858

5959
### Use with SwiftNIO ByteBuffer
6060

6161
For maximal performance create an `[UInt8]` from your `ByteBuffer`, even though `buffer.readableBytesView` would technically work as well.
6262

6363
```swift
64-
let result = try pureDecoder.decode(
64+
let result = try XJSONDecoder().decode(
6565
[SampleStructure].self,
6666
from: buffer.readBytes(length: buffer.readableBytes)!)
6767
```
6868

6969
```swift
70-
let bytes = try pureEncoder.encode(encodable)
70+
let bytes = try XJSONEncoder().encode(encodable)
7171
var buffer = byteBufferAllocator.buffer(capacity: bytes.count)
7272
buffer.writeBytes(bytes)
7373
```
7474

7575

7676
### Use with Vapor 4
7777

78-
Increase the performance of your Vapor 4 API by using `pure-swift-json` instead of the default Foundation implementation. First you'll need to implement the conformance to Vapor's `ContentEncoder` and `ContentDecoder` as described in the [Vapor docs](https://docs.vapor.codes/4.0/content/#custom-coders).
78+
Increase the performance of your Vapor 4 API by using `swift-extras-json` instead of the default Foundation implementation. First you'll need to implement the conformance to Vapor's `ContentEncoder` and `ContentDecoder` as described in the [Vapor docs](https://docs.vapor.codes/4.0/content/#custom-coders).
7979

8080
```swift
8181
import Vapor
82-
import PureSwiftJSON
82+
import ExtrasJSON
8383

84-
extension PSJSONEncoder: ContentEncoder {
84+
extension XJSONEncoder: ContentEncoder {
8585
public func encode<E: Encodable>(
8686
_ encodable: E,
8787
to body: inout ByteBuffer,
@@ -94,7 +94,7 @@ extension PSJSONEncoder: ContentEncoder {
9494
}
9595
}
9696

97-
extension PSJSONDecoder: ContentDecoder {
97+
extension XJSONDecoder: ContentDecoder {
9898
public func decode<D: Decodable>(
9999
_ decodable: D.Type,
100100
from body: ByteBuffer,
@@ -112,10 +112,10 @@ extension PSJSONDecoder: ContentDecoder {
112112
Next, register the encoder and decoder for use in Vapor:
113113

114114
```swift
115-
let decoder = PSJSONDecoder()
115+
let decoder = XJSONDecoder()
116116
ContentConfiguration.global.use(decoder: decoder, for: .json)
117117

118-
let encoder = PSJSONEncoder()
118+
let encoder = XJSONEncoder()
119119
ContentConfiguration.global.use(encoder: encoder, for: .json)
120120
```
121121

@@ -138,7 +138,7 @@ $ swift run -c release
138138
| | macOS Swift 5.1 | macOS Swift 5.2 | Linux Swift 5.1 | Linux Swift 5.2 |
139139
|:--|:--|:--|:--|:--|
140140
| Foundation | 2.61s | 2.62s | 13.03s | 12.52s |
141-
| PureSwiftJSON | 1.23s | 1.25s | 1.13s | 1.05s |
141+
| ExtrasJSON | 1.23s | 1.25s | 1.13s | 1.05s |
142142
| Speedup | ~2x | ~2x | **~10x** | **~10x** |
143143

144144

@@ -147,7 +147,7 @@ $ swift run -c release
147147
| | macOS Swift 5.1 | macOS Swift 5.2 | Linux Swift 5.1 | Linux Swift 5.2 |
148148
|:--|:--|:--|:--|:--|
149149
| Foundation | 2.72s | 3.04s | 10.27s | 10.65s |
150-
| PureSwiftJSON | 1.70s | 1.72s | 1.39s | 1.16s |
150+
| ExtrasJSON | 1.70s | 1.72s | 1.39s | 1.16s |
151151
| Speedup | ~1.5x | ~1.5x | **~7x** | **~8x** |
152152

153153
## Workarounds
@@ -242,7 +242,7 @@ struct MyEvent: Decodable {
242242
}
243243
```
244244

245-
Checkout a full example in the test file [DateCodingTests](https://github.com/fabianfett/pure-swift-json/blob/main/Tests/PureSwiftJSONTests/DateCodingTests.swift).
245+
Checkout a full example in the test file [DateCodingTests](https://github.com/swift-extras/swift-extras-json/blob/main/Tests/ExtrasJSONTests/DateCodingTests.swift).
246246

247247
### UTF-16 and UTF-32
248248

@@ -260,7 +260,7 @@ let utf8 = Array(String(decoding: utf32, as: Unicode.UTF32.self).utf8)
260260

261261
## Contributing
262262

263-
Please feel welcome and encouraged to contribute to `pure-swift-json`. This is a very young endeavour and help is always welcome.
263+
Please feel welcome and encouraged to contribute to `swift-extras-json`. This is a very young endeavour and help is always welcome.
264264

265265
If you've found a bug, have a suggestion, or need help getting started, please open an Issue or a PR. If you use this package, I'd be grateful for sharing your experience.
266266

Sources/PureSwiftJSON/Decoding/JSONDecoder.swift renamed to Sources/ExtrasJSON/Decoding/JSONDecoder.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
public struct PSJSONDecoder {
2+
public struct XJSONDecoder {
33
public var userInfo: [CodingUserInfoKey: Any] = [:]
44

55
public init() {}

0 commit comments

Comments
 (0)