Skip to content

Commit 9119255

Browse files
Merge pull request #10 from SomeRandomiOSDev/LinuxSupport
Added support for Linux
2 parents 0382680 + 102742e commit 9119255

File tree

12 files changed

+225
-28
lines changed

12 files changed

+225
-28
lines changed

.github/workflows/swift.yml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,25 @@ on: [push, pull_request]
44

55
jobs:
66
build:
7-
8-
runs-on: macOS-latest
9-
7+
strategy:
8+
matrix:
9+
os: [macOS-latest, ubuntu-latest]
10+
swift: ["5.1"]
11+
runs-on: ${{ matrix.os }}
12+
env:
13+
SWIFT_VERSION: ${{ matrix.swift }}
14+
SWIFT_EXEC: .swiftenv/shims/swift
1015
steps:
1116
- uses: actions/checkout@v2
17+
- name: Install Swift
18+
run: |
19+
git clone https://github.com/kylef/swiftenv.git ~/.swiftenv
20+
~/.swiftenv/bin/swiftenv install $SWIFT_VERSION --skip-existing
21+
~/.swiftenv/bin/swiftenv rehash
1222
- name: Build
13-
run: swift build -v
14-
- name: Run Tests
15-
run: swift test -v
23+
run: |
24+
~/$SWIFT_EXEC --version
25+
~/$SWIFT_EXEC build -v
26+
- name: Test
27+
run: |
28+
~/$SWIFT_EXEC test -v

.swiftlint.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ opt_in_rules:
4444
- multiple_closures_with_trailing_closure
4545
- nesting
4646
- notification_center_detachment
47-
- number_separator
4847
- object_literal
4948
- operator_usage_whitespace
5049
- override_in_extension
@@ -60,8 +59,9 @@ opt_in_rules:
6059
- yoda_condition
6160

6261
excluded:
63-
- Pods
64-
- Carthage
62+
- .build
63+
- Tests/LinuxMain.swift
64+
- Tests/CBORCodingTests/XCTestManifests.swift
6565

6666
reporter: "xcode"
6767

.travis.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@ os: osx
22
language: swift
33
osx_image: xcode11.3
44
xcode_project: CBORCoding.xcodeproj
5-
addons:
6-
homebrew:
7-
packages:
8-
carthage
95

106
script:
11-
- carthage bootstrap
12-
137
- set -o pipefail && travis_retry xcodebuild -scheme "CBORCodingTests" -destination "platform=iOS Simulator,name=iPhone 11 Pro Max" -configuration Debug ONLY_ACTIVE_ARCH=YES -enableCodeCoverage YES test
148
- set -o pipefail && travis_retry xcodebuild -scheme "CBORCoding macOS Tests" -destination "platform=macOS" -configuration Debug ONLY_ACTIVE_ARCH=YES -enableCodeCoverage YES test
159
- set -o pipefail && travis_retry xcodebuild -scheme "CBORCoding tvOS Tests" -destination "platform=tvOS Simulator,name=Apple TV 4K" -configuration Debug ONLY_ACTIVE_ARCH=YES -enableCodeCoverage YES test

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ CBORCoding
55
[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/CBORCoding.svg)](https://cocoapods.org/pods/CBORCoding)
66
[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
77
[![Platform](https://img.shields.io/cocoapods/p/CBORCoding.svg)](https://cocoapods.org/pods/CBORCoding)
8+
![Linux](https://img.shields.io/badge/platform-linux-lightgrey)
89
[![Build](https://travis-ci.com/SomeRandomiOSDev/CBORCoding.svg?branch=master)](https://travis-ci.com/SomeRandomiOSDev/CBORCoding)
910
[![Code Coverage](https://codecov.io/gh/SomeRandomiOSDev/CBORCoding/branch/master/graph/badge.svg)](https://codecov.io/gh/SomeRandomiOSDev/CBORCoding)
1011
[![Codacy](https://api.codacy.com/project/badge/Grade/8ad52c117e4a46d9aa4699d22fc0bf49)](https://app.codacy.com/app/SomeRandomiOSDev/CBORCoding?utm_source=github.com&utm_medium=referral&utm_content=SomeRandomiOSDev/CBORCoding&utm_campaign=Badge_Grade_Dashboard)
12+
![Swift](https://github.com/SomeRandomiOSDev/CBORCoding/workflows/Swift/badge.svg)
1113

1214
**CBORCoding** is a lightweight framework containing a coder pair for encoding and decoding `Codable` conforming types to and from [CBOR](https://cbor.io) document format for iOS, macOS, tvOS, and watchOS.
1315

Sources/CBORCoding/CBOR+Equatable.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extension CBOR.Bignum: Equatable {
4343

4444
// MARK: - CBOR.DecimalFraction Extension
4545

46-
extension CBOR.DecimalFraction: Equatable where I1: Equatable, I2: Equatable {
46+
extension CBOR.DecimalFraction: Equatable {
4747

4848
public static func == (lhs: CBOR.DecimalFraction<I1, I2>, rhs: CBOR.DecimalFraction<I1, I2>) -> Bool {
4949
return lhs.exponent == rhs.exponent && lhs.mantissa == rhs.mantissa
@@ -52,7 +52,7 @@ extension CBOR.DecimalFraction: Equatable where I1: Equatable, I2: Equatable {
5252

5353
// MARK: - CBOR.Bigfloat Extension
5454

55-
extension CBOR.Bigfloat: Equatable where I1: Equatable, I2: Equatable {
55+
extension CBOR.Bigfloat: Equatable {
5656

5757
public static func == (lhs: CBOR.Bigfloat<I1, I2>, rhs: CBOR.Bigfloat<I1, I2>) -> Bool {
5858
return lhs.exponent == rhs.exponent && lhs.mantissa == rhs.mantissa

Sources/CBORCoding/CBORDecoder.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,8 @@ private struct __CBORKeyedDecodingContainer<K: CodingKey>: KeyedDecodingContaine
757757
throw DecodingError._typeMismatch(at: codingPath, expectation: [String: Any].self, reality: value)
758758
}
759759

760-
let container = __CBORKeyedDecodingContainer<NestedKey>(referencing: decoder, wrapping: dictionary)
761-
return KeyedDecodingContainer(container)
760+
let keyedContainer = __CBORKeyedDecodingContainer<NestedKey>(referencing: decoder, wrapping: dictionary)
761+
return KeyedDecodingContainer(keyedContainer)
762762
}
763763

764764
func nestedUnkeyedContainer(forKey key: Key) throws -> UnkeyedDecodingContainer {

Sources/CBORCoding/CBOREncoder.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -965,8 +965,8 @@ private struct __CBORKeyedEncodingContainer<K>: KeyedEncodingContainerProtocol w
965965
self.codingPath.append(key)
966966
defer { self.codingPath.removeLast() }
967967

968-
let container = __CBORKeyedEncodingContainer<NestedKey>(referencing: encoder, codingPath: codingPath, wrapping: dictionary)
969-
return KeyedEncodingContainer<NestedKey>(container)
968+
let keyedContainer = __CBORKeyedEncodingContainer<NestedKey>(referencing: encoder, codingPath: codingPath, wrapping: dictionary)
969+
return KeyedEncodingContainer<NestedKey>(keyedContainer)
970970
}
971971

972972
mutating func nestedUnkeyedContainer(forKey key: Key) -> UnkeyedEncodingContainer {
@@ -1046,8 +1046,8 @@ private struct __CBORUnkeyedEncodingContainer: UnkeyedEncodingContainer {
10461046
let dictionary = CodingKeyDictionary<Any>(indefiniteLength: encoder.newContainerLength.contains(.indefinite))
10471047
container.append(dictionary)
10481048

1049-
let container = __CBORKeyedEncodingContainer<NestedKey>(referencing: encoder, codingPath: codingPath, wrapping: dictionary)
1050-
return KeyedEncodingContainer<NestedKey>(container)
1049+
let keyedContainer = __CBORKeyedEncodingContainer<NestedKey>(referencing: encoder, codingPath: codingPath, wrapping: dictionary)
1050+
return KeyedEncodingContainer<NestedKey>(keyedContainer)
10511051
}
10521052

10531053
mutating func nestedUnkeyedContainer() -> UnkeyedEncodingContainer {
@@ -1117,7 +1117,7 @@ private class __CBORReferencingEncoder: __CBOREncoder {
11171117
}
11181118

11191119
switch reference {
1120-
case .array(var array, let index):
1120+
case let .array(array, index):
11211121
array.insert(value, at: index)
11221122

11231123
case let .dictionary(dictionary, key):

Sources/CBORCoding/CBORParser.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ internal class CBORParser {
10651065

10661066
let index = containers.count - 1
10671067

1068-
if var array = containers[index] as? (container: ArrayWrapper<Any>, length: UInt64?) {
1068+
if let array = containers[index] as? (container: ArrayWrapper<Any>, length: UInt64?) {
10691069
array.container.append(value)
10701070
containers[index].length -= 1
10711071
} else if let dictionary = containers[index] as? (container: CodingKeyDictionary<Any>, length: UInt64?) {
@@ -1207,7 +1207,7 @@ internal class CBORParser {
12071207

12081208
// MARK: - Optional Extension
12091209

1210-
extension Optional where Wrapped: AdditiveArithmetic {
1210+
extension Optional where Wrapped == UInt64 {
12111211

12121212
fileprivate static func -= (lhs: inout Wrapped?, rhs: Wrapped) {
12131213
if let value = lhs {

Sources/CBORCoding/Containers.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ internal class ArrayWrapper<Element>: MutableCollection, RandomAccessCollection,
7171
func replaceSubrange<C, R>(_ subrange: R, with newElements: __owned C) where C: Collection, R: RangeExpression, Element == C.Element, Index == R.Bound {
7272
array.replaceSubrange(subrange, with: newElements)
7373
}
74+
75+
func insert(_ newElement: __owned Element, at i: Int) {
76+
array.insert(newElement, at: i)
77+
}
78+
79+
func append(_ newElement: __owned Element) {
80+
array.append(newElement)
81+
}
7482
}
7583

7684
// MARK: - CodingKeyDictionary Definition
@@ -151,7 +159,6 @@ internal class CodingKeyDictionary<Value>: Sequence, ExpressibleByDictionaryLite
151159
// MARK: - ExpressibleByDictionaryLiteral Protocol Requirements
152160

153161
typealias Key = CodingKey
154-
typealias Value = Value
155162

156163
required init(dictionaryLiteral elements: (Key, Value)...) {
157164
self.keyValuePairs = elements

Tests/CBORCodingTests/CBOREncoderTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class CBOREncoderTests: XCTestCase {
3333
(try! encoder.encode(UInt64(1000)), "0x1903E8"),
3434
(try! encoder.encode(UInt64(1000000)), "0x1A000F4240"),
3535
(try! encoder.encode(UInt64(1000000000000)), "0x1B000000E8D4A51000"),
36-
(try! encoder.encode(UInt64(18446744073709551615)), "0x1BFFFFFFFFFFFFFFFF"),
36+
(try! encoder.encode(18446744073709551615 as UInt64), "0x1BFFFFFFFFFFFFFFFF"),
3737
(try! encoder.encode(CBOR.Bignum(isPositive: true,
3838
content: Data([UInt8(0x01), 0x00, 0x00, 0x00,
3939
0x00, 0x00, 0x00, 0x00, 0x00]))), "0xC249010000000000000000"), // 18446744073709551616

0 commit comments

Comments
 (0)