forked from grpc/grpc-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove the requirement that messages conform to GRPCPayload on the se…
…rver (grpc#886) Motivation: To support payloads other than `SwiftProtobuf.Message` we required that all messages conform to `GRPCPayload`. For protobuf messages we added `GRPCProtobufPayload` which provides a default implemenation of `GRPCPayload` for protobuf messages. We generated this conformance for all protobuf messages we saw. This lead to a number issues and workarounds including: grpc#738, grpc#778, grpc#801, grpc#837, grpc#877, grpc#881. The intention is to continue to support `GRPCPayload` in addition to protobuf, however, support for protobuf will not be via the `GRPCProtobufPayload` protocol. This PR adjusts server components such that they are not constrained to `GRPCPayload`. At the moment only `SwiftProtobuf.Message` is supported. Once the client side has had the same treatment and `GRPCProtobufPayload` no longer inherits from `SwiftProtobuf.Message`, support for `GRPCPayload` will be added back. Modifications: - The `HTTP1ToGRPCServerCodec` has had the message encoding and decoding removed. It now deals in `ByteBuffer`s rather than request/response messages. - An additional `GRPCServerCodecHandler` which sits between the `HTTP1ToGRPCServerCodec` and `_BaseCallHandler` has been added which serializes/deserializes messages. - Custom payload tests have been commented out. They will return when the transition has completed. Result: - Servers only support SwiftProtobuf - Genertic constraints on the server have been removed; the constraints are place on the `init` of public handlers instead. - `GRPCProtobufPayload` is no longer required on the server.
- Loading branch information
Showing
31 changed files
with
855 additions
and
382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 2020, 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 NIO | ||
import SwiftProtobuf | ||
|
||
// We can't use a 'where' clause on 'init's to constrain the generic requirements of a type. Instead | ||
// we'll use static methods on this factory. | ||
public enum CallHandlerFactory { | ||
public typealias UnaryContext<Response> = UnaryResponseCallContext<Response> | ||
public typealias UnaryEventObserver<Request, Response> = (Request) -> EventLoopFuture<Response> | ||
|
||
public static func makeUnary<Request: Message, Response: Message>( | ||
callHandlerContext: CallHandlerContext, | ||
eventObserverFactory: @escaping (UnaryContext<Response>) -> UnaryEventObserver<Request, Response> | ||
) -> UnaryCallHandler<Request, Response> { | ||
return UnaryCallHandler( | ||
serializer: ProtobufSerializer(), | ||
deserializer: ProtobufDeserializer(), | ||
callHandlerContext: callHandlerContext, | ||
eventObserverFactory: eventObserverFactory | ||
) | ||
} | ||
|
||
public typealias ClientStreamingContext<Response> = UnaryResponseCallContext<Response> | ||
public typealias ClientStreamingEventObserver<Request> = EventLoopFuture<(StreamEvent<Request>) -> Void> | ||
|
||
public static func makeClientStreaming<Request: Message, Response: Message>( | ||
callHandlerContext: CallHandlerContext, | ||
eventObserverFactory: @escaping (ClientStreamingContext<Response>) -> ClientStreamingEventObserver<Request> | ||
) -> ClientStreamingCallHandler<Request, Response> { | ||
return ClientStreamingCallHandler( | ||
serializer: ProtobufSerializer(), | ||
deserializer: ProtobufDeserializer(), | ||
callHandlerContext: callHandlerContext, | ||
eventObserverFactory: eventObserverFactory | ||
) | ||
} | ||
|
||
public typealias ServerStreamingContext<Response> = StreamingResponseCallContext<Response> | ||
public typealias ServerStreamingEventObserver<Request> = (Request) -> EventLoopFuture<GRPCStatus> | ||
|
||
public static func makeServerStreaming<Request: Message, Response: Message>( | ||
callHandlerContext: CallHandlerContext, | ||
eventObserverFactory: @escaping (ServerStreamingContext<Response>) -> ServerStreamingEventObserver<Request> | ||
) -> ServerStreamingCallHandler<Request, Response> { | ||
return ServerStreamingCallHandler( | ||
serializer: ProtobufSerializer(), | ||
deserializer: ProtobufDeserializer(), | ||
callHandlerContext: callHandlerContext, | ||
eventObserverFactory: eventObserverFactory | ||
) | ||
} | ||
|
||
public typealias BidirectionalStreamingContext<Response> = StreamingResponseCallContext<Response> | ||
public typealias BidirectionalStreamingEventObserver<Request> = EventLoopFuture<(StreamEvent<Request>) -> Void> | ||
|
||
public static func makeBidirectionalStreaming<Request: Message, Response: Message>( | ||
callHandlerContext: CallHandlerContext, | ||
eventObserverFactory: @escaping (BidirectionalStreamingContext<Response>) -> BidirectionalStreamingEventObserver<Request> | ||
) -> BidirectionalStreamingCallHandler<Request, Response> { | ||
return BidirectionalStreamingCallHandler( | ||
serializer: ProtobufSerializer(), | ||
deserializer: ProtobufDeserializer(), | ||
callHandlerContext: callHandlerContext, | ||
eventObserverFactory: eventObserverFactory | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.