[GitHub] thrift issue #1084: THRIFT-3773 Swift 3 Native Library
Github user fumoboy007 commented on the issue: https://github.com/apache/thrift/pull/1084 Yeah, itâs implemented in Swift 4. ![img_1999](https://user-images.githubusercontent.com/2100868/26892962-c6356fa6-4b6e-11e7-8394-1964d6ee.PNG) --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] thrift issue #1084: THRIFT-3773 Swift 3 Native Library
Github user fumoboy007 commented on the issue: https://github.com/apache/thrift/pull/1084 > SE-0162 [ https://github.com/apple/swift-evolution/blob/master/proposals/0162-package-manager-custom-target-layouts.md ] added API for controlling where the source files for each target should be found. This allows SwiftPM to support source trees that don't conform to the standard package layout conventions. Can we take advantage of this so that people can use the library from the official repo? --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] thrift issue #1084: THRIFT-3773 Swift 3 Native Library
Github user fumoboy007 commented on the issue: https://github.com/apache/thrift/pull/1084 Woah, nice! --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] thrift issue #1084: THRIFT-3773 Swift 3 Native Library
Github user fumoboy007 commented on the issue: https://github.com/apache/thrift/pull/1084 I donât see a `[MyService]ProcessorAsync` in the generated code. How do I handle requests in an asynchronous manner? --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] thrift issue #1084: THRIFT-3773 Swift 3 Native Library
Github user fumoboy007 commented on the issue: https://github.com/apache/thrift/pull/1084 Oh I didnât know about the `async_clients` option⦠thanks! ð¬ --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] thrift issue #1084: THRIFT-3773 Swift 3 Native Library
Github user fumoboy007 commented on the issue: https://github.com/apache/thrift/pull/1084 One major issue I encountered is the async support. There doesnât seem to be an asynchronous `TProcessor`/`TProtocol`/`TClient` API in the base/generated code. Async support is important for high-efficiency server applications. (At least until [SR-2905](https://bugs.swift.org/browse/SR-2905) is implemented for Linux.) I can explain this in more detail if desired. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] thrift issue #1084: THRIFT-3773 Swift 3 Native Library
Github user fumoboy007 commented on the issue: https://github.com/apache/thrift/pull/1084 ``` Compile Swift Module 'Thrift' (37 sources) /Users/â¦/Packages/Thrift-1.0.0/Sources/TSet.swift:22:70: warning: 'IndexableBase' is deprecated: it will be removed in Swift 4.0. Please use 'Collection' instead public struct TSet : Collection, IndexableBase, ExpressibleByArrayLiteral, Hashable, TSerializable { ^ ``` --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] thrift pull request #1084: THRIFT-3773 Swift 3 Native Library
Github user fumoboy007 commented on a diff in the pull request: https://github.com/apache/thrift/pull/1084#discussion_r78313579 --- Diff: lib/swift/Sources/LinuxHelper.swift --- @@ -0,0 +1,42 @@ +// +// LinuxHelper.swift +// Thrift +// +// Created by Christopher Simpson on 8/22/16. +// +// + +import Foundation +import CoreFoundation + +#if os(Linux) +/// Extensions for Linux for incomplete Foundation API's. +/// swift-corelibs-foundation is not yet 1:1 with OSX/iOS Foundation + +extension URLSession { + // Current one uses NSURLRequest which doesn't currently bridge + @discardableResult + open func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask { --- End diff -- Iâm not too sure how the tagging/branching works in the Swift repo, but I see that the [commit](https://github.com/apple/swift-corelibs-foundation/commit/cffa65a1f933ddb29b7d3d21cd1756caeddc238f) is in `swift-3.0-branch` (as well as `master`) and is included in the `swift-3.0-GM-CANDIDATE` tag. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] thrift pull request #1084: THRIFT-3773 Swift 3 Native Library
Github user fumoboy007 commented on a diff in the pull request: https://github.com/apache/thrift/pull/1084#discussion_r78312854 --- Diff: lib/swift/Sources/LinuxHelper.swift --- @@ -0,0 +1,42 @@ +// +// LinuxHelper.swift +// Thrift +// +// Created by Christopher Simpson on 8/22/16. +// +// + +import Foundation +import CoreFoundation + +#if os(Linux) +/// Extensions for Linux for incomplete Foundation API's. +/// swift-corelibs-foundation is not yet 1:1 with OSX/iOS Foundation + +extension URLSession { + // Current one uses NSURLRequest which doesn't currently bridge + @discardableResult + open func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask { --- End diff -- Not necessary anymore I think: https://github.com/apple/swift-corelibs-foundation/blob/master/Foundation/NSURLSession/NSURLSession.swift#L423 --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] thrift pull request #1084: THRIFT-3773 Swift 3 Native Library
Github user fumoboy007 commented on a diff in the pull request: https://github.com/apache/thrift/pull/1084#discussion_r78312577 --- Diff: lib/swift/Sources/TStruct.swift --- @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + +/// Protocol for Generated Structs to conform to +/// Dictionary maps field names to internal IDs and uses Reflection +/// to iterate through all fields. +/// `writeFieldValue(_:name:type:id:)` calls `TSerializable.write(to:)` internally +/// giving a nice recursive behavior for nested TStructs, TLists, TMaps, and TSets +public protocol TStruct : TSerializable { + static var fieldIds: [String: Int32] { get } + static var structName: String { get } +} + +public extension TStruct { + public static var fieldIds: [String: (id: Int32, type: TType)] { return [:] } + public static var thriftType: TType { return .struct } + + public func write(to proto: TProtocol) throws { +// Write struct name first +try proto.writeStructBegin(name: Self.structName) + +try self.forEach { name, value, id in + // Write to protocol + try proto.writeFieldValue(value, name: name, +type: value.thriftType, id: id) +} +try proto.writeFieldStop() +try proto.writeStructEnd() + } + + public var hashValue: Int { +let prime = 31 +var result = 1 +self.forEach { _, value, _ in + result = prime * result + (value.hashValue) --- End diff -- `&*`, `&+`? --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] thrift pull request #1084: THRIFT-3773 Swift 3 Native Library
Github user fumoboy007 commented on a diff in the pull request: https://github.com/apache/thrift/pull/1084#discussion_r78312532 --- Diff: lib/swift/Sources/TSet.swift --- @@ -0,0 +1,175 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import Foundation + +public struct TSet : SetAlgebra, Hashable, Collection, ExpressibleByArrayLiteral, TSerializable { + /// Typealias for Storage type + typealias Storage = Set + + + /// Internal Storage used for TSet (Set\<Element\>) + internal var storage : Storage + + + /// Mark: Collection + + public typealias Indices = Storage.Indices + public typealias Index = Storage.Index + public typealias IndexDistance = Storage.IndexDistance + 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) + } + + public func index(_ i: Index, offsetBy n: IndexDistance) -> Index { +return storage.index(i, offsetBy: n) + } + + public func index(_ i: Index, offsetBy n: IndexDistance, limitedBy limit: Index) -> Index? { +return storage.index(i, offsetBy: n, limitedBy: limit) + } + + public subscript (position: Storage.Index) -> Element? { +return storage[position] + } + + /// Mark: SetAlgebra + internal init(storage: Set) { +self.storage = storage + } + + public func contains(_ member: Element) -> Bool { +return storage.contains(member) + } + + public mutating func insert(_ newMember: Element) -> (inserted: Bool, memberAfterInsert: Element) { +return storage.insert(newMember) + } + + public mutating func remove(_ member: Element) -> Element? { +return storage.remove(member) + } + + public func union(_ other: TSet) -> TSet { +return TSet(storage: storage.union(other.storage)) + } + + public mutating func formIntersection(_ other: TSet) { +return storage.formIntersection(other.storage) + } + + public mutating func formSymmetricDifference(_ other: TSet) { +return storage.formSymmetricDifference(other.storage) + } + + public mutating func formUnion(_ other: TSet) { +return storage.formUnion(other.storage) + } + + public func intersection(_ other: TSet) -> TSet { +return TSet(storage: storage.intersection(other.storage)) + } + + public func symmetricDifference(_ other: TSet) -> TSet { +return TSet(storage: storage.symmetricDifference(other.storage)) + } + + public mutating func update(with newMember: Element) -> Element? { +return storage.update(with: newMember) + } + + /// Mark: IndexableBase + + public var startIndex: Index { return storage.startIndex } + public var endIndex: Index { return storage.endIndex } + public func index(after i: Index) -> Index { +return storage.index(after: i) + } + + public func formIndex(after i: inout Storage.Index) { +storage.formIndex(after: ) + } + + public subscript(bounds: Range) -> SubSequence { +return storage[bounds] + } + + + /// Mark: Hashable + public var hashValue : Int { +let prime = 31 +var result = 1 +for element in storage { + result = prime * result + element.hashValue --- End diff -- `&*`, `&+`? --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your pr
[GitHub] thrift pull request #1084: THRIFT-3773 Swift 3 Native Library
Github user fumoboy007 commented on a diff in the pull request: https://github.com/apache/thrift/pull/1084#discussion_r78312512 --- Diff: lib/swift/Sources/TMap.swift --- @@ -0,0 +1,182 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +public struct TMap: Collection, ExpressibleByDictionaryLiteral, Hashable, TSerializable { + typealias Storage = Dictionary<Key, Value> + public typealias Element = Storage.Element + public typealias Index = Storage.Index + public typealias IndexDistance = Storage.IndexDistance + public typealias Indices = Storage.Indices + public typealias SubSequence = Storage.SubSequence + internal var storage = Storage() + + /// Mark: Be Like Dictionary + + public func indexForKey(_ key: Key) -> Index? { +return storage.index(forKey: key) + } + + public mutating func updateValue(_ value: Value, forKey key: Key) -> Value? { +return updateValue(value, forKey: key) + } + + public mutating func removeAtIndex(_ index: DictionaryIndex<Key, Value>) -> (Key, Value) { +return removeAtIndex(index) + } + + public mutating func removeValueForKey(_ key: Key) -> Value? { +return storage.removeValue(forKey: key) + } + + public init(minimumCapacity: Int) { +storage = Storage(minimumCapacity: minimumCapacity) + } + + public subscript (key: Key) -> Value? { +get { + return storage[key] +} +set { + storage[key] = newValue +} + } + + /// Mark: Collection + + public var indices: Indices { +return storage.indices + } + + public func distance(from start: Index, to end: Index) -> IndexDistance { +return storage.distance(from: start, to: end) + } + + public func index(_ i: Index, offsetBy n: IndexDistance) -> Index { +return storage.index(i, offsetBy: n) + } + + public func index(_ i: Index, offsetBy n: IndexDistance, limitedBy limit: Index) -> Index? { +return storage.index(i, offsetBy: n, limitedBy: limit) + } + + public subscript(position: Index) -> Element { +return storage[position] + } + + /// Mark: IndexableBase + + public var startIndex: Index { return storage.startIndex } + public var endIndex: Index { return storage.endIndex } + public func index(after i: Index) -> Index { +return storage.index(after: i) + } + + public func formIndex(after i: inout Index) { +storage.formIndex(after: ) + } + + public subscript(bounds: Range) -> SubSequence { +return storage[bounds] + } + + /// Mark: DictionaryLiteralConvertible + + public init(dictionaryLiteral elements: (Key, Value)...) { +storage = Storage() +for (key, value) in elements { + storage[key] = value +} + } + + /// Mark: Hashable + + public var hashValue: Int { +let prime = 31 +var result = 1 +for (key, value) in storage { + result = prime * result + key.hashValue --- End diff -- `&*`, `&+`? --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] thrift pull request #1084: THRIFT-3773 Swift 3 Native Library
Github user fumoboy007 commented on a diff in the pull request: https://github.com/apache/thrift/pull/1084#discussion_r78312455 --- Diff: lib/swift/Sources/TApplicationError.swift --- @@ -0,0 +1,157 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + + +public struct TApplicationError : TError { + public enum Code : TErrorCode { +case unknown +case unknownMethod(methodName: String?) +case invalidMessageType +case wrongMethodName(methodName: String?) +case badSequenceId +case missingResult(methodName: String?) +case internalError +case protocolError +case invalidTransform +case invalidProtocol +case unsupportedClientType + + +/// Initialize a TApplicationError with a Thrift error code +/// Normally this would be achieved with RawRepresentable however +/// by doing this we can allow for associated properties on enum cases for +/// case specific context data in a Swifty, type-safe manner. +/// +/// - parameter thriftErrorCode: Integer TApplicationError(exception) error code. +/// Default to 0 (.unknown) +public init(thriftErrorCode: Int) { + switch thriftErrorCode { + case 1: self = .unknownMethod(methodName: nil) + case 2: self = .invalidMessageType + case 3: self = .wrongMethodName(methodName: nil) + case 4: self = .badSequenceId + case 5: self = .missingResult(methodName: nil) + case 6: self = .internalError + case 7: self = .protocolError + case 8: self = .invalidProtocol + case 9: self = .invalidTransform + case 10: self = .unsupportedClientType + default: self = .unknown + } +} +public var thriftErrorCode: Int { + switch self { + case .unknown:return 0 + case .unknownMethod: return 1 + case .invalidMessageType: return 2 + case .wrongMethodName:return 3 + case .badSequenceId: return 4 + case .missingResult: return 5 + case .internalError: return 6 + case .protocolError: return 7 + case .invalidProtocol:return 8 + case .invalidTransform: return 9 + case .unsupportedClientType: return 10 + } +} + +public var description: String { + /// Output "for #methodName" if method is not nil else empty + let methodUnwrap: (String?) -> String = { method in +return "\(method == nil ? "" : " for \(method ?? "")")" + } + switch self { + case .unknown: return "Unknown TApplicationError" + case .unknownMethod(let method):return "Unknown Method\(methodUnwrap(method))" + case .invalidMessageType: return "Invalid Message Type" + case .wrongMethodName(let method): return "Wrong Method Name\(methodUnwrap(method))" + case .badSequenceId:return "Bad Sequence ID" + case .missingResult(let method):return "Missing Result\(methodUnwrap(method))" + case .internalError:return "Internal Error" + case .protocolError:return "Protocol Error" + case .invalidProtocol: return "Invalid Protocol" + case .invalidTransform: return "Invalid Transform" + case .unsupportedClientType:return "Unsupported Client Type" + } +} + } + + public init() { } + + public init(thriftErrorCode code: Int, message: String?=nil) { +self.error = Code(thriftErrorCode: code) +self.message = message + } + + public var error: Code = .unknow
[GitHub] thrift pull request #1084: THRIFT-3773 Swift 3 Native Library
Github user fumoboy007 commented on a diff in the pull request: https://github.com/apache/thrift/pull/1084#discussion_r78312489 --- Diff: lib/swift/Sources/TList.swift --- @@ -0,0 +1,135 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +public struct TList : RandomAccessCollection, MutableCollection, ExpressibleByArrayLiteral, TSerializable, Hashable { + typealias Storage = Array + public typealias Indices = Storage.Indices + + internal var storage = Storage() + public init() { } + public init(arrayLiteral elements: Element...) { +self.storage = Storage(storage) + } + + /// Mark: Hashable + public var hashValue : Int { +let prime = 31 +var result = 1 +for element in storage { + result = prime * result + element.hashValue --- End diff -- `&*`, `&+`? --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---