1
1
/*
2
- * Copyright 2020, gRPC Authors All rights reserved.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
2
+ * Copyright 2020, gRPC Authors All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
16
import NIO
17
17
import SwiftProtobuf
18
18
@@ -34,6 +34,18 @@ public enum CallHandlerFactory {
34
34
)
35
35
}
36
36
37
+ public static func makeUnary< Request: GRPCPayload , Response: GRPCPayload > (
38
+ callHandlerContext: CallHandlerContext ,
39
+ eventObserverFactory: @escaping ( UnaryContext < Response > ) -> UnaryEventObserver < Request , Response >
40
+ ) -> UnaryCallHandler < Request , Response > {
41
+ return UnaryCallHandler (
42
+ serializer: GRPCPayloadSerializer ( ) ,
43
+ deserializer: GRPCPayloadDeserializer ( ) ,
44
+ callHandlerContext: callHandlerContext,
45
+ eventObserverFactory: eventObserverFactory
46
+ )
47
+ }
48
+
37
49
public typealias ClientStreamingContext < Response> = UnaryResponseCallContext < Response >
38
50
public typealias ClientStreamingEventObserver < Request> = EventLoopFuture < ( StreamEvent < Request > ) -> Void >
39
51
@@ -49,6 +61,18 @@ public enum CallHandlerFactory {
49
61
)
50
62
}
51
63
64
+ public static func makeClientStreaming< Request: GRPCPayload , Response: GRPCPayload > (
65
+ callHandlerContext: CallHandlerContext ,
66
+ eventObserverFactory: @escaping ( ClientStreamingContext < Response > ) -> ClientStreamingEventObserver < Request >
67
+ ) -> ClientStreamingCallHandler < Request , Response > {
68
+ return ClientStreamingCallHandler (
69
+ serializer: GRPCPayloadSerializer ( ) ,
70
+ deserializer: GRPCPayloadDeserializer ( ) ,
71
+ callHandlerContext: callHandlerContext,
72
+ eventObserverFactory: eventObserverFactory
73
+ )
74
+ }
75
+
52
76
public typealias ServerStreamingContext < Response> = StreamingResponseCallContext < Response >
53
77
public typealias ServerStreamingEventObserver < Request> = ( Request ) -> EventLoopFuture < GRPCStatus >
54
78
@@ -64,6 +88,18 @@ public enum CallHandlerFactory {
64
88
)
65
89
}
66
90
91
+ public static func makeServerStreaming< Request: GRPCPayload , Response: GRPCPayload > (
92
+ callHandlerContext: CallHandlerContext ,
93
+ eventObserverFactory: @escaping ( ServerStreamingContext < Response > ) -> ServerStreamingEventObserver < Request >
94
+ ) -> ServerStreamingCallHandler < Request , Response > {
95
+ return ServerStreamingCallHandler (
96
+ serializer: GRPCPayloadSerializer ( ) ,
97
+ deserializer: GRPCPayloadDeserializer ( ) ,
98
+ callHandlerContext: callHandlerContext,
99
+ eventObserverFactory: eventObserverFactory
100
+ )
101
+ }
102
+
67
103
public typealias BidirectionalStreamingContext < Response> = StreamingResponseCallContext < Response >
68
104
public typealias BidirectionalStreamingEventObserver < Request> = EventLoopFuture < ( StreamEvent < Request > ) -> Void >
69
105
@@ -78,4 +114,16 @@ public enum CallHandlerFactory {
78
114
eventObserverFactory: eventObserverFactory
79
115
)
80
116
}
117
+
118
+ public static func makeBidirectionalStreaming< Request: GRPCPayload , Response: GRPCPayload > (
119
+ callHandlerContext: CallHandlerContext ,
120
+ eventObserverFactory: @escaping ( BidirectionalStreamingContext < Response > ) -> BidirectionalStreamingEventObserver < Request >
121
+ ) -> BidirectionalStreamingCallHandler < Request , Response > {
122
+ return BidirectionalStreamingCallHandler (
123
+ serializer: GRPCPayloadSerializer ( ) ,
124
+ deserializer: GRPCPayloadDeserializer ( ) ,
125
+ callHandlerContext: callHandlerContext,
126
+ eventObserverFactory: eventObserverFactory
127
+ )
128
+ }
81
129
}
0 commit comments