Skip to content

Commit 764041f

Browse files
committed
Updated for Swift 4
1 parent 5249c16 commit 764041f

File tree

17 files changed

+1630
-1066
lines changed

17 files changed

+1630
-1066
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,6 @@ fastlane/report.xml
6565
fastlane/Preview.html
6666
fastlane/screenshots
6767
fastlane/test_output
68+
69+
# Xcode project
70+
TLVCoding.xcodeproj/*

Package.swift

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
// swift-tools-version:4.1
12
import PackageDescription
23

3-
let package = Package(
4-
name: "TLVCoding",
5-
targets: [
6-
Target(
7-
name: "TLVCoding")
8-
]
9-
)
4+
let package = Package(name: "TLVCoding",
5+
products: [
6+
.library(
7+
name: "TLVCoding",
8+
targets: ["TLVCoding"]
9+
)
10+
],
11+
targets: [
12+
.target(name: "TLVCoding", path: "./Sources"),
13+
.testTarget(name: "TLVCodingTests", dependencies: ["TLVCoding"])
14+
],
15+
swiftLanguageVersions: [4])

Sources/Decoder.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
import Foundation
1010

11-
public struct TLVDecoder {
11+
struct TLVDecoder {
1212

13-
public static func decode(data: Data, from types: [TLVDecodable.Type]) throws -> [TLVDecodable] {
13+
static func decode(data: Data, from types: [TLVDecodable.Type]) throws -> [TLVDecodable] {
1414

1515
var offset = 0
1616

@@ -51,14 +51,14 @@ public struct TLVDecoder {
5151

5252
// MARK: - Supporting Types
5353

54-
public extension TLVDecoder {
54+
extension TLVDecoder {
5555

56-
public struct DecodingContext {
56+
struct DecodingContext {
5757

58-
public let offset: Int
58+
let offset: Int
5959
}
6060

61-
public enum DecodingError: Swift.Error {
61+
enum DecodingError: Swift.Error {
6262

6363
case invalidSize(Int, context: DecodingContext)
6464
case invalidType(UInt8, context: DecodingContext)
@@ -70,9 +70,9 @@ public extension TLVDecoder {
7070

7171
// MARK: - Coder Convenience Extensions
7272

73-
public extension TLVDecoder {
73+
extension TLVDecoder {
7474

75-
public static func decode <Decodable: TLVDecodable> (data: Data, from type: Decodable.Type) throws -> Decodable {
75+
static func decode <Decodable: TLVDecodable> (data: Data, from type: Decodable.Type) throws -> Decodable {
7676

7777
let decodables = try decode(data: data, from: [type])
7878

@@ -83,7 +83,7 @@ public extension TLVDecoder {
8383
return decodable
8484
}
8585

86-
public static func decode <T1: TLVDecodable, T2: TLVDecodable>
86+
static func decode <T1: TLVDecodable, T2: TLVDecodable>
8787
(data: Data, from types: (T1.Type, T2.Type)) throws -> (T1, T2) {
8888

8989
let decodables = try decode(data: data, from: [types.0, types.1])
@@ -96,7 +96,7 @@ public extension TLVDecoder {
9696
return (decodable1, decodable2)
9797
}
9898

99-
public static func decode <T1: TLVDecodable, T2: TLVDecodable, T3: TLVDecodable>
99+
static func decode <T1: TLVDecodable, T2: TLVDecodable, T3: TLVDecodable>
100100
(data: Data, from types: (T1.Type, T2.Type, T3.Type)) throws -> (T1, T2, T3) {
101101

102102
let decodables = try decode(data: data, from: [types.0, types.1, types.2])
@@ -110,7 +110,7 @@ public extension TLVDecoder {
110110
return (decodable1, decodable2, decodable3)
111111
}
112112

113-
public static func decode <T1: TLVDecodable, T2: TLVDecodable, T3: TLVDecodable, T4: TLVDecodable>
113+
static func decode <T1: TLVDecodable, T2: TLVDecodable, T3: TLVDecodable, T4: TLVDecodable>
114114
(data: Data, from types: (T1.Type, T2.Type, T3.Type, T4.Type)) throws -> (T1, T2, T3, T4) {
115115

116116
let decodables = try decode(data: data, from: [types.0, types.1, types.2, types.3])
@@ -125,7 +125,7 @@ public extension TLVDecoder {
125125
return (decodable1, decodable2, decodable3, decodable4)
126126
}
127127

128-
public static func decode <T1: TLVDecodable, T2: TLVDecodable, T3: TLVDecodable, T4: TLVDecodable, T5: TLVDecodable>
128+
static func decode <T1: TLVDecodable, T2: TLVDecodable, T3: TLVDecodable, T4: TLVDecodable, T5: TLVDecodable>
129129
(data: Data, from types: (T1.Type, T2.Type, T3.Type, T4.Type, T5.Type)) throws -> (T1, T2, T3, T4, T5) {
130130

131131
let decodables = try decode(data: data, from: [types.0, types.1, types.2, types.3, types.4])
@@ -141,7 +141,7 @@ public extension TLVDecoder {
141141
return (decodable1, decodable2, decodable3, decodable4, decodable5)
142142
}
143143

144-
public static func decode <T1: TLVDecodable, T2: TLVDecodable, T3: TLVDecodable, T4: TLVDecodable, T5: TLVDecodable, T6: TLVDecodable>
144+
static func decode <T1: TLVDecodable, T2: TLVDecodable, T3: TLVDecodable, T4: TLVDecodable, T5: TLVDecodable, T6: TLVDecodable>
145145
(data: Data, from types: (T1.Type, T2.Type, T3.Type, T4.Type, T5.Type, T6.Type)) throws -> (T1, T2, T3, T4, T5, T6) {
146146

147147
let decodables = try decode(data: data, from: [types.0, types.1, types.2, types.3, types.4, types.5])
@@ -158,11 +158,11 @@ public extension TLVDecoder {
158158
return (decodable1, decodable2, decodable3, decodable4, decodable5, decodable6)
159159
}
160160

161-
public static func decodeOptional <T1: TLVDecodable, T2: TLVDecodable, T3: TLVDecodable, T4: TLVDecodable, T5: TLVDecodable, T6: TLVDecodable>
161+
static func decodeOptional <T1: TLVDecodable, T2: TLVDecodable, T3: TLVDecodable, T4: TLVDecodable, T5: TLVDecodable, T6: TLVDecodable>
162162
(data: Data, from types: (T1.Type, T2.Type, T3.Type, T4.Type, T5.Type, T6.Type)) throws -> (T1?, T2?, T3?, T4?, T5?, T6?) {
163163

164164
let decodables = try decode(data: data, from: [types.0, types.1, types.2, types.3, types.4, types.5])
165-
.sorted(by: { type(of: $0.0).typeCode.rawValue < type(of: $0.1).typeCode.rawValue })
165+
.sorted(by: { type(of: $0).typeCode.rawValue < type(of: $1).typeCode.rawValue })
166166

167167
return (decodables.count > 0 ? decodables[0] as? T1 : nil,
168168
decodables.count > 1 ? decodables[1] as? T2 : nil,

Sources/Encoder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public struct TLVEncoder {
1616

1717
for encodable in encodables {
1818

19-
let type = type(of: encodable).typeCode.rawValue
19+
let type = Swift.type(of: encodable).typeCode.rawValue
2020

2121
let valueData = encodable.valueData
2222

Sources/TLVCodable.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public protocol TLVTypeCode {
4040

4141
public extension TLVDecodable where Self: RawRepresentable, Self.RawValue: RawRepresentable, Self.RawValue.RawValue == UInt8 {
4242

43-
public init?(valueData: Foundation.Data) {
43+
init?(valueData: Foundation.Data) {
4444

4545
guard valueData.count == 1
4646
else { return nil }
@@ -56,7 +56,7 @@ public extension TLVDecodable where Self: RawRepresentable, Self.RawValue: RawRe
5656

5757
public extension TLVEncodable where Self: RawRepresentable, Self.RawValue: RawRepresentable, Self.RawValue.RawValue == UInt8 {
5858

59-
public var valueData: Foundation.Data {
59+
var valueData: Foundation.Data {
6060

6161
let byte = rawValue.rawValue
6262

@@ -66,7 +66,7 @@ public extension TLVEncodable where Self: RawRepresentable, Self.RawValue: RawRe
6666

6767
public extension TLVDecodable where Self: RawRepresentable, Self.RawValue == String {
6868

69-
public init?(valueData: Foundation.Data) {
69+
init?(valueData: Foundation.Data) {
7070

7171
guard let string = String(data: valueData, encoding: .utf8)
7272
else { return nil }
@@ -77,7 +77,7 @@ public extension TLVDecodable where Self: RawRepresentable, Self.RawValue == Str
7777

7878
public extension TLVEncodable where Self: RawRepresentable, Self.RawValue == String {
7979

80-
public var valueData: Foundation.Data {
80+
var valueData: Foundation.Data {
8181

8282
guard let data = self.rawValue.data(using: .utf8)
8383
else { fatalError("Could not encode string") }
@@ -90,7 +90,7 @@ public extension TLVEncodable where Self: RawRepresentable, Self.RawValue == Str
9090

9191
public extension TLVDecodable where Self: RawRepresentable, Self.RawValue: RawRepresentable, Self.RawValue.RawValue: UnsignedInteger {
9292

93-
public init?(valueData: Foundation.Data) {
93+
init?(valueData: Foundation.Data) {
9494

9595
typealias IntegerType = Self.RawValue.RawValue
9696

@@ -110,7 +110,7 @@ public extension TLVEncodable where Self: RawRepresentable, Self.RawValue == Str
110110

111111
public extension TLVEncodable where Self: RawRepresentable, Self.RawValue: RawRepresentable, Self.RawValue.RawValue: UnsignedInteger {
112112

113-
public var valueData: Foundation.Data {
113+
var valueData: Foundation.Data {
114114

115115
typealias IntegerType = Self.RawValue.RawValue
116116

@@ -124,7 +124,7 @@ public extension TLVEncodable where Self: RawRepresentable, Self.RawValue == Str
124124

125125
public extension TLVDecodable where Self: RawRepresentable, Self.RawValue: ExpressibleByStringLiteral {
126126

127-
public init?(valueData: Foundation.Data) {
127+
init?(valueData: Foundation.Data) {
128128

129129
typealias StringType = Self.RawValue
130130

@@ -139,7 +139,7 @@ public extension TLVEncodable where Self: RawRepresentable, Self.RawValue == Str
139139

140140
public extension TLVEncodable where Self: RawRepresentable, Self.RawValue: ExpressibleByStringLiteral {
141141

142-
public var valueData: Foundation.Data {
142+
var valueData: Foundation.Data {
143143

144144
assert(Self.RawValue.self == String.self, "Default implementation only for String")
145145

TLVCoding.podspec

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)