This is an automated email from the ASF dual-hosted git repository.

jking pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git


The following commit(s) were added to refs/heads/master by this push:
     new 2566ecd  Update Swift Library and tests
2566ecd is described below

commit 2566ecd5d9999f7ff70e6ac702243f0dfb24e7aa
Author: Chris Simpson <apocoli...@gmail.com>
AuthorDate: Wed Aug 29 14:40:44 2018 -0400

    Update Swift Library and tests
---
 lib/swift/README.md                                |  5 +-
 lib/swift/Sources/TBinaryProtocol.swift            |  6 +-
 lib/swift/Sources/TClient.swift                    |  4 +-
 lib/swift/Sources/TCompactProtocol.swift           |  8 +--
 lib/swift/Sources/TList.swift                      |  2 +-
 lib/swift/Sources/TMap.swift                       |  2 +-
 lib/swift/Sources/TSet.swift                       |  2 +-
 lib/swift/Sources/TSocketTransport.swift           |  4 +-
 lib/swift/Sources/Thrift.swift                     |  2 +-
 .../Tests/ThriftTests/TBinaryProtocolTests.swift   | 22 +++++++
 .../Tests/ThriftTests/TCompactProtocolTests.swift  | 68 +++++++++++++++++++++-
 lib/swift/Tests/ThriftTests/ThriftTests.swift      |  8 +--
 12 files changed, 112 insertions(+), 21 deletions(-)

diff --git a/lib/swift/README.md b/lib/swift/README.md
index 50f522d..2ad88d6 100644
--- a/lib/swift/README.md
+++ b/lib/swift/README.md
@@ -20,6 +20,8 @@ KIND, either express or implied. See the License for the
 specific language governing permissions and limitations
 under the License.
 
+Brought to you by [FiscalNote, Inc](http://www.fiscalnote.com/)
+
 
 ## Build
 
@@ -88,10 +90,11 @@ func write(_ val: String) throws
 #### Generator Flags
 | Flag          | Description           |
 | ------------- |:-------------:|
-| async_clients | Generate clients which invoke asynchronously via block 
syntax.Asynchronous classes are appended with `_Async` |
+| async_clients | Generate clients which invoke asynchronously via block 
syntax. Asynchronous classes are appended with `_Async` |
 | no_strict*    | Generates non-strict structs      |
 | debug_descriptions | Allow use of debugDescription so the app can add 
description via a cateogory/extension      |
 | log_unexpected | Log every time an unexpected field ID or type is 
encountered. |
+| safe_enums     | Generate enum types with an unknown case to handle 
unspecified values rather than throw a serialization error  |
 
 
 
diff --git a/lib/swift/Sources/TBinaryProtocol.swift 
b/lib/swift/Sources/TBinaryProtocol.swift
index 47f3f28..a97249a 100644
--- a/lib/swift/Sources/TBinaryProtocol.swift
+++ b/lib/swift/Sources/TBinaryProtocol.swift
@@ -79,7 +79,7 @@ public class TBinaryProtocol: TProtocol {
       messageName = try read()
     } else {
       if strictRead {
-        let errorMessage = "Missing message version, old client? Message Name: 
\(currentMessageName)"
+        let errorMessage = "Missing message version, old client? Message Name: 
\(currentMessageName ?? "")"
         throw TProtocolError(error: .invalidData,
                              message: errorMessage)
       }
@@ -233,7 +233,7 @@ public class TBinaryProtocol: TProtocol {
   
   public func read() throws -> Double {
     let val = try read() as Int64
-    return unsafeBitCast(val, to: Double.self)
+    return Double(bitPattern: UInt64(bitPattern: val))
   }
   
   public func read() throws -> Data {
@@ -371,7 +371,7 @@ public class TBinaryProtocol: TProtocol {
   
   public func write(_ value: Double) throws {
     // Notably unsafe, since Double and Int64 are the same size, this should 
work fine
-    try self.write(unsafeBitCast(value, to: Int64.self))
+    try self.write(Int64(bitPattern: value.bitPattern))
   }
   
   public func write(_ data: Data) throws {
diff --git a/lib/swift/Sources/TClient.swift b/lib/swift/Sources/TClient.swift
index c404c9a..cc3288a 100644
--- a/lib/swift/Sources/TClient.swift
+++ b/lib/swift/Sources/TClient.swift
@@ -22,12 +22,12 @@ open class TClient {
   public let inProtocol: TProtocol
   public let outProtocol: TProtocol
 
-  public init(inoutProtocol: TProtocol) {
+  required public init(inoutProtocol: TProtocol) {
     self.inProtocol = inoutProtocol
     self.outProtocol = inoutProtocol
   }
 
-  public init(inProtocol: TProtocol, outProtocol: TProtocol) {
+  required public init(inProtocol: TProtocol, outProtocol: TProtocol) {
     self.inProtocol = inProtocol
     self.outProtocol = outProtocol
   }
diff --git a/lib/swift/Sources/TCompactProtocol.swift 
b/lib/swift/Sources/TCompactProtocol.swift
index ac5b35a..59773c3 100644
--- a/lib/swift/Sources/TCompactProtocol.swift
+++ b/lib/swift/Sources/TCompactProtocol.swift
@@ -222,11 +222,11 @@ public class TCompactProtocol: TProtocol {
   ///
   /// - returns: zigzaged UInt32
   func i32ToZigZag(_ n : Int32) -> UInt32 {
-    return UInt32(n << 1) ^ UInt32(n >> 31)
+    return UInt32(bitPattern: Int32(n << 1) ^ Int32(n >> 31))
   }
 
   func i64ToZigZag(_ n : Int64) -> UInt64 {
-    return UInt64(n << 1) ^ UInt64(n >> 63)
+    return UInt64(bitPattern: Int64(n << 1) ^ Int64(n >> 63))
   }
 
   func zigZagToi32(_ n: UInt32) -> Int32 {
@@ -379,7 +379,7 @@ public class TCompactProtocol: TProtocol {
       return UnsafePointer<UInt64>(OpaquePointer(ptr)).pointee
     }
     let bits = CFSwapInt64LittleToHost(i64)
-    return unsafeBitCast(bits, to: Double.self)
+    return Double(bitPattern: bits)
   }
   
   public func read() throws -> Data {
@@ -557,7 +557,7 @@ public class TCompactProtocol: TProtocol {
   }
   
   public func write(_ value: Double) throws {
-    var bits = CFSwapInt64HostToLittle(unsafeBitCast(value, to: UInt64.self))
+    var bits = CFSwapInt64HostToLittle(value.bitPattern)
     let data = withUnsafePointer(to: &bits) {
       return Data(bytes: UnsafePointer<UInt8>(OpaquePointer($0)), count: 
MemoryLayout<UInt64>.size)
     }
diff --git a/lib/swift/Sources/TList.swift b/lib/swift/Sources/TList.swift
index 0077156..c239d10 100644
--- a/lib/swift/Sources/TList.swift
+++ b/lib/swift/Sources/TList.swift
@@ -18,7 +18,7 @@
  */
 
 public struct TList<Element : TSerializable> : RandomAccessCollection, 
MutableCollection, ExpressibleByArrayLiteral, TSerializable, Hashable {
-  typealias Storage = Array<Element>
+  public typealias Storage = Array<Element>
   public typealias Indices = Storage.Indices
 
   internal var storage = Storage()
diff --git a/lib/swift/Sources/TMap.swift b/lib/swift/Sources/TMap.swift
index f8b02d2..8980377 100644
--- a/lib/swift/Sources/TMap.swift
+++ b/lib/swift/Sources/TMap.swift
@@ -18,7 +18,7 @@
  */
 
 public struct TMap<Key : TSerializable & Hashable, Value : TSerializable>: 
Collection, ExpressibleByDictionaryLiteral, Hashable, TSerializable {
-  typealias Storage = Dictionary<Key, Value>
+  public typealias Storage = Dictionary<Key, Value>
   public typealias Element = Storage.Element
   public typealias Index = Storage.Index
   public typealias IndexDistance = Storage.IndexDistance
diff --git a/lib/swift/Sources/TSet.swift b/lib/swift/Sources/TSet.swift
index 3e014c1..1ecd170 100644
--- a/lib/swift/Sources/TSet.swift
+++ b/lib/swift/Sources/TSet.swift
@@ -21,7 +21,7 @@ import Foundation
 
 public struct TSet<Element : TSerializable & Hashable> : SetAlgebra, Hashable, 
Collection, ExpressibleByArrayLiteral, TSerializable {
   /// Typealias for Storage type
-  typealias Storage = Set<Element>
+  public typealias Storage = Set<Element>
   
   
   /// Internal Storage used for TSet (Set\<Element\>)
diff --git a/lib/swift/Sources/TSocketTransport.swift 
b/lib/swift/Sources/TSocketTransport.swift
index 891bd27..0316e37 100644
--- a/lib/swift/Sources/TSocketTransport.swift
+++ b/lib/swift/Sources/TSocketTransport.swift
@@ -83,8 +83,8 @@ public class TCFSocketTransport: TStreamTransport {
         CFWriteStreamSetProperty(writeStream, .shouldCloseNativeSocket, 
kCFBooleanTrue)
       
         if secure {
-            CFReadStreamSetProperty(readStream, .socketSecurityLevel, 
StreamSocketSecurityLevel.negotiatedSSL._rawValue)
-            CFWriteStreamSetProperty(writeStream, .socketSecurityLevel, 
StreamSocketSecurityLevel.negotiatedSSL._rawValue)
+            CFReadStreamSetProperty(readStream, .socketSecurityLevel, 
StreamSocketSecurityLevel.negotiatedSSL.rawValue as CFString)
+            CFWriteStreamSetProperty(writeStream, .socketSecurityLevel, 
StreamSocketSecurityLevel.negotiatedSSL.rawValue as CFString)
         }
 
       inputStream = readStream as InputStream
diff --git a/lib/swift/Sources/Thrift.swift b/lib/swift/Sources/Thrift.swift
index afa3096..5bd1758 100644
--- a/lib/swift/Sources/Thrift.swift
+++ b/lib/swift/Sources/Thrift.swift
@@ -1,3 +1,3 @@
 class Thrift {
-       let version = "0.0.1"
+       let version = "1.1.0"
 }
diff --git a/lib/swift/Tests/ThriftTests/TBinaryProtocolTests.swift 
b/lib/swift/Tests/ThriftTests/TBinaryProtocolTests.swift
index f0e48b9..56a5572 100644
--- a/lib/swift/Tests/ThriftTests/TBinaryProtocolTests.swift
+++ b/lib/swift/Tests/ThriftTests/TBinaryProtocolTests.swift
@@ -129,6 +129,28 @@ class TBinaryProtocolTests: XCTestCase {
       XCTAssertFalse(true, "Caught Error attempting to read \(error)")
     }
   }
+  func testUnsafeBitcastUpdate() {
+    let value: Double = 3.14159
+    let val: Int64 = 31415926
+    let uval: UInt64 = 31415926
+    
+    let i64 = Int64(bitPattern: value.bitPattern)
+    let ubc = unsafeBitCast(value, to: Int64.self)
+    
+    XCTAssertEqual(i64, ubc, "Bitcast Double-> i64 Values don't match")
+    
+    let dbl = Double(bitPattern: UInt64(val))
+    let ubdb = unsafeBitCast(val, to: Double.self)
+    
+    XCTAssertEqual(dbl, ubdb, "Bitcast i64 -> Double Values don't match")
+    
+    let db2 = Double(bitPattern: uval)
+    let usbc2 = unsafeBitCast(uval, to: Double.self)
+    
+    XCTAssertEqual(db2, usbc2, "Bitcast u64 -> Double Values don't match")
+
+    
+  }
   
   static var allTests : [(String, (TBinaryProtocolTests) -> () throws -> 
Void)] {
     return [
diff --git a/lib/swift/Tests/ThriftTests/TCompactProtocolTests.swift 
b/lib/swift/Tests/ThriftTests/TCompactProtocolTests.swift
index ccc32aa..882c260 100644
--- a/lib/swift/Tests/ThriftTests/TCompactProtocolTests.swift
+++ b/lib/swift/Tests/ThriftTests/TCompactProtocolTests.swift
@@ -128,6 +128,70 @@ class TCompactProtocolTests: XCTestCase {
     }
   }
   
+  func testInt32ZigZag() {
+    let zero: Int32 = 0
+    let one: Int32 = 1
+    let nOne: Int32 = -1
+    let two: Int32 = 2
+    let nTwo: Int32 = -2
+    let max = Int32.max
+    let min = Int32.min
+
+    XCTAssertEqual(proto.i32ToZigZag(zero), UInt32(0), "Error 32bit zigzag on 
\(zero)")
+    XCTAssertEqual(proto.zigZagToi32(0), zero, "Error 32bit zigzag on \(zero)")
+
+    XCTAssertEqual(proto.i32ToZigZag(nOne), UInt32(1), "Error 32bit zigzag on 
\(nOne)")
+    XCTAssertEqual(proto.zigZagToi32(1), nOne, "Error 32bit zigzag on \(nOne)")
+
+    XCTAssertEqual(proto.i32ToZigZag(one), UInt32(2), "Error 32bit zigzag on 
\(one)")
+    XCTAssertEqual(proto.zigZagToi32(2), one, "Error 32bit zigzag on \(one)")
+
+    XCTAssertEqual(proto.i32ToZigZag(nTwo), UInt32(3), "Error 32bit zigzag on 
\(nTwo)")
+    XCTAssertEqual(proto.zigZagToi32(3), nTwo, "Error 32bit zigzag on \(nTwo)")
+
+    XCTAssertEqual(proto.i32ToZigZag(two), UInt32(4), "Error 32bit zigzag on 
\(two)")
+    XCTAssertEqual(proto.zigZagToi32(4), two, "Error 32bit zigzag on \(two)")
+
+    let uMaxMinusOne: UInt32 = UInt32.max - 1
+    XCTAssertEqual(proto.i32ToZigZag(max), uMaxMinusOne, "Error 32bit zigzag 
on \(max)")
+    XCTAssertEqual(proto.zigZagToi32(uMaxMinusOne), max, "Error 32bit zigzag 
on \(max)")
+
+    XCTAssertEqual(proto.i32ToZigZag(min), UInt32.max, "Error 32bit zigzag on 
\(min)")
+    XCTAssertEqual(proto.zigZagToi32(UInt32.max), min, "Error 32bit zigzag on 
\(min)")
+  }
+
+  func testInt64ZigZag() {
+    let zero: Int64 = 0
+    let one: Int64 = 1
+    let nOne: Int64 = -1
+    let two: Int64 = 2
+    let nTwo: Int64 = -2
+    let max = Int64.max
+    let min = Int64.min
+
+    XCTAssertEqual(proto.i64ToZigZag(zero), UInt64(0), "Error 64bit zigzag on 
\(zero)")
+    XCTAssertEqual(proto.zigZagToi64(0), zero, "Error 64bit zigzag on \(zero)")
+
+    XCTAssertEqual(proto.i64ToZigZag(nOne), UInt64(1), "Error 64bit zigzag on 
\(nOne)")
+    XCTAssertEqual(proto.zigZagToi64(1), nOne, "Error 64bit zigzag on \(nOne)")
+
+    XCTAssertEqual(proto.i64ToZigZag(one), UInt64(2), "Error 64bit zigzag on 
\(one)")
+    XCTAssertEqual(proto.zigZagToi64(2), one, "Error 64bit zigzag on \(one)")
+
+    XCTAssertEqual(proto.i64ToZigZag(nTwo), UInt64(3), "Error 64bit zigzag on 
\(nTwo)")
+    XCTAssertEqual(proto.zigZagToi64(3), nTwo, "Error 64bit zigzag on \(nTwo)")
+
+    XCTAssertEqual(proto.i64ToZigZag(two), UInt64(4), "Error 64bit zigzag on 
\(two)")
+    XCTAssertEqual(proto.zigZagToi64(4), two, "Error 64bit zigzag on \(two)")
+
+    let uMaxMinusOne: UInt64 = UInt64.max - 1
+    XCTAssertEqual(proto.i64ToZigZag(max), uMaxMinusOne, "Error 64bit zigzag 
on \(max)")
+    XCTAssertEqual(proto.zigZagToi64(uMaxMinusOne), max, "Error 64bit zigzag 
on \(max)")
+
+    XCTAssertEqual(proto.i64ToZigZag(min), UInt64.max, "Error 64bit zigzag on 
\(min)")
+    XCTAssertEqual(proto.zigZagToi64(UInt64.max), min, "Error 64bit zigzag on 
\(min)")
+  }
+  
   static var allTests : [(String, (TCompactProtocolTests) -> () throws -> 
Void)] {
     return [
       ("testInt8WriteRead", testInt8WriteRead),
@@ -138,7 +202,9 @@ class TCompactProtocolTests: XCTestCase {
       ("testBoolWriteRead", testBoolWriteRead),
       ("testStringWriteRead", testStringWriteRead),
       ("testDataWriteRead", testDataWriteRead),
-      ("testStructWriteRead", testStructWriteRead)
+      ("testStructWriteRead", testStructWriteRead),
+      ("testInt32ZigZag", testInt32ZigZag),
+      ("testInt64ZigZag", testInt64ZigZag)
     ]
   }
 }
diff --git a/lib/swift/Tests/ThriftTests/ThriftTests.swift 
b/lib/swift/Tests/ThriftTests/ThriftTests.swift
index 0c81330..9316100 100644
--- a/lib/swift/Tests/ThriftTests/ThriftTests.swift
+++ b/lib/swift/Tests/ThriftTests/ThriftTests.swift
@@ -3,13 +3,13 @@ import XCTest
 
 class ThriftTests: XCTestCase {
   func testVersion() {
-    XCTAssertEqual(Thrift().version, "0.0.1")
+    XCTAssertEqual(Thrift().version, "1.1.0")
   }
-  
+
   func test_in_addr_extension() {
-    
+
   }
-  
+
   static var allTests : [(String, (ThriftTests) -> () throws -> Void)] {
     return [
       ("testVersion", testVersion),

Reply via email to