Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added strict concurrency checking and Sendable conformances #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions CBORCoding.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "CBORCoding"
s.version = "1.4.0"
s.version = "1.4.1"
s.summary = "A CBOR Encoder and Decoder"
s.description = <<-DESC
A lightweight framework containing a coder pair for encoding and decoding `Codable` conforming types to and from CBOR document format for iOS, macOS, tvOS, and watchOS.
Expand All @@ -17,11 +17,12 @@ Pod::Spec.new do |s|
s.tvos.deployment_target = '12.0'
s.watchos.deployment_target = '4.0'

s.source = { :git => "https://github.com/SomeRandomiOSDev/CBORCoding.git", :tag => s.version.to_s }
s.source_files = 'Sources/**/*.swift'
s.swift_versions = ['5.0']
s.cocoapods_version = '>= 1.7.3'
s.source = { :git => "https://github.com/SomeRandomiOSDev/CBORCoding.git", :tag => s.version.to_s }
s.source_files = 'Sources/**/*.swift'
s.pod_target_xcconfig = { 'SWIFT_STRICT_CONCURRENCY' => 'complete' }
s.swift_versions = ['5.0']
s.cocoapods_version = '>= 1.7.3'

s.dependency 'Half', '~> 1.4'
s.dependency 'Half', '~> 1.4.2'

end
2 changes: 2 additions & 0 deletions CBORCoding.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,7 @@
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
TVOS_DEPLOYMENT_TARGET = 12.0;
VERSIONING_SYSTEM = "apple-generic";
Expand Down Expand Up @@ -1184,6 +1185,7 @@
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
TVOS_DEPLOYMENT_TARGET = 12.0;
VALIDATE_PRODUCT = YES;
Expand Down
2 changes: 1 addition & 1 deletion Half
24 changes: 11 additions & 13 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
{
"object": {
"pins": [
{
"package": "Half",
"repositoryURL": "https://github.com/SomeRandomiOSDev/Half",
"state": {
"branch": null,
"revision": "bb32fc7a5d5cfcee01e5442b1381450b1fcd4803",
"version": "1.4.1"
}
"pins" : [
{
"identity" : "half",
"kind" : "remoteSourceControl",
"location" : "https://github.com/SomeRandomiOSDev/Half",
"state" : {
"revision" : "14b1ab35ffdf62c999ef1016ec0f8e745a6feed5",
"version" : "1.4.2"
}
]
},
"version": 1
}
],
"version" : 2
}
20 changes: 16 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.0
// swift-tools-version:5.8
import PackageDescription

let package = Package(
Expand All @@ -16,11 +16,23 @@ let package = Package(
],

dependencies: [
.package(url: "https://github.com/SomeRandomiOSDev/Half", from: "1.4.1")
.package(url: "https://github.com/SomeRandomiOSDev/Half", from: "1.4.2")
],

targets: [
.target(name: "CBORCoding", dependencies: ["Half"]),
.testTarget(name: "CBORCodingTests", dependencies: ["CBORCoding", "Half"])
.target(
name: "CBORCoding",
dependencies: ["Half"],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),
.testTarget(
name: "CBORCodingTests",
dependencies: ["CBORCoding", "Half"],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
)
]
)
44 changes: 30 additions & 14 deletions Sources/CBORCoding/CBOR.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public enum CBOR {
Type value for encoding/decoding Undefined values as outlined in [RFC 8949
Section 5.7](https://datatracker.ietf.org/doc/html/rfc8949#section-5.7).
*/
public struct Undefined { }
public struct Undefined: Sendable { }

/**
CBOR supports encoding negative values normally outside of the range `Int64`.
Expand All @@ -35,7 +35,7 @@ public enum CBOR {
--------------Int64--------------
```
*/
public struct NegativeUInt64: RawRepresentable {
public struct NegativeUInt64: RawRepresentable, Sendable {

// MARK: Public Constants

Expand Down Expand Up @@ -70,7 +70,7 @@ public enum CBOR {
to any particular type/value. `SimpleValue` fills this gap by returning the
exact encoded value for those codes that are unassigned or unused.
*/
public struct SimpleValue: RawRepresentable {
public struct SimpleValue: RawRepresentable, Sendable {

// MARK: RawRepresentable Protocol Requirements

Expand All @@ -94,7 +94,7 @@ public enum CBOR {
Type value for encoding/decoding Big numbers as outlined in [RFC 8949 Section
3.4.3](https://datatracker.ietf.org/doc/html/rfc8949#section-3.4.3).
*/
public struct Bignum {
public struct Bignum: Sendable {

// MARK: Public Properties

Expand Down Expand Up @@ -250,7 +250,7 @@ public enum CBOR {
support for encoding byte data in this way. This may be useful for sending to
decoders that expect byte data lengths to be undefined.
*/
public struct IndefiniteLengthData {
public struct IndefiniteLengthData: Sendable {

// MARK: Public Properties

Expand Down Expand Up @@ -310,7 +310,7 @@ public enum CBOR {
provides support for encoding byte strings in this way. This may be useful for
sending to decoders that expect byte string lengths to be undefined.
*/
public struct IndefiniteLengthString {
public struct IndefiniteLengthString: Sendable {

// MARK: Public Properties

Expand Down Expand Up @@ -394,7 +394,7 @@ public enum CBOR {
A type that asserts its data is already in CBOR encoded format. No additional
encoding is done on the contained byte data.
*/
public struct CBOREncoded {
public struct CBOREncoded: Sendable {

// MARK: - Properties

Expand Down Expand Up @@ -424,15 +424,15 @@ extension CBOR {
// MARK: Internal Types

/// `Null` type for encoding
internal struct Null: Encodable { }
internal struct Null: Encodable, Sendable { }

/// `Break` code for ending indefinite length types. This is only used for
/// type-mismatch error messages
internal struct Break { }
internal struct Break: Sendable { }

/// A byte mask used for splitting the major type bits from the additional
/// information bits
internal enum ByteMask: UInt8 {
internal enum ByteMask: UInt8, Sendable {

// MARK: Cases

Expand All @@ -441,7 +441,7 @@ extension CBOR {
}

/// CBOR Major Type
internal enum MajorType: UInt8 {
internal enum MajorType: UInt8, Sendable {

// MARK: Cases

Expand All @@ -456,7 +456,7 @@ extension CBOR {
}

/// Major Type 7 defined bits
internal enum Bits: UInt8 {
internal enum Bits: UInt8, Sendable {

// MARK: Cases

Expand All @@ -474,7 +474,7 @@ extension CBOR {
Optional CBOR Tags described by [RFC 8949 Section
3.4](https://datatracker.ietf.org/doc/html/rfc8949#section-3.4).
*/
internal enum Tag: CustomStringConvertible {
internal enum Tag: CustomStringConvertible, Sendable {

// MARK: Cases

Expand Down Expand Up @@ -590,7 +590,7 @@ extension CBOR {
constructing the `codingPath` property of the `__CBOREncoder` and
`__CBORDecoder` instances
*/
internal struct CodingKey: Swift.CodingKey {
internal struct CodingKey: Swift.CodingKey, Sendable {

// MARK: Swift.CodingKey Protocol Requirements

Expand Down Expand Up @@ -696,3 +696,19 @@ extension DecodingError {
}
}
}

// MARK: - CBOR.DecimalFraction Extension

extension CBOR.DecimalFraction: Sendable where I1: Sendable, I2: Sendable { }

// MARK: - CBOR.Bigfloat Extension

extension CBOR.Bigfloat: Sendable where I1: Sendable, I2: Sendable { }

// MARK: - CBOR.IndefiniteLengthArray Extension

extension CBOR.IndefiniteLengthArray: Sendable where Element: Sendable { }

// MARK: - CBOR.IndefiniteLengthMap Extension

extension CBOR.IndefiniteLengthMap: Sendable where Key: Sendable, Value: Sendable { }
2 changes: 1 addition & 1 deletion Tests/CBORCodingTests/CBORTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ class CBORTests: XCTestCase {
func testDirectlyEncodeCBOREncoded() {
struct Test: Encodable {

static var value: Data = {
static let value: Data = {
try! CBOREncoder().encode("CBOR")
}()

Expand Down