瀏覽代碼

Run `swiftformat` on the new runtime support code.

Daniel Alm 7 年之前
父節點
當前提交
c02b4f4076

+ 8 - 8
Examples/Echo/Generated/echo.grpc.swift

@@ -278,18 +278,18 @@ internal protocol Echo_EchoProvider {
 
 internal protocol Echo_EchoGetSession: ServerSessionUnary { }
 
-fileprivate final class Echo_EchoGetSessionImpl: ServerSessionUnaryImpl<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoGetSession { }
+fileprivate final class Echo_EchoGetSessionImpl: ServerSessionUnaryImpl<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoGetSession {}
 
-class Echo_EchoGetSessionTestStub: ServerSessionUnaryTestStub, Echo_EchoGetSession { }
+class Echo_EchoGetSessionTestStub: ServerSessionUnaryTestStub, Echo_EchoGetSession {}
 
 internal protocol Echo_EchoExpandSession: ServerSessionServerStreaming {
   /// Send a message. Nonblocking.
   func send(_ response: Echo_EchoResponse, completion: ((Bool) -> Void)?) throws
 }
 
-fileprivate final class Echo_EchoExpandSessionImpl: ServerSessionServerStreamingImpl<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoExpandSession { }
+fileprivate final class Echo_EchoExpandSessionImpl: ServerSessionServerStreamingImpl<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoExpandSession {}
 
-class Echo_EchoExpandSessionTestStub: ServerSessionServerStreamingTestStub<Echo_EchoResponse>, Echo_EchoExpandSession { }
+class Echo_EchoExpandSessionTestStub: ServerSessionServerStreamingTestStub<Echo_EchoResponse>, Echo_EchoExpandSession {}
 
 internal protocol Echo_EchoCollectSession: ServerSessionClientStreaming {
   /// Receive a message. Blocks until a message is received or the client closes the connection.
@@ -299,9 +299,9 @@ internal protocol Echo_EchoCollectSession: ServerSessionClientStreaming {
   func sendAndClose(_ response: Echo_EchoResponse) throws
 }
 
-fileprivate final class Echo_EchoCollectSessionImpl: ServerSessionClientStreamingImpl<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectSession { }
+fileprivate final class Echo_EchoCollectSessionImpl: ServerSessionClientStreamingImpl<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectSession {}
 
-class Echo_EchoCollectSessionTestStub: ServerSessionClientStreamingTestStub<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectSession { }
+class Echo_EchoCollectSessionTestStub: ServerSessionClientStreamingTestStub<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectSession {}
 
 internal protocol Echo_EchoUpdateSession: ServerSessionBidirectionalStreaming {
   /// Receive a message. Blocks until a message is received or the client closes the connection.
@@ -314,9 +314,9 @@ internal protocol Echo_EchoUpdateSession: ServerSessionBidirectionalStreaming {
   func close() throws
 }
 
-fileprivate final class Echo_EchoUpdateSessionImpl: ServerSessionBidirectionalStreamingImpl<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoUpdateSession { }
+fileprivate final class Echo_EchoUpdateSessionImpl: ServerSessionBidirectionalStreamingImpl<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoUpdateSession {}
 
-class Echo_EchoUpdateSessionTestStub: ServerSessionBidirectionalStreamingTestStub<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoUpdateSession { }
+class Echo_EchoUpdateSessionTestStub: ServerSessionBidirectionalStreamingTestStub<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoUpdateSession {}
 
 
 /// Main server for generated service

+ 2 - 2
Plugin/Templates/server-session-bidistreaming.swift

@@ -9,8 +9,8 @@
   func close() throws
 }
 
-fileprivate final class {{ .|session:file,service,method }}Impl: ServerSessionBidirectionalStreamingImpl<{{ method|input }}, {{ method|output }}>, {{ .|session:file,service,method }} { }
+fileprivate final class {{ .|session:file,service,method }}Impl: ServerSessionBidirectionalStreamingImpl<{{ method|input }}, {{ method|output }}>, {{ .|session:file,service,method }} {}
 
 //-{% if generateTestStubs %}
-class {{ .|session:file,service,method }}TestStub: ServerSessionBidirectionalStreamingTestStub<{{ method|input }}, {{ method|output }}>, {{ .|session:file,service,method }} { }
+class {{ .|session:file,service,method }}TestStub: ServerSessionBidirectionalStreamingTestStub<{{ method|input }}, {{ method|output }}>, {{ .|session:file,service,method }} {}
 //-{% endif %}

+ 2 - 2
Plugin/Templates/server-session-clientstreaming.swift

@@ -6,8 +6,8 @@
   func sendAndClose(_ response: {{ method|output }}) throws
 }
 
-fileprivate final class {{ .|session:file,service,method }}Impl: ServerSessionClientStreamingImpl<{{ method|input }}, {{ method|output }}>, {{ .|session:file,service,method }} { }
+fileprivate final class {{ .|session:file,service,method }}Impl: ServerSessionClientStreamingImpl<{{ method|input }}, {{ method|output }}>, {{ .|session:file,service,method }} {}
 
 //-{% if generateTestStubs %}
-class {{ .|session:file,service,method }}TestStub: ServerSessionClientStreamingTestStub<{{ method|input }}, {{ method|output }}>, {{ .|session:file,service,method }} { }
+class {{ .|session:file,service,method }}TestStub: ServerSessionClientStreamingTestStub<{{ method|input }}, {{ method|output }}>, {{ .|session:file,service,method }} {}
 //-{% endif %}

+ 2 - 2
Plugin/Templates/server-session-serverstreaming.swift

@@ -3,8 +3,8 @@
   func send(_ response: {{ method|output }}, completion: ((Bool) -> Void)?) throws
 }
 
-fileprivate final class {{ .|session:file,service,method }}Impl: ServerSessionServerStreamingImpl<{{ method|input }}, {{ method|output }}>, {{ .|session:file,service,method }} { }
+fileprivate final class {{ .|session:file,service,method }}Impl: ServerSessionServerStreamingImpl<{{ method|input }}, {{ method|output }}>, {{ .|session:file,service,method }} {}
 
 //-{% if generateTestStubs %}
-class {{ .|session:file,service,method }}TestStub: ServerSessionServerStreamingTestStub<{{ method|output }}>, {{ .|session:file,service,method }} { }
+class {{ .|session:file,service,method }}TestStub: ServerSessionServerStreamingTestStub<{{ method|output }}>, {{ .|session:file,service,method }} {}
 //-{% endif %}

+ 2 - 2
Plugin/Templates/server-session-unary.swift

@@ -1,7 +1,7 @@
 {{ access }} protocol {{ .|session:file,service,method }}: ServerSessionUnary { }
 
-fileprivate final class {{ .|session:file,service,method }}Impl: ServerSessionUnaryImpl<{{ method|input }}, {{ method|output }}>, {{ .|session:file,service,method }} { }
+fileprivate final class {{ .|session:file,service,method }}Impl: ServerSessionUnaryImpl<{{ method|input }}, {{ method|output }}>, {{ .|session:file,service,method }} {}
 
 //-{% if generateTestStubs %}
-class {{ .|session:file,service,method }}TestStub: ServerSessionUnaryTestStub, {{ .|session:file,service,method }} { }
+class {{ .|session:file,service,method }}TestStub: ServerSessionUnaryTestStub, {{ .|session:file,service,method }} {}
 //-{% endif %}

+ 37 - 37
Sources/gRPC/GenCodeSupport/ClientCallBidirectionalStreaming.swift

@@ -14,39 +14,39 @@
  * limitations under the License.
  */
 
-import Foundation
 import Dispatch
+import Foundation
 import SwiftProtobuf
 
 public protocol ClientCallBidirectionalStreamingBase: class {
   static var method: String { get }
-  
+
   // TODO: Move the other, message type-dependent, methods into this protocol. At the moment, this is not possible,
   // as the protocol would then have an associated type requirement (and become pretty much unusable in the process).
 }
 
 open class ClientCallBidirectionalStreamingImpl<InputType: Message, OutputType: Message>: ClientCallBidirectionalStreamingBase {
   open class var method: String { fatalError("needs to be overridden") }
-  
+
   private var call: Call
-  
+
   /// Create a call.
   public init(_ channel: Channel) {
-    self.call = channel.makeCall(type(of: self).method)
+    call = channel.makeCall(type(of: self).method)
   }
-  
+
   /// Call this to start a call. Nonblocking.
-  public func start(metadata:Metadata, completion: ((CallResult)->())?)
+  public func start(metadata: Metadata, completion: ((CallResult) -> Void)?)
     throws -> Self {
-      try self.call.start(.bidiStreaming, metadata:metadata, completion:completion)
-      return self
+    try call.start(.bidiStreaming, metadata: metadata, completion: completion)
+    return self
   }
-  
-  public func receive(completion:@escaping (OutputType?, ClientError?)->()) throws {
+
+  public func receive(completion: @escaping (OutputType?, ClientError?) -> Void) throws {
     do {
-      try call.receiveMessage() {(data) in
+      try call.receiveMessage { data in
         if let data = data {
-          if let returnMessage = try? OutputType(serializedData:data) {
+          if let returnMessage = try? OutputType(serializedData: data) {
             completion(returnMessage, nil)
           } else {
             completion(nil, .invalidMessageReceived)
@@ -57,13 +57,13 @@ open class ClientCallBidirectionalStreamingImpl<InputType: Message, OutputType:
       }
     }
   }
-  
+
   public func receive() throws -> OutputType {
-    var returnError : ClientError?
-    var returnMessage : OutputType!
+    var returnError: ClientError?
+    var returnMessage: OutputType!
     let sem = DispatchSemaphore(value: 0)
     do {
-      try receive() {response, error in
+      try receive { response, error in
         returnMessage = response
         returnError = error
         sem.signal()
@@ -75,24 +75,24 @@ open class ClientCallBidirectionalStreamingImpl<InputType: Message, OutputType:
     }
     return returnMessage
   }
-  
-  public func send(_ message:InputType, errorHandler:@escaping (Error)->()) throws {
+
+  public func send(_ message: InputType, errorHandler: @escaping (Error) -> Void) throws {
     let messageData = try message.serializedData()
-    try call.sendMessage(data:messageData, errorHandler:errorHandler)
+    try call.sendMessage(data: messageData, errorHandler: errorHandler)
   }
-  
-  public func closeSend(completion: (()->())?) throws {
+
+  public func closeSend(completion: (() -> Void)?) throws {
     try call.close(completion: completion)
   }
-  
+
   public func closeSend() throws {
     let sem = DispatchSemaphore(value: 0)
-    try closeSend() {
+    try closeSend {
       sem.signal()
     }
     _ = sem.wait(timeout: DispatchTime.distantFuture)
   }
-  
+
   public func cancel() {
     call.cancel()
   }
@@ -102,11 +102,11 @@ open class ClientCallBidirectionalStreamingImpl<InputType: Message, OutputType:
 /// and stores sent values for later verification.
 open class ClientCallBidirectionalStreamingTestStub<InputType: Message, OutputType: Message>: ClientCallBidirectionalStreamingBase {
   open class var method: String { fatalError("needs to be overridden") }
-  
+
   open var inputs: [InputType] = []
   open var outputs: [OutputType] = []
-  
-  open func receive(completion:@escaping (OutputType?, ClientError?)->()) throws {
+
+  open func receive(completion: @escaping (OutputType?, ClientError?) -> Void) throws {
     if let output = outputs.first {
       outputs.removeFirst()
       completion(output, nil)
@@ -114,7 +114,7 @@ open class ClientCallBidirectionalStreamingTestStub<InputType: Message, OutputTy
       completion(nil, .endOfStream)
     }
   }
-  
+
   open func receive() throws -> OutputType {
     if let output = outputs.first {
       outputs.removeFirst()
@@ -123,14 +123,14 @@ open class ClientCallBidirectionalStreamingTestStub<InputType: Message, OutputTy
       throw ClientError.endOfStream
     }
   }
-  
-  open func send(_ message: InputType, errorHandler:@escaping (Error)->()) throws {
+
+  open func send(_ message: InputType, errorHandler _: @escaping (Error) -> Void) throws {
     inputs.append(message)
   }
-  
-  open func closeSend(completion: (()->())?) throws { completion?() }
-  
-  open func closeSend() throws { }
-  
-  open func cancel() { }
+
+  open func closeSend(completion: (() -> Void)?) throws { completion?() }
+
+  open func closeSend() throws {}
+
+  open func cancel() {}
 }

+ 30 - 30
Sources/gRPC/GenCodeSupport/ClientCallClientStreaming.swift

@@ -14,63 +14,63 @@
  * limitations under the License.
  */
 
-import Foundation
 import Dispatch
+import Foundation
 import SwiftProtobuf
 
 public protocol ClientCallClientStreamingBase: class {
   static var method: String { get }
-  
+
   /// Cancel the call.
   func cancel()
-  
+
   // TODO: Move the other, message type-dependent, methods into this protocol. At the moment, this is not possible,
   // as the protocol would then have an associated type requirement (and become pretty much unusable in the process).
 }
 
 open class ClientCallClientStreamingImpl<InputType: Message, OutputType: Message>: ClientCallClientStreamingBase {
   open class var method: String { fatalError("needs to be overridden") }
-  
+
   private var call: Call
-  
+
   /// Create a call.
   public init(_ channel: Channel) {
-    self.call = channel.makeCall(type(of: self).method)
+    call = channel.makeCall(type(of: self).method)
   }
-  
+
   /// Call this to start a call. Nonblocking.
-  public func start(metadata:Metadata, completion: ((CallResult)->())?) throws -> Self {
-    try self.call.start(.clientStreaming, metadata:metadata, completion:completion)
+  public func start(metadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Self {
+    try call.start(.clientStreaming, metadata: metadata, completion: completion)
     return self
   }
-  
-  public func send(_ message: InputType, errorHandler:@escaping (Error)->()) throws {
+
+  public func send(_ message: InputType, errorHandler: @escaping (Error) -> Void) throws {
     let messageData = try message.serializedData()
-    try call.sendMessage(data:messageData, errorHandler:errorHandler)
+    try call.sendMessage(data: messageData, errorHandler: errorHandler)
   }
-  
-  public func closeAndReceive(completion:@escaping (OutputType?, ClientError?)->()) throws {
+
+  public func closeAndReceive(completion: @escaping (OutputType?, ClientError?) -> Void) throws {
     do {
-      try call.receiveMessage() {(responseData) in
+      try call.receiveMessage { responseData in
         if let responseData = responseData,
-          let response = try? OutputType(serializedData:responseData) {
+          let response = try? OutputType(serializedData: responseData) {
           completion(response, nil)
         } else {
           completion(nil, .invalidMessageReceived)
         }
       }
-      try call.close(completion:{})
+      try call.close(completion: {})
     } catch (let error) {
       throw error
     }
   }
-  
+
   public func closeAndReceive() throws -> OutputType {
-    var returnError : ClientError?
-    var returnResponse : OutputType!
+    var returnError: ClientError?
+    var returnResponse: OutputType!
     let sem = DispatchSemaphore(value: 0)
     do {
-      try closeAndReceive() {response, error in
+      try closeAndReceive { response, error in
         returnResponse = response
         returnError = error
         sem.signal()
@@ -84,7 +84,7 @@ open class ClientCallClientStreamingImpl<InputType: Message, OutputType: Message
     }
     return returnResponse
   }
-  
+
   public func cancel() {
     call.cancel()
   }
@@ -94,21 +94,21 @@ open class ClientCallClientStreamingImpl<InputType: Message, OutputType: Message
 /// stores sent values for later verification and finally returns a previously-defined result.
 open class ClientCallClientStreamingTestStub<InputType: Message, OutputType: Message>: ClientCallClientStreamingBase {
   open class var method: String { fatalError("needs to be overridden") }
-  
+
   open var inputs: [InputType] = []
   open var output: OutputType?
-  
-  open func send(_ message: InputType, errorHandler:@escaping (Error)->()) throws {
+
+  open func send(_ message: InputType, errorHandler _: @escaping (Error) -> Void) throws {
     inputs.append(message)
   }
-  
-  open func closeAndReceive(completion:@escaping (OutputType?, ClientError?)->()) throws {
+
+  open func closeAndReceive(completion: @escaping (OutputType?, ClientError?) -> Void) throws {
     completion(output!, nil)
   }
-  
+
   open func closeAndReceive() throws -> OutputType {
     return output!
   }
-  
-  open func cancel() { }
+
+  open func cancel() {}
 }

+ 26 - 26
Sources/gRPC/GenCodeSupport/ClientCallServerStreaming.swift

@@ -14,45 +14,45 @@
  * limitations under the License.
  */
 
-import Foundation
 import Dispatch
+import Foundation
 import SwiftProtobuf
 
 public protocol ClientCallServerStreamingBase: class {
   static var method: String { get }
-  
+
   /// Cancel the call.
   func cancel()
-  
+
   // TODO: Move the other, message type-dependent, methods into this protocol. At the moment, this is not possible,
   // as the protocol would then have an associated type requirement (and become pretty much unusable in the process).
 }
 
 open class ClientCallServerStreamingImpl<InputType: Message, OutputType: Message>: ClientCallServerStreamingBase {
   open class var method: String { fatalError("needs to be overridden") }
-  
+
   private var call: Call
-  
+
   /// Create a call.
   public init(_ channel: Channel) {
-    self.call = channel.makeCall(type(of: self).method)
+    call = channel.makeCall(type(of: self).method)
   }
-  
+
   /// Call this once with the message to send. Nonblocking.
-  public func start(request: InputType, metadata: Metadata, completion: ((CallResult) -> ())?) throws -> Self {
+  public func start(request: InputType, metadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Self {
     let requestData = try request.serializedData()
     try call.start(.serverStreaming,
-                   metadata:metadata,
-                   message:requestData,
-                   completion:completion)
+                   metadata: metadata,
+                   message: requestData,
+                   completion: completion)
     return self
   }
-  
-  public func receive(completion:@escaping (OutputType?, ClientError?)->()) throws {
+
+  public func receive(completion: @escaping (OutputType?, ClientError?) -> Void) throws {
     do {
-      try call.receiveMessage() {(responseData) in
+      try call.receiveMessage { responseData in
         if let responseData = responseData {
-          if let response = try? OutputType(serializedData:responseData) {
+          if let response = try? OutputType(serializedData: responseData) {
             completion(response, nil)
           } else {
             completion(nil, .invalidMessageReceived)
@@ -63,13 +63,13 @@ open class ClientCallServerStreamingImpl<InputType: Message, OutputType: Message
       }
     }
   }
-  
+
   public func receive() throws -> OutputType {
-    var returnError : ClientError?
-    var returnResponse : OutputType!
+    var returnError: ClientError?
+    var returnResponse: OutputType!
     let sem = DispatchSemaphore(value: 0)
     do {
-      try receive() {response, error in
+      try receive { response, error in
         returnResponse = response
         returnError = error
         sem.signal()
@@ -81,7 +81,7 @@ open class ClientCallServerStreamingImpl<InputType: Message, OutputType: Message
     }
     return returnResponse
   }
-  
+
   public func cancel() {
     call.cancel()
   }
@@ -90,10 +90,10 @@ open class ClientCallServerStreamingImpl<InputType: Message, OutputType: Message
 /// Simple fake implementation of ClientCallServerStreamingBase that returns a previously-defined set of results.
 open class ClientCallServerStreamingTestStub<OutputType: Message>: ClientCallServerStreamingBase {
   open class var method: String { fatalError("needs to be overridden") }
-  
+
   open var outputs: [OutputType] = []
-  
-  open func receive(completion:@escaping (OutputType?, ClientError?)->()) throws {
+
+  open func receive(completion: @escaping (OutputType?, ClientError?) -> Void) throws {
     if let output = outputs.first {
       outputs.removeFirst()
       completion(output, nil)
@@ -101,7 +101,7 @@ open class ClientCallServerStreamingTestStub<OutputType: Message>: ClientCallSer
       completion(nil, .endOfStream)
     }
   }
-  
+
   open func receive() throws -> OutputType {
     if let output = outputs.first {
       outputs.removeFirst()
@@ -110,6 +110,6 @@ open class ClientCallServerStreamingTestStub<OutputType: Message>: ClientCallSer
       throw ClientError.endOfStream
     }
   }
-  
-  open func cancel() { }
+
+  open func cancel() {}
 }

+ 14 - 14
Sources/gRPC/GenCodeSupport/ClientCallUnary.swift

@@ -14,34 +14,34 @@
  * limitations under the License.
  */
 
-import Foundation
 import Dispatch
+import Foundation
 import SwiftProtobuf
 
 public protocol ClientCallUnary: class {
   static var method: String { get }
-  
+
   /// Cancel the call.
   func cancel()
 }
 
 open class ClientCallUnaryImpl<InputType: Message, OutputType: Message>: ClientCallUnary {
   open class var method: String { fatalError("needs to be overridden") }
-  
+
   private var call: Call
-  
+
   /// Create a call.
   public init(_ channel: Channel) {
-    self.call = channel.makeCall(type(of: self).method)
+    call = channel.makeCall(type(of: self).method)
   }
-  
+
   /// Run the call. Blocks until the reply is received.
   /// - Throws: `BinaryEncodingError` if encoding fails. `CallError` if fails to call. `ClientError` if receives no response.
   public func run(request: InputType, metadata: Metadata) throws -> OutputType {
     let sem = DispatchSemaphore(value: 0)
-    var returnCallResult : CallResult!
-    var returnResponse : OutputType?
-    _ = try start(request:request, metadata:metadata) { response, callResult in
+    var returnCallResult: CallResult!
+    var returnResponse: OutputType?
+    _ = try start(request: request, metadata: metadata) { response, callResult in
       returnResponse = response
       returnCallResult = callResult
       sem.signal()
@@ -53,16 +53,16 @@ open class ClientCallUnaryImpl<InputType: Message, OutputType: Message>: ClientC
       throw ClientError.error(c: returnCallResult)
     }
   }
-  
+
   /// Start the call. Nonblocking.
   /// - Throws: `BinaryEncodingError` if encoding fails. `CallError` if fails to call.
   public func start(request: InputType,
                     metadata: Metadata,
-                    completion: @escaping ((OutputType?, CallResult)->())) throws -> Self {
+                    completion: @escaping ((OutputType?, CallResult) -> Void)) throws -> Self {
     let requestData = try request.serializedData()
-    try call.start(.unary, metadata:metadata, message:requestData) { (callResult) in
+    try call.start(.unary, metadata: metadata, message: requestData) { callResult in
       if let responseData = callResult.resultData,
-        let response = try? OutputType(serializedData:responseData) {
+        let response = try? OutputType(serializedData: responseData) {
         completion(response, callResult)
       } else {
         completion(nil, callResult)
@@ -70,7 +70,7 @@ open class ClientCallUnaryImpl<InputType: Message, OutputType: Message>: ClientC
     }
     return self
   }
-  
+
   public func cancel() {
     call.cancel()
   }

+ 3 - 5
Sources/gRPC/GenCodeSupport/ClientError.swift

@@ -15,11 +15,9 @@
  */
 
 import Foundation
-import Dispatch
-import SwiftProtobuf
 
 public enum ClientError: Error {
-	case endOfStream
-	case invalidMessageReceived
-	case error(c: CallResult)
+  case endOfStream
+  case invalidMessageReceived
+  case error(c: CallResult)
 }

+ 0 - 2
Sources/gRPC/GenCodeSupport/ServerError.swift

@@ -15,8 +15,6 @@
  */
 
 import Foundation
-import Dispatch
-import SwiftProtobuf
 
 /// Type for errors thrown from generated server code.
 public enum ServerError: Error {

+ 17 - 17
Sources/gRPC/GenCodeSupport/ServerSession.swift

@@ -14,36 +14,36 @@
  * limitations under the License.
  */
 
-import Foundation
 import Dispatch
+import Foundation
 import SwiftProtobuf
 
 public protocol ServerSession: class {
-  var requestMetadata : Metadata { get }
-  
-  var statusCode : StatusCode { get }
-  var statusMessage : String { get }
-  var initialMetadata : Metadata { get }
-  var trailingMetadata : Metadata { get }
+  var requestMetadata: Metadata { get }
+
+  var statusCode: StatusCode { get }
+  var statusMessage: String { get }
+  var initialMetadata: Metadata { get }
+  var trailingMetadata: Metadata { get }
 }
 
 open class ServerSessionImpl: ServerSession {
-  public var handler : Handler
-  public var requestMetadata : Metadata { return handler.requestMetadata }
-  
-  public var statusCode : StatusCode = .ok
-  public var statusMessage : String = "OK"
-  public var initialMetadata : Metadata = Metadata()
-  public var trailingMetadata : Metadata = Metadata()
-  
-  public init(handler:Handler) {
+  public var handler: Handler
+  public var requestMetadata: Metadata { return handler.requestMetadata }
+
+  public var statusCode: StatusCode = .ok
+  public var statusMessage: String = "OK"
+  public var initialMetadata: Metadata = Metadata()
+  public var trailingMetadata: Metadata = Metadata()
+
+  public init(handler: Handler) {
     self.handler = handler
   }
 }
 
 open class ServerSessionTestStub: ServerSession {
   open var requestMetadata = Metadata()
-  
+
   open var statusCode = StatusCode.ok
   open var statusMessage = "OK"
   open var initialMetadata = Metadata()

+ 24 - 24
Sources/gRPC/GenCodeSupport/ServerSessionBidirectionalStreaming.swift

@@ -14,28 +14,28 @@
  * limitations under the License.
  */
 
-import Foundation
 import Dispatch
+import Foundation
 import SwiftProtobuf
 
-public protocol ServerSessionBidirectionalStreaming: ServerSession { }
+public protocol ServerSessionBidirectionalStreaming: ServerSession {}
 
 open class ServerSessionBidirectionalStreamingImpl<InputType: Message, OutputType: Message>: ServerSessionImpl, ServerSessionBidirectionalStreaming {
   public typealias ProviderBlock = (ServerSessionBidirectionalStreamingImpl) throws -> Void
   private var providerBlock: ProviderBlock
-  
-  public init(handler:Handler, providerBlock: @escaping ProviderBlock) {
+
+  public init(handler: Handler, providerBlock: @escaping ProviderBlock) {
     self.providerBlock = providerBlock
-    super.init(handler:handler)
+    super.init(handler: handler)
   }
-  
+
   public func receive() throws -> InputType {
     let sem = DispatchSemaphore(value: 0)
-    var requestMessage : InputType?
-    try self.handler.receiveMessage() {(requestData) in
+    var requestMessage: InputType?
+    try handler.receiveMessage { requestData in
       if let requestData = requestData {
         do {
-          requestMessage = try InputType(serializedData:requestData)
+          requestMessage = try InputType(serializedData: requestData)
         } catch (let error) {
           print("error \(error)")
         }
@@ -49,21 +49,21 @@ open class ServerSessionBidirectionalStreamingImpl<InputType: Message, OutputTyp
       throw ServerError.endOfStream
     }
   }
-  
-  public func send(_ response: OutputType, completion: ((Bool)->())?) throws {
-    try handler.sendResponse(message:response.serializedData(), completion: completion)
+
+  public func send(_ response: OutputType, completion: ((Bool) -> Void)?) throws {
+    try handler.sendResponse(message: response.serializedData(), completion: completion)
   }
-  
+
   public func close() throws {
     let sem = DispatchSemaphore(value: 0)
-    try self.handler.sendStatus(statusCode:self.statusCode,
-                                statusMessage:self.statusMessage,
-                                trailingMetadata:self.trailingMetadata) { _ in sem.signal() }
+    try handler.sendStatus(statusCode: statusCode,
+                           statusMessage: statusMessage,
+                           trailingMetadata: trailingMetadata) { _ in sem.signal() }
     _ = sem.wait(timeout: DispatchTime.distantFuture)
   }
-  
-  public func run(queue:DispatchQueue) throws {
-    try self.handler.sendMetadata(initialMetadata:initialMetadata) { _ in
+
+  public func run(queue: DispatchQueue) throws {
+    try handler.sendMetadata(initialMetadata: initialMetadata) { _ in
       queue.async {
         do {
           try self.providerBlock(self)
@@ -80,7 +80,7 @@ open class ServerSessionBidirectionalStreamingImpl<InputType: Message, OutputTyp
 open class ServerSessionBidirectionalStreamingTestStub<InputType: Message, OutputType: Message>: ServerSessionTestStub, ServerSessionBidirectionalStreaming {
   open var inputs: [InputType] = []
   open var outputs: [OutputType] = []
-  
+
   open func receive() throws -> InputType {
     if let input = inputs.first {
       inputs.removeFirst()
@@ -89,10 +89,10 @@ open class ServerSessionBidirectionalStreamingTestStub<InputType: Message, Outpu
       throw ServerError.endOfStream
     }
   }
-  
-  open func send(_ response: OutputType, completion: ((Bool)->())?) throws {
+
+  open func send(_ response: OutputType, completion _: ((Bool) -> Void)?) throws {
     outputs.append(response)
   }
-  
-  open func close() throws { }
+
+  open func close() throws {}
 }

+ 21 - 21
Sources/gRPC/GenCodeSupport/ServerSessionClientStreaming.swift

@@ -14,27 +14,27 @@
  * limitations under the License.
  */
 
-import Foundation
 import Dispatch
+import Foundation
 import SwiftProtobuf
 
-public protocol ServerSessionClientStreaming: ServerSession { }
+public protocol ServerSessionClientStreaming: ServerSession {}
 
 open class ServerSessionClientStreamingImpl<InputType: Message, OutputType: Message>: ServerSessionImpl, ServerSessionClientStreaming {
   public typealias ProviderBlock = (ServerSessionClientStreamingImpl) throws -> Void
   private var providerBlock: ProviderBlock
-  
-  public init(handler:Handler, providerBlock: @escaping ProviderBlock) {
+
+  public init(handler: Handler, providerBlock: @escaping ProviderBlock) {
     self.providerBlock = providerBlock
-    super.init(handler:handler)
+    super.init(handler: handler)
   }
-  
+
   public func receive() throws -> InputType {
     let sem = DispatchSemaphore(value: 0)
-    var requestMessage : InputType?
-    try self.handler.receiveMessage() {(requestData) in
+    var requestMessage: InputType?
+    try handler.receiveMessage { requestData in
       if let requestData = requestData {
-        requestMessage = try? InputType(serializedData:requestData)
+        requestMessage = try? InputType(serializedData: requestData)
       }
       sem.signal()
     }
@@ -44,16 +44,16 @@ open class ServerSessionClientStreamingImpl<InputType: Message, OutputType: Mess
     }
     return requestMessage!
   }
-  
+
   public func sendAndClose(_ response: OutputType) throws {
-    try self.handler.sendResponse(message:response.serializedData(),
-                                  statusCode:self.statusCode,
-                                  statusMessage:self.statusMessage,
-                                  trailingMetadata:self.trailingMetadata)
+    try handler.sendResponse(message: response.serializedData(),
+                             statusCode: statusCode,
+                             statusMessage: statusMessage,
+                             trailingMetadata: trailingMetadata)
   }
-  
-  public func run(queue:DispatchQueue) throws {
-    try self.handler.sendMetadata(initialMetadata:initialMetadata) { _ in
+
+  public func run(queue: DispatchQueue) throws {
+    try handler.sendMetadata(initialMetadata: initialMetadata) { _ in
       queue.async {
         do {
           try self.providerBlock(self)
@@ -70,7 +70,7 @@ open class ServerSessionClientStreamingImpl<InputType: Message, OutputType: Mess
 open class ServerSessionClientStreamingTestStub<InputType: Message, OutputType: Message>: ServerSessionTestStub, ServerSessionClientStreaming {
   open var inputs: [InputType] = []
   open var output: OutputType?
-  
+
   open func receive() throws -> InputType {
     if let input = inputs.first {
       inputs.removeFirst()
@@ -79,10 +79,10 @@ open class ServerSessionClientStreamingTestStub<InputType: Message, OutputType:
       throw ServerError.endOfStream
     }
   }
-  
+
   open func sendAndClose(_ response: OutputType) throws {
     output = response
   }
-  
-  open func close() throws { }
+
+  open func close() throws {}
 }

+ 20 - 20
Sources/gRPC/GenCodeSupport/ServerSessionServerStreaming.swift

@@ -14,39 +14,39 @@
  * limitations under the License.
  */
 
-import Foundation
 import Dispatch
+import Foundation
 import SwiftProtobuf
 
-public protocol ServerSessionServerStreaming: ServerSession { }
+public protocol ServerSessionServerStreaming: ServerSession {}
 
 open class ServerSessionServerStreamingImpl<InputType: Message, OutputType: Message>: ServerSessionImpl, ServerSessionServerStreaming {
   public typealias ProviderBlock = (InputType, ServerSessionServerStreamingImpl) throws -> Void
   private var providerBlock: ProviderBlock
-  
-  public init(handler:Handler, providerBlock: @escaping ProviderBlock) {
+
+  public init(handler: Handler, providerBlock: @escaping ProviderBlock) {
     self.providerBlock = providerBlock
-    super.init(handler:handler)
+    super.init(handler: handler)
   }
-  
-  public func send(_ response: OutputType, completion: ((Bool)->())?) throws {
-    try handler.sendResponse(message:response.serializedData(), completion: completion)
+
+  public func send(_ response: OutputType, completion: ((Bool) -> Void)?) throws {
+    try handler.sendResponse(message: response.serializedData(), completion: completion)
   }
-  
-  public func run(queue:DispatchQueue) throws {
-    try self.handler.receiveMessage(initialMetadata:initialMetadata) {(requestData) in
+
+  public func run(queue: DispatchQueue) throws {
+    try handler.receiveMessage(initialMetadata: initialMetadata) { requestData in
       if let requestData = requestData {
         do {
-          let requestMessage = try InputType(serializedData:requestData)
+          let requestMessage = try InputType(serializedData: requestData)
           // to keep providers from blocking the server thread,
           // we dispatch them to another queue.
           queue.async {
             do {
               try self.providerBlock(requestMessage, self)
-              try self.handler.sendStatus(statusCode:self.statusCode,
-                                          statusMessage:self.statusMessage,
-                                          trailingMetadata:self.trailingMetadata,
-                                          completion:nil)
+              try self.handler.sendStatus(statusCode: self.statusCode,
+                                          statusMessage: self.statusMessage,
+                                          trailingMetadata: self.trailingMetadata,
+                                          completion: nil)
             } catch (let error) {
               print("error: \(error)")
             }
@@ -63,10 +63,10 @@ open class ServerSessionServerStreamingImpl<InputType: Message, OutputType: Mess
 /// and stores sent values for later verification.
 open class ServerSessionServerStreamingTestStub<OutputType: Message>: ServerSessionTestStub, ServerSessionServerStreaming {
   open var outputs: [OutputType] = []
-  
-  open func send(_ response: OutputType, completion: ((Bool)->())?) throws {
+
+  open func send(_ response: OutputType, completion _: ((Bool) -> Void)?) throws {
     outputs.append(response)
   }
-  
-  open func close() throws { }
+
+  open func close() throws {}
 }

+ 14 - 14
Sources/gRPC/GenCodeSupport/ServerSessionUnary.swift

@@ -14,34 +14,34 @@
  * limitations under the License.
  */
 
-import Foundation
 import Dispatch
+import Foundation
 import SwiftProtobuf
 
-public protocol ServerSessionUnary: ServerSession { }
+public protocol ServerSessionUnary: ServerSession {}
 
 open class ServerSessionUnaryImpl<InputType: Message, OutputType: Message>: ServerSessionImpl, ServerSessionUnary {
   public typealias ProviderBlock = (InputType, ServerSessionUnaryImpl) throws -> OutputType
   private var providerBlock: ProviderBlock
-  
-  public init(handler:Handler, providerBlock: @escaping ProviderBlock) {
+
+  public init(handler: Handler, providerBlock: @escaping ProviderBlock) {
     self.providerBlock = providerBlock
-    super.init(handler:handler)
+    super.init(handler: handler)
   }
-  
-  public func run(queue:DispatchQueue) throws {
-    try handler.receiveMessage(initialMetadata:initialMetadata) {(requestData) in
+
+  public func run(queue _: DispatchQueue) throws {
+    try handler.receiveMessage(initialMetadata: initialMetadata) { requestData in
       if let requestData = requestData {
-        let requestMessage = try InputType(serializedData:requestData)
+        let requestMessage = try InputType(serializedData: requestData)
         let replyMessage = try self.providerBlock(requestMessage, self)
-        try self.handler.sendResponse(message:replyMessage.serializedData(),
-                                      statusCode:self.statusCode,
-                                      statusMessage:self.statusMessage,
-                                      trailingMetadata:self.trailingMetadata)
+        try self.handler.sendResponse(message: replyMessage.serializedData(),
+                                      statusCode: self.statusCode,
+                                      statusMessage: self.statusMessage,
+                                      trailingMetadata: self.trailingMetadata)
       }
     }
   }
 }
 
 /// Trivial fake implementation of ServerSessionUnary.
-open class ServerSessionUnaryTestStub: ServerSessionTestStub, ServerSessionUnary { }
+open class ServerSessionUnaryTestStub: ServerSessionTestStub, ServerSessionUnary {}