Skip to content

Commit

Permalink
Merge pull request #32 from luckfamousa/swift5.1
Browse files Browse the repository at this point in the history
Swift5.1
  • Loading branch information
wyland committed Jan 19, 2023
2 parents 55e1f83 + 823d06d commit e98814a
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 28 deletions.
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.2
13 changes: 12 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// swift-tools-version: 5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand All @@ -20,5 +23,13 @@
import PackageDescription

let package = Package(
name: "Thrift"
name: "Thrift",
products: [
.library(
name: "Thrift",
targets: ["Thrift"]),
],
targets: [
.target(name: "Thrift", path: "Sources")
]
)
6 changes: 3 additions & 3 deletions Sources/TMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public struct TMap<Key : TSerializable & Hashable, Value : TSerializable>: Colle
public typealias Storage = Dictionary<Key, Value>
public typealias Element = Storage.Element
public typealias Index = Storage.Index
public typealias IndexDistance = Storage.IndexDistance
public typealias IndexDistance = Int
public typealias Indices = Storage.Indices
public typealias SubSequence = Storage.SubSequence
internal var storage = Storage()
Expand All @@ -33,11 +33,11 @@ public struct TMap<Key : TSerializable & Hashable, Value : TSerializable>: Colle
}

public mutating func updateValue(_ value: Value, forKey key: Key) -> Value? {
return updateValue(value, forKey: key)
return storage.updateValue(value, forKey: key)
}

public mutating func removeAtIndex(_ index: DictionaryIndex<Key, Value>) -> (Key, Value) {
return removeAtIndex(index)
return storage.remove(at: index)
}

public mutating func removeValueForKey(_ key: Key) -> Value? {
Expand Down
8 changes: 4 additions & 4 deletions Sources/TSSLSocketTransport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@ public class TSSLSocketTransport: TStreamTransport {

CFReadStreamSetProperty(readStream?.takeRetainedValue(),
.SSLSettings,
settings as CFTypeRef!)
settings as CFTypeRef)

CFWriteStreamSetProperty(writeStream?.takeRetainedValue(),
.SSLSettings,
settings as CFTypeRef!)
settings as CFTypeRef)

inputStream = readStream!.takeRetainedValue()
inputStream?.schedule(in: .current, forMode: .defaultRunLoopMode)
inputStream?.schedule(in: .current, forMode: RunLoop.Mode.default)
inputStream?.open()

outputStream = writeStream!.takeRetainedValue()
outputStream?.schedule(in: .current, forMode: .defaultRunLoopMode)
outputStream?.schedule(in: .current, forMode: RunLoop.Mode.default)
outputStream?.open()

readStream?.release()
Expand Down
34 changes: 19 additions & 15 deletions Sources/TSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

import Foundation

public struct TSet<Element : TSerializable & Hashable> : SetAlgebra, Hashable, Collection, ExpressibleByArrayLiteral, TSerializable {
public struct TSet<Element : TSerializable & Hashable> : Collection, Hashable, SetAlgebra, ExpressibleByArrayLiteral, TSerializable {

/// Typealias for Storage type
public typealias Storage = Set<Element>


/// Internal Storage used for TSet (Set\<Element\>)
internal var storage : Storage

Expand All @@ -32,15 +32,15 @@ public struct TSet<Element : TSerializable & Hashable> : SetAlgebra, Hashable, C

public typealias Indices = Storage.Indices
public typealias Index = Storage.Index
public typealias IndexDistance = Storage.IndexDistance
public typealias IndexDistance = Int
public typealias SubSequence = Storage.SubSequence


public var indices: Indices { return storage.indices }

// Must implement isEmpty even though both SetAlgebra and Collection provide it due to their conflciting default implementations
public var isEmpty: Bool { return storage.isEmpty }

public func distance(from start: Index, to end: Index) -> IndexDistance {
return storage.distance(from: start, to: end)
}
Expand All @@ -67,7 +67,7 @@ public struct TSet<Element : TSerializable & Hashable> : SetAlgebra, Hashable, C
internal init(storage: Set<Element>) {
self.storage = storage
}

public func contains(_ member: Element) -> Bool {
return storage.contains(member)
}
Expand All @@ -80,28 +80,28 @@ public struct TSet<Element : TSerializable & Hashable> : SetAlgebra, Hashable, C
return storage.remove(member)
}

public func union(_ other: TSet<Element>) -> TSet {
return TSet(storage: storage.union(other.storage))
public func union(_ other: __owned TSet<Element>) -> TSet<Element> {
return TSet<Element>(storage: storage.union(other.storage))
}

public mutating func formIntersection(_ other: TSet<Element>) {
return storage.formIntersection(other.storage)
}

public mutating func formSymmetricDifference(_ other: TSet<Element>) {
public mutating func formSymmetricDifference(_ other: __owned TSet<Element>) {
return storage.formSymmetricDifference(other.storage)
}

public mutating func formUnion(_ other: TSet<Element>) {
public mutating func formUnion(_ other: __owned TSet<Element>) {
return storage.formUnion(other.storage)
}

public func intersection(_ other: TSet<Element>) -> TSet {
return TSet(storage: storage.intersection(other.storage))
public func intersection(_ other: TSet<Element>) -> TSet<Element> {
return TSet<Element>(storage: storage.intersection(other.storage))
}

public func symmetricDifference(_ other: TSet<Element>) -> TSet {
return TSet(storage: storage.symmetricDifference(other.storage))
public func symmetricDifference(_ other: __owned TSet<Element>) -> TSet<Element> {
return TSet<Element>(storage: storage.symmetricDifference(other.storage))
}

public mutating func update(with newMember: Element) -> Element? {
Expand Down Expand Up @@ -135,6 +135,10 @@ public struct TSet<Element : TSerializable & Hashable> : SetAlgebra, Hashable, C
return result
}

public func hash(into hasher: inout Hasher) {
hasher.combine(hashValue)
}

/// Mark: TSerializable
public static var thriftType : TType { return .set }

Expand All @@ -150,13 +154,13 @@ public struct TSet<Element : TSerializable & Hashable> : SetAlgebra, Hashable, C
storage = Storage(sequence)
}

public static func read(from proto: TProtocol) throws -> TSet {
public static func read(from proto: TProtocol) throws -> TSet<Element> {
let (elementType, size) = try proto.readSetBegin()
if elementType != Element.thriftType {
throw TProtocolError(error: .invalidData,
extendedError: .unexpectedType(type: elementType))
}
var set = TSet()
var set = TSet<Element>()
for _ in 0..<size {
let element = try Element.read(from: proto)
set.storage.insert(element)
Expand Down
6 changes: 3 additions & 3 deletions Sources/TSocketTransport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class TCFSocketTransport: TStreamTransport {
var readStream: Unmanaged<CFReadStream>?
var writeStream: Unmanaged<CFWriteStream>?
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault,
hostname as CFString!,
hostname as CFString,
UInt32(port),
&readStream,
&writeStream)
Expand All @@ -88,11 +88,11 @@ public class TCFSocketTransport: TStreamTransport {
}

inputStream = readStream as InputStream
inputStream.schedule(in: .current, forMode: .defaultRunLoopMode)
inputStream.schedule(in: .current, forMode: RunLoop.Mode.default)
inputStream.open()

outputStream = writeStream as OutputStream
outputStream.schedule(in: .current, forMode: .defaultRunLoopMode)
outputStream.schedule(in: .current, forMode: RunLoop.Mode.default)
outputStream.open()

} else {
Expand Down
4 changes: 2 additions & 2 deletions Sources/TStreamTransport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ import CoreFoundation

input?.delegate = nil
input?.close()
input?.remove(from: .current, forMode: .defaultRunLoopMode)
input?.remove(from: .current, forMode: RunLoop.Mode.default)
input = nil
}

Expand All @@ -135,7 +135,7 @@ import CoreFoundation
}
output?.delegate = nil
output?.close()
output?.remove(from: .current, forMode: .defaultRunLoopMode)
output?.remove(from: .current, forMode: RunLoop.Mode.default)
output = nil
}
}
Expand Down

0 comments on commit e98814a

Please sign in to comment.