forked from grpc/grpc-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.grpc.swift
129 lines (112 loc) · 4.5 KB
/
test.grpc.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//
// DO NOT EDIT.
// swift-format-ignore-file
//
// Generated by the protocol buffer compiler.
// Source: test.proto
//
//
// 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 GRPC
import NIO
import SwiftProtobuf
/// Usage: instantiate `Codegentest_FooClient`, then call methods of this protocol to make API calls.
internal protocol Codegentest_FooClientProtocol: GRPCClient {
var serviceName: String { get }
var interceptors: Codegentest_FooClientInterceptorFactoryProtocol? { get }
func bar(
_ request: SwiftProtobuf.Google_Protobuf_Empty,
callOptions: CallOptions?
) -> UnaryCall<SwiftProtobuf.Google_Protobuf_Empty, SwiftProtobuf.Google_Protobuf_Empty>
}
extension Codegentest_FooClientProtocol {
internal var serviceName: String {
return "codegentest.Foo"
}
/// Unary call to Bar
///
/// - Parameters:
/// - request: Request to send to Bar.
/// - callOptions: Call options.
/// - Returns: A `UnaryCall` with futures for the metadata, status and response.
internal func bar(
_ request: SwiftProtobuf.Google_Protobuf_Empty,
callOptions: CallOptions? = nil
) -> UnaryCall<SwiftProtobuf.Google_Protobuf_Empty, SwiftProtobuf.Google_Protobuf_Empty> {
return self.makeUnaryCall(
path: "/codegentest.Foo/Bar",
request: request,
callOptions: callOptions ?? self.defaultCallOptions,
interceptors: self.interceptors?.makeBarInterceptors() ?? []
)
}
}
internal protocol Codegentest_FooClientInterceptorFactoryProtocol {
/// - Returns: Interceptors to use when invoking 'bar'.
func makeBarInterceptors() -> [ClientInterceptor<SwiftProtobuf.Google_Protobuf_Empty, SwiftProtobuf.Google_Protobuf_Empty>]
}
internal final class Codegentest_FooClient: Codegentest_FooClientProtocol {
internal let channel: GRPCChannel
internal var defaultCallOptions: CallOptions
internal var interceptors: Codegentest_FooClientInterceptorFactoryProtocol?
/// Creates a client for the codegentest.Foo service.
///
/// - Parameters:
/// - channel: `GRPCChannel` to the service host.
/// - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
/// - interceptors: A factory providing interceptors for each RPC.
internal init(
channel: GRPCChannel,
defaultCallOptions: CallOptions = CallOptions(),
interceptors: Codegentest_FooClientInterceptorFactoryProtocol? = nil
) {
self.channel = channel
self.defaultCallOptions = defaultCallOptions
self.interceptors = interceptors
}
}
/// To build a server, implement a class that conforms to this protocol.
internal protocol Codegentest_FooProvider: CallHandlerProvider {
var interceptors: Codegentest_FooServerInterceptorFactoryProtocol? { get }
func bar(request: SwiftProtobuf.Google_Protobuf_Empty, context: StatusOnlyCallContext) -> EventLoopFuture<SwiftProtobuf.Google_Protobuf_Empty>
}
extension Codegentest_FooProvider {
internal var serviceName: Substring { return "codegentest.Foo" }
/// Determines, calls and returns the appropriate request handler, depending on the request's method.
/// Returns nil for methods not handled by this service.
internal func handle(
method name: Substring,
context: CallHandlerContext
) -> GRPCServerHandlerProtocol? {
switch name {
case "Bar":
return UnaryServerHandler(
context: context,
requestDeserializer: ProtobufDeserializer<SwiftProtobuf.Google_Protobuf_Empty>(),
responseSerializer: ProtobufSerializer<SwiftProtobuf.Google_Protobuf_Empty>(),
interceptors: self.interceptors?.makeBarInterceptors() ?? [],
userFunction: self.bar(request:context:)
)
default:
return nil
}
}
}
internal protocol Codegentest_FooServerInterceptorFactoryProtocol {
/// - Returns: Interceptors to use when handling 'bar'.
/// Defaults to calling `self.makeInterceptors()`.
func makeBarInterceptors() -> [ServerInterceptor<SwiftProtobuf.Google_Protobuf_Empty, SwiftProtobuf.Google_Protobuf_Empty>]
}