瀏覽代碼

Rename many `Impl` classes to `Base` and extract a bit more common logic into a shared `ClientCall` protocol + `ClientCallBase` class (similar to `ServerSession`).

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

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

@@ -28,18 +28,18 @@ import SwiftProtobuf
 
 internal protocol Echo_EchoGetCall: ClientCallUnary { }
 
-fileprivate final class Echo_EchoGetCallImpl: ClientCallUnaryImpl<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoGetCall {
+fileprivate final class Echo_EchoGetCallBase: ClientCallUnaryBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoGetCall {
   override class var method: String { return "/echo.Echo/Get" }
 }
 
-internal protocol Echo_EchoExpandCall: ClientCallServerStreamingBase {
+internal protocol Echo_EchoExpandCall: ClientCallServerStreaming {
   /// Call this to wait for a result. Blocking.
   func receive() throws -> Echo_EchoResponse
   /// Call this to wait for a result. Nonblocking.
   func receive(completion: @escaping (Echo_EchoResponse?, ClientError?) -> Void) throws
 }
 
-fileprivate final class Echo_EchoExpandCallImpl: ClientCallServerStreamingImpl<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoExpandCall {
+fileprivate final class Echo_EchoExpandCallBase: ClientCallServerStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoExpandCall {
   override class var method: String { return "/echo.Echo/Expand" }
 }
 
@@ -47,7 +47,7 @@ class Echo_EchoExpandCallTestStub: ClientCallServerStreamingTestStub<Echo_EchoRe
   override class var method: String { return "/echo.Echo/Expand" }
 }
 
-internal protocol Echo_EchoCollectCall: ClientCallClientStreamingBase {
+internal protocol Echo_EchoCollectCall: ClientCallClientStreaming {
   /// Call this to send each message in the request stream. Nonblocking.
   func send(_ message: Echo_EchoRequest, errorHandler: @escaping (Error) -> Void) throws
   
@@ -57,7 +57,7 @@ internal protocol Echo_EchoCollectCall: ClientCallClientStreamingBase {
   func closeAndReceive(completion: @escaping (Echo_EchoResponse?, ClientError?) -> Void) throws
 }
 
-fileprivate final class Echo_EchoCollectCallImpl: ClientCallClientStreamingImpl<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectCall {
+fileprivate final class Echo_EchoCollectCallBase: ClientCallClientStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectCall {
   override class var method: String { return "/echo.Echo/Collect" }
 }
 
@@ -67,7 +67,7 @@ class Echo_EchoCollectCallTestStub: ClientCallClientStreamingTestStub<Echo_EchoR
   override class var method: String { return "/echo.Echo/Collect" }
 }
 
-internal protocol Echo_EchoUpdateCall: ClientCallBidirectionalStreamingBase {
+internal protocol Echo_EchoUpdateCall: ClientCallBidirectionalStreaming {
   /// Call this to wait for a result. Blocking.
   func receive() throws -> Echo_EchoResponse
   /// Call this to wait for a result. Nonblocking.
@@ -82,7 +82,7 @@ internal protocol Echo_EchoUpdateCall: ClientCallBidirectionalStreamingBase {
   func closeSend(completion: (() -> Void)?) throws
 }
 
-fileprivate final class Echo_EchoUpdateCallImpl: ClientCallBidirectionalStreamingImpl<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoUpdateCall {
+fileprivate final class Echo_EchoUpdateCallBase: ClientCallBidirectionalStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoUpdateCall {
   override class var method: String { return "/echo.Echo/Update" }
 }
 
@@ -91,7 +91,7 @@ class Echo_EchoUpdateCallTestStub: ClientCallBidirectionalStreamingTestStub<Echo
 }
 
 
-/// Instantiate Echo_EchoServiceImpl, then call methods of this protocol to make API calls.
+/// Instantiate Echo_EchoServiceClient, then call methods of this protocol to make API calls.
 internal protocol Echo_EchoService: ServiceClient {
   /// Synchronous. Unary.
   func get(_ request: Echo_EchoRequest) throws -> Echo_EchoResponse
@@ -118,13 +118,13 @@ internal protocol Echo_EchoService: ServiceClient {
 internal final class Echo_EchoServiceClient: ServiceClientBase, Echo_EchoService {
   /// Synchronous. Unary.
   internal func get(_ request: Echo_EchoRequest) throws -> Echo_EchoResponse {
-    return try Echo_EchoGetCallImpl(channel)
+    return try Echo_EchoGetCallBase(channel)
       .run(request: request, metadata: metadata)
   }
   /// Asynchronous. Unary.
   internal func get(_ request: Echo_EchoRequest,
                   completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall {
-    return try Echo_EchoGetCallImpl(channel)
+    return try Echo_EchoGetCallBase(channel)
       .start(request: request, metadata: metadata, completion: completion)
   }
 
@@ -132,7 +132,7 @@ internal final class Echo_EchoServiceClient: ServiceClientBase, Echo_EchoService
   /// Send the initial message.
   /// Use methods on the returned object to get streamed responses.
   internal func expand(_ request: Echo_EchoRequest, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall {
-    return try Echo_EchoExpandCallImpl(channel)
+    return try Echo_EchoExpandCallBase(channel)
       .start(request:request, metadata:metadata, completion:completion)
   }
 
@@ -140,7 +140,7 @@ internal final class Echo_EchoServiceClient: ServiceClientBase, Echo_EchoService
   /// Use methods on the returned object to stream messages and
   /// to close the connection and wait for a final response.
   internal func collect(completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall {
-    return try Echo_EchoCollectCallImpl(channel)
+    return try Echo_EchoCollectCallBase(channel)
        .start(metadata: metadata, completion: completion)
   }
 
@@ -148,7 +148,7 @@ internal final class Echo_EchoServiceClient: ServiceClientBase, Echo_EchoService
   /// Use methods on the returned object to stream messages,
   /// to wait for replies, and to close the connection.
   internal func update(completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall {
-    return try Echo_EchoUpdateCallImpl(channel)
+    return try Echo_EchoUpdateCallBase(channel)
       .start(metadata: metadata, completion: completion)
   }
 
@@ -199,7 +199,7 @@ 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_EchoGetSessionBase: ServerSessionUnaryBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoGetSession {}
 
 class Echo_EchoGetSessionTestStub: ServerSessionUnaryTestStub, Echo_EchoGetSession {}
 
@@ -208,7 +208,7 @@ internal protocol Echo_EchoExpandSession: ServerSessionServerStreaming {
   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_EchoExpandSessionBase: ServerSessionServerStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoExpandSession {}
 
 class Echo_EchoExpandSessionTestStub: ServerSessionServerStreamingTestStub<Echo_EchoResponse>, Echo_EchoExpandSession {}
 
@@ -220,7 +220,7 @@ 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_EchoCollectSessionBase: ServerSessionClientStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectSession {}
 
 class Echo_EchoCollectSessionTestStub: ServerSessionClientStreamingTestStub<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectSession {}
 
@@ -235,14 +235,14 @@ internal protocol Echo_EchoUpdateSession: ServerSessionBidirectionalStreaming {
   func close() throws
 }
 
-fileprivate final class Echo_EchoUpdateSessionImpl: ServerSessionBidirectionalStreamingImpl<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoUpdateSession {}
+fileprivate final class Echo_EchoUpdateSessionBase: ServerSessionBidirectionalStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoUpdateSession {}
 
 class Echo_EchoUpdateSessionTestStub: ServerSessionBidirectionalStreamingTestStub<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoUpdateSession {}
 
 
 /// Main server for generated service
 internal final class Echo_EchoServer: ServiceServer {
-  private var provider: Echo_EchoProvider
+  private let provider: Echo_EchoProvider
 
   internal init(address: String, provider: Echo_EchoProvider) {
     self.provider = provider
@@ -259,27 +259,27 @@ internal final class Echo_EchoServer: ServiceServer {
     let provider = self.provider
     switch method {
     case "/echo.Echo/Get":
-      try Echo_EchoGetSessionImpl(
+      try Echo_EchoGetSessionBase(
         handler: handler,
-        providerBlock: { try provider.get(request: $0, session: $1 as! Echo_EchoGetSessionImpl) })
+        providerBlock: { try provider.get(request: $0, session: $1 as! Echo_EchoGetSessionBase) })
           .run(queue: queue)
       return true
     case "/echo.Echo/Expand":
-      try Echo_EchoExpandSessionImpl(
+      try Echo_EchoExpandSessionBase(
         handler: handler,
-        providerBlock: { try provider.expand(request: $0, session: $1 as! Echo_EchoExpandSessionImpl) })
+        providerBlock: { try provider.expand(request: $0, session: $1 as! Echo_EchoExpandSessionBase) })
           .run(queue: queue)
       return true
     case "/echo.Echo/Collect":
-      try Echo_EchoCollectSessionImpl(
+      try Echo_EchoCollectSessionBase(
         handler: handler,
-        providerBlock: { try provider.collect(session: $0 as! Echo_EchoCollectSessionImpl) })
+        providerBlock: { try provider.collect(session: $0 as! Echo_EchoCollectSessionBase) })
           .run(queue: queue)
       return true
     case "/echo.Echo/Update":
-      try Echo_EchoUpdateSessionImpl(
+      try Echo_EchoUpdateSessionBase(
         handler: handler,
-        providerBlock: { try provider.update(session: $0 as! Echo_EchoUpdateSessionImpl) })
+        providerBlock: { try provider.update(session: $0 as! Echo_EchoUpdateSessionBase) })
           .run(queue: queue)
       return true
     default:

+ 2 - 2
Plugin/Templates/client-call-bidistreaming.swift

@@ -1,4 +1,4 @@
-{{ access }} protocol {{ .|call:file,service,method }}: ClientCallBidirectionalStreamingBase {
+{{ access }} protocol {{ .|call:file,service,method }}: ClientCallBidirectionalStreaming {
   /// Call this to wait for a result. Blocking.
   func receive() throws -> {{ method|output }}
   /// Call this to wait for a result. Nonblocking.
@@ -13,7 +13,7 @@
   func closeSend(completion: (() -> Void)?) throws
 }
 
-fileprivate final class {{ .|call:file,service,method }}Impl: ClientCallBidirectionalStreamingImpl<{{ method|input }}, {{ method|output }}>, {{ .|call:file,service,method }} {
+fileprivate final class {{ .|call:file,service,method }}Base: ClientCallBidirectionalStreamingBase<{{ method|input }}, {{ method|output }}>, {{ .|call:file,service,method }} {
   override class var method: String { return "{{ .|path:file,service,method }}" }
 }
 

+ 2 - 2
Plugin/Templates/client-call-clientstreaming.swift

@@ -1,4 +1,4 @@
-{{ access }} protocol {{ .|call:file,service,method }}: ClientCallClientStreamingBase {
+{{ access }} protocol {{ .|call:file,service,method }}: ClientCallClientStreaming {
   /// Call this to send each message in the request stream. Nonblocking.
   func send(_ message: {{ method|input }}, errorHandler: @escaping (Error) -> Void) throws
   
@@ -8,7 +8,7 @@
   func closeAndReceive(completion: @escaping ({{ method|output }}?, ClientError?) -> Void) throws
 }
 
-fileprivate final class {{ .|call:file,service,method }}Impl: ClientCallClientStreamingImpl<{{ method|input }}, {{ method|output }}>, {{ .|call:file,service,method }} {
+fileprivate final class {{ .|call:file,service,method }}Base: ClientCallClientStreamingBase<{{ method|input }}, {{ method|output }}>, {{ .|call:file,service,method }} {
   override class var method: String { return "{{ .|path:file,service,method }}" }
 }
 

+ 2 - 2
Plugin/Templates/client-call-serverstreaming.swift

@@ -1,11 +1,11 @@
-{{ access }} protocol {{ .|call:file,service,method }}: ClientCallServerStreamingBase {
+{{ access }} protocol {{ .|call:file,service,method }}: ClientCallServerStreaming {
   /// Call this to wait for a result. Blocking.
   func receive() throws -> {{ method|output }}
   /// Call this to wait for a result. Nonblocking.
   func receive(completion: @escaping ({{ method|output }}?, ClientError?) -> Void) throws
 }
 
-fileprivate final class {{ .|call:file,service,method }}Impl: ClientCallServerStreamingImpl<{{ method|input }}, {{ method|output }}>, {{ .|call:file,service,method }} {
+fileprivate final class {{ .|call:file,service,method }}Base: ClientCallServerStreamingBase<{{ method|input }}, {{ method|output }}>, {{ .|call:file,service,method }} {
   override class var method: String { return "{{ .|path:file,service,method }}" }
 }
 

+ 1 - 1
Plugin/Templates/client-call-unary.swift

@@ -1,5 +1,5 @@
 {{ access }} protocol {{ .|call:file,service,method }}: ClientCallUnary { }
 
-fileprivate final class {{ .|call:file,service,method }}Impl: ClientCallUnaryImpl<{{ method|input }}, {{ method|output }}>, {{ .|call:file,service,method }} {
+fileprivate final class {{ .|call:file,service,method }}Base: ClientCallUnaryBase<{{ method|input }}, {{ method|output }}>, {{ .|call:file,service,method }} {
   override class var method: String { return "{{ .|path:file,service,method }}" }
 }

+ 6 - 6
Plugin/Templates/client.swift

@@ -15,7 +15,7 @@
 //-{% endif %}
 //-{% endfor %}
 
-/// Instantiate {{ .|serviceclass:file,service }}Impl, then call methods of this protocol to make API calls.
+/// Instantiate {{ .|serviceclass:file,service }}Client, then call methods of this protocol to make API calls.
 {{ access }} protocol {{ .|serviceclass:file,service }}: ServiceClient {
   //-{% for method in service.methods %}
   //-{% if method|methodIsUnary %}
@@ -51,13 +51,13 @@
   //-{% if method|methodIsUnary %}
   /// Synchronous. Unary.
   {{ access }} func {{ method|methodDescriptorName|lowercase }}(_ request: {{ method|input }}) throws -> {{ method|output }} {
-    return try {{ .|call:file,service,method }}Impl(channel)
+    return try {{ .|call:file,service,method }}Base(channel)
       .run(request: request, metadata: metadata)
   }
   /// Asynchronous. Unary.
   {{ access }} func {{ method|methodDescriptorName|lowercase }}(_ request: {{ method|input }},
                   completion: @escaping ({{ method|output }}?, CallResult) -> Void) throws -> {{ .|call:file,service,method }} {
-    return try {{ .|call:file,service,method }}Impl(channel)
+    return try {{ .|call:file,service,method }}Base(channel)
       .start(request: request, metadata: metadata, completion: completion)
   }
   //-{% endif %}
@@ -66,7 +66,7 @@
   /// Send the initial message.
   /// Use methods on the returned object to get streamed responses.
   {{ access }} func {{ method|methodDescriptorName|lowercase }}(_ request: {{ method|input }}, completion: ((CallResult) -> Void)?) throws -> {{ .|call:file,service,method }} {
-    return try {{ .|call:file,service,method }}Impl(channel)
+    return try {{ .|call:file,service,method }}Base(channel)
       .start(request:request, metadata:metadata, completion:completion)
   }
   //-{% endif %}
@@ -75,7 +75,7 @@
   /// Use methods on the returned object to stream messages and
   /// to close the connection and wait for a final response.
   {{ access }} func {{ method|methodDescriptorName|lowercase }}(completion: ((CallResult) -> Void)?) throws -> {{ .|call:file,service,method }} {
-    return try {{ .|call:file,service,method }}Impl(channel)
+    return try {{ .|call:file,service,method }}Base(channel)
        .start(metadata: metadata, completion: completion)
   }
   //-{% endif %}
@@ -84,7 +84,7 @@
   /// Use methods on the returned object to stream messages,
   /// to wait for replies, and to close the connection.
   {{ access }} func {{ method|methodDescriptorName|lowercase }}(completion: ((CallResult) -> Void)?) throws -> {{ .|call:file,service,method }} {
-    return try {{ .|call:file,service,method }}Impl(channel)
+    return try {{ .|call:file,service,method }}Base(channel)
       .start(metadata: metadata, completion: completion)
   }
   //-{% endif %}

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

@@ -9,7 +9,7 @@
   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 }}Base: ServerSessionBidirectionalStreamingBase<{{ 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 }} {}

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

@@ -6,7 +6,7 @@
   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 }}Base: ServerSessionClientStreamingBase<{{ 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 }} {}

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

@@ -3,7 +3,7 @@
   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 }}Base: ServerSessionServerStreamingBase<{{ method|input }}, {{ method|output }}>, {{ .|session:file,service,method }} {}
 
 //-{% if generateTestStubs %}
 class {{ .|session:file,service,method }}TestStub: ServerSessionServerStreamingTestStub<{{ method|output }}>, {{ .|session:file,service,method }} {}

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

@@ -1,6 +1,6 @@
 {{ 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 }}Base: ServerSessionUnaryBase<{{ method|input }}, {{ method|output }}>, {{ .|session:file,service,method }} {}
 
 //-{% if generateTestStubs %}
 class {{ .|session:file,service,method }}TestStub: ServerSessionUnaryTestStub, {{ .|session:file,service,method }} {}

+ 5 - 5
Plugin/Templates/server.swift

@@ -34,7 +34,7 @@
 
 /// Main server for generated service
 {{ access }} final class {{ .|server:file,service }}: ServiceServer {
-  private var provider: {{ .|provider:file,service }}
+  private let provider: {{ .|provider:file,service }}
 
   {{ access }} init(address: String, provider: {{ .|provider:file,service }}) {
     self.provider = provider
@@ -53,14 +53,14 @@
     //-{% for method in service.methods %}
     case "{{ .|path:file,service,method }}":
       //-{% if method|methodIsUnary or method|methodIsServerStreaming %}
-      try {{ .|session:file,service,method }}Impl(
+      try {{ .|session:file,service,method }}Base(
         handler: handler,
-        providerBlock: { try provider.{{ method|methodDescriptorName|lowercase }}(request: $0, session: $1 as! {{ .|session:file,service,method }}Impl) })
+        providerBlock: { try provider.{{ method|methodDescriptorName|lowercase }}(request: $0, session: $1 as! {{ .|session:file,service,method }}Base) })
           .run(queue: queue)
       //-{% else %}
-      try {{ .|session:file,service,method }}Impl(
+      try {{ .|session:file,service,method }}Base(
         handler: handler,
-        providerBlock: { try provider.{{ method|methodDescriptorName|lowercase }}(session: $0 as! {{ .|session:file,service,method }}Impl) })
+        providerBlock: { try provider.{{ method|methodDescriptorName|lowercase }}(session: $0 as! {{ .|session:file,service,method }}Base) })
           .run(queue: queue)
       //-{% endif %}
       return true

+ 34 - 0
Sources/gRPC/GenCodeSupport/ClientCall.swift

@@ -0,0 +1,34 @@
+/*
+ * Copyright 2018, gRPC Authors All rights reserved.
+ *
+ * Licensed 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 Dispatch
+import Foundation
+import SwiftProtobuf
+
+public protocol ClientCall: class {
+  static var method: String { get }
+}
+
+open class ClientCallBase: ClientCall {
+  open class var method: String { fatalError("needs to be overridden") }
+
+  public let call: Call
+
+  /// Create a call.
+  public init(_ channel: Channel) {
+    call = channel.makeCall(type(of: self).method)
+  }
+}

+ 3 - 14
Sources/gRPC/GenCodeSupport/ClientCallBidirectionalStreaming.swift

@@ -18,23 +18,12 @@ import Dispatch
 import Foundation
 import SwiftProtobuf
 
-public protocol ClientCallBidirectionalStreamingBase: class {
-  static var method: String { get }
-
+public protocol ClientCallBidirectionalStreaming: ClientCall {
   // 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) {
-    call = channel.makeCall(type(of: self).method)
-  }
-
+open class ClientCallBidirectionalStreamingBase<InputType: Message, OutputType: Message>: ClientCallBase, ClientCallBidirectionalStreaming {
   /// Call this to start a call. Nonblocking.
   public func start(metadata: Metadata, completion: ((CallResult) -> Void)?)
     throws -> Self {
@@ -100,7 +89,7 @@ open class ClientCallBidirectionalStreamingImpl<InputType: Message, OutputType:
 
 /// Simple fake implementation of ClientCallBidirectionalStreamingBase that returns a previously-defined set of results
 /// and stores sent values for later verification.
-open class ClientCallBidirectionalStreamingTestStub<InputType: Message, OutputType: Message>: ClientCallBidirectionalStreamingBase {
+open class ClientCallBidirectionalStreamingTestStub<InputType: Message, OutputType: Message>: ClientCallBidirectionalStreaming {
   open class var method: String { fatalError("needs to be overridden") }
 
   open var inputs: [InputType] = []

+ 3 - 14
Sources/gRPC/GenCodeSupport/ClientCallClientStreaming.swift

@@ -18,9 +18,7 @@ import Dispatch
 import Foundation
 import SwiftProtobuf
 
-public protocol ClientCallClientStreamingBase: class {
-  static var method: String { get }
-
+public protocol ClientCallClientStreaming: ClientCall {
   /// Cancel the call.
   func cancel()
 
@@ -28,16 +26,7 @@ public protocol ClientCallClientStreamingBase: class {
   // 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) {
-    call = channel.makeCall(type(of: self).method)
-  }
-
+open class ClientCallClientStreamingBase<InputType: Message, OutputType: Message>: ClientCallBase, ClientCallClientStreaming {
   /// Call this to start a call. Nonblocking.
   public func start(metadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Self {
     try call.start(.clientStreaming, metadata: metadata, completion: completion)
@@ -92,7 +81,7 @@ open class ClientCallClientStreamingImpl<InputType: Message, OutputType: Message
 
 /// Simple fake implementation of ClientCallClientStreamingBase that
 /// stores sent values for later verification and finally returns a previously-defined result.
-open class ClientCallClientStreamingTestStub<InputType: Message, OutputType: Message>: ClientCallClientStreamingBase {
+open class ClientCallClientStreamingTestStub<InputType: Message, OutputType: Message>: ClientCallClientStreaming {
   open class var method: String { fatalError("needs to be overridden") }
 
   open var inputs: [InputType] = []

+ 3 - 14
Sources/gRPC/GenCodeSupport/ClientCallServerStreaming.swift

@@ -18,9 +18,7 @@ import Dispatch
 import Foundation
 import SwiftProtobuf
 
-public protocol ClientCallServerStreamingBase: class {
-  static var method: String { get }
-
+public protocol ClientCallServerStreaming: ClientCall {
   /// Cancel the call.
   func cancel()
 
@@ -28,16 +26,7 @@ public protocol ClientCallServerStreamingBase: class {
   // 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) {
-    call = channel.makeCall(type(of: self).method)
-  }
-
+open class ClientCallServerStreamingBase<InputType: Message, OutputType: Message>: ClientCallBase, ClientCallServerStreaming {
   /// Call this once with the message to send. Nonblocking.
   public func start(request: InputType, metadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Self {
     let requestData = try request.serializedData()
@@ -88,7 +77,7 @@ 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 ClientCallServerStreamingTestStub<OutputType: Message>: ClientCallServerStreaming {
   open class var method: String { fatalError("needs to be overridden") }
 
   open var outputs: [OutputType] = []

+ 2 - 13
Sources/gRPC/GenCodeSupport/ClientCallUnary.swift

@@ -18,23 +18,12 @@ import Dispatch
 import Foundation
 import SwiftProtobuf
 
-public protocol ClientCallUnary: class {
-  static var method: String { get }
-
+public protocol ClientCallUnary: ClientCall {
   /// 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) {
-    call = channel.makeCall(type(of: self).method)
-  }
-
+open class ClientCallUnaryBase<InputType: Message, OutputType: Message>: ClientCallBase, ClientCallUnary {
   /// 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 {

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

@@ -27,7 +27,7 @@ public protocol ServerSession: class {
   var trailingMetadata: Metadata { get }
 }
 
-open class ServerSessionImpl: ServerSession {
+open class ServerSessionBase: ServerSession {
   public var handler: Handler
   public var requestMetadata: Metadata { return handler.requestMetadata }
 

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

@@ -20,8 +20,8 @@ import SwiftProtobuf
 
 public protocol ServerSessionBidirectionalStreaming: ServerSession {}
 
-open class ServerSessionBidirectionalStreamingImpl<InputType: Message, OutputType: Message>: ServerSessionImpl, ServerSessionBidirectionalStreaming {
-  public typealias ProviderBlock = (ServerSessionBidirectionalStreamingImpl) throws -> Void
+open class ServerSessionBidirectionalStreamingBase<InputType: Message, OutputType: Message>: ServerSessionBase, ServerSessionBidirectionalStreaming {
+  public typealias ProviderBlock = (ServerSessionBidirectionalStreamingBase) throws -> Void
   private var providerBlock: ProviderBlock
 
   public init(handler: Handler, providerBlock: @escaping ProviderBlock) {

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

@@ -20,8 +20,8 @@ import SwiftProtobuf
 
 public protocol ServerSessionClientStreaming: ServerSession {}
 
-open class ServerSessionClientStreamingImpl<InputType: Message, OutputType: Message>: ServerSessionImpl, ServerSessionClientStreaming {
-  public typealias ProviderBlock = (ServerSessionClientStreamingImpl) throws -> Void
+open class ServerSessionClientStreamingBase<InputType: Message, OutputType: Message>: ServerSessionBase, ServerSessionClientStreaming {
+  public typealias ProviderBlock = (ServerSessionClientStreamingBase) throws -> Void
   private var providerBlock: ProviderBlock
 
   public init(handler: Handler, providerBlock: @escaping ProviderBlock) {

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

@@ -20,8 +20,8 @@ import SwiftProtobuf
 
 public protocol ServerSessionServerStreaming: ServerSession {}
 
-open class ServerSessionServerStreamingImpl<InputType: Message, OutputType: Message>: ServerSessionImpl, ServerSessionServerStreaming {
-  public typealias ProviderBlock = (InputType, ServerSessionServerStreamingImpl) throws -> Void
+open class ServerSessionServerStreamingBase<InputType: Message, OutputType: Message>: ServerSessionBase, ServerSessionServerStreaming {
+  public typealias ProviderBlock = (InputType, ServerSessionServerStreamingBase) throws -> Void
   private var providerBlock: ProviderBlock
 
   public init(handler: Handler, providerBlock: @escaping ProviderBlock) {

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

@@ -20,8 +20,8 @@ import SwiftProtobuf
 
 public protocol ServerSessionUnary: ServerSession {}
 
-open class ServerSessionUnaryImpl<InputType: Message, OutputType: Message>: ServerSessionImpl, ServerSessionUnary {
-  public typealias ProviderBlock = (InputType, ServerSessionUnaryImpl) throws -> OutputType
+open class ServerSessionUnaryBase<InputType: Message, OutputType: Message>: ServerSessionBase, ServerSessionUnary {
+  public typealias ProviderBlock = (InputType, ServerSessionUnaryBase) throws -> OutputType
   private var providerBlock: ProviderBlock
 
   public init(handler: Handler, providerBlock: @escaping ProviderBlock) {