|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 | 16 |
|
17 |
| -/// A namespace for request message types used by clients. |
18 |
| -public enum ClientRequest {} |
19 |
| - |
20 |
| -extension ClientRequest { |
21 |
| - /// A request created by the client for a single message. |
22 |
| - /// |
23 |
| - /// This is used for unary and server-streaming RPCs. |
24 |
| - /// |
25 |
| - /// See ``ClientRequest/Stream`` for streaming requests and ``ServerRequest/Single`` for the |
26 |
| - /// servers representation of a single-message request. |
27 |
| - /// |
28 |
| - /// ## Creating ``Single`` requests |
| 17 | +/// A request created by the client for a single message. |
| 18 | +/// |
| 19 | +/// This is used for unary and server-streaming RPCs. |
| 20 | +/// |
| 21 | +/// See ``StreamingClientRequest`` for streaming requests and ``ServerRequest`` for the |
| 22 | +/// servers representation of a single-message request. |
| 23 | +/// |
| 24 | +/// ## Creating ``Single`` requests |
| 25 | +/// |
| 26 | +/// ```swift |
| 27 | +/// let request = ClientRequest<String>(message: "Hello, gRPC!") |
| 28 | +/// print(request.metadata) // prints '[:]' |
| 29 | +/// print(request.message) // prints 'Hello, gRPC!' |
| 30 | +/// ``` |
| 31 | +public struct ClientRequest<Message: Sendable>: Sendable { |
| 32 | + /// Caller-specified metadata to send to the server at the start of the RPC. |
29 | 33 | ///
|
30 |
| - /// ```swift |
31 |
| - /// let request = ClientRequest.Single<String>(message: "Hello, gRPC!") |
32 |
| - /// print(request.metadata) // prints '[:]' |
33 |
| - /// print(request.message) // prints 'Hello, gRPC!' |
34 |
| - /// ``` |
35 |
| - public struct Single<Message: Sendable>: Sendable { |
36 |
| - /// Caller-specified metadata to send to the server at the start of the RPC. |
37 |
| - /// |
38 |
| - /// Both gRPC Swift and its transport layer may insert additional metadata. Keys prefixed with |
39 |
| - /// "grpc-" are prohibited and may result in undefined behaviour. Transports may also insert |
40 |
| - /// their own metadata, you should avoid using key names which may clash with transport specific |
41 |
| - /// metadata. Note that transports may also impose limits in the amount of metadata which may |
42 |
| - /// be sent. |
43 |
| - public var metadata: Metadata |
| 34 | + /// Both gRPC Swift and its transport layer may insert additional metadata. Keys prefixed with |
| 35 | + /// "grpc-" are prohibited and may result in undefined behaviour. Transports may also insert |
| 36 | + /// their own metadata, you should avoid using key names which may clash with transport specific |
| 37 | + /// metadata. Note that transports may also impose limits in the amount of metadata which may |
| 38 | + /// be sent. |
| 39 | + public var metadata: Metadata |
44 | 40 |
|
45 |
| - /// The message to send to the server. |
46 |
| - public var message: Message |
| 41 | + /// The message to send to the server. |
| 42 | + public var message: Message |
47 | 43 |
|
48 |
| - /// Create a new single client request. |
49 |
| - /// |
50 |
| - /// - Parameters: |
51 |
| - /// - message: The message to send to the server. |
52 |
| - /// - metadata: Metadata to send to the server at the start of the request. Defaults to empty. |
53 |
| - public init( |
54 |
| - message: Message, |
55 |
| - metadata: Metadata = [:] |
56 |
| - ) { |
57 |
| - self.metadata = metadata |
58 |
| - self.message = message |
59 |
| - } |
| 44 | + /// Create a new single client request. |
| 45 | + /// |
| 46 | + /// - Parameters: |
| 47 | + /// - message: The message to send to the server. |
| 48 | + /// - metadata: Metadata to send to the server at the start of the request. Defaults to empty. |
| 49 | + public init( |
| 50 | + message: Message, |
| 51 | + metadata: Metadata = [:] |
| 52 | + ) { |
| 53 | + self.metadata = metadata |
| 54 | + self.message = message |
60 | 55 | }
|
61 | 56 | }
|
62 | 57 |
|
63 |
| -extension ClientRequest { |
64 |
| - /// A request created by the client for a stream of messages. |
65 |
| - /// |
66 |
| - /// This is used for client-streaming and bidirectional-streaming RPCs. |
| 58 | +/// A request created by the client for a stream of messages. |
| 59 | +/// |
| 60 | +/// This is used for client-streaming and bidirectional-streaming RPCs. |
| 61 | +/// |
| 62 | +/// See ``ClientRequest`` for single-message requests and ``StreamingServerRequest`` for the |
| 63 | +/// servers representation of a streaming-message request. |
| 64 | +@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) |
| 65 | +public struct StreamingClientRequest<Message: Sendable>: Sendable { |
| 66 | + /// Caller-specified metadata sent to the server at the start of the RPC. |
67 | 67 | ///
|
68 |
| - /// See ``ClientRequest/Single`` for single-message requests and ``ServerRequest/Stream`` for the |
69 |
| - /// servers representation of a streaming-message request. |
70 |
| - @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) |
71 |
| - public struct Stream<Message: Sendable>: Sendable { |
72 |
| - /// Caller-specified metadata sent to the server at the start of the RPC. |
73 |
| - /// |
74 |
| - /// Both gRPC Swift and its transport layer may insert additional metadata. Keys prefixed with |
75 |
| - /// "grpc-" are prohibited and may result in undefined behaviour. Transports may also insert |
76 |
| - /// their own metadata, you should avoid using key names which may clash with transport specific |
77 |
| - /// metadata. Note that transports may also impose limits in the amount of metadata which may |
78 |
| - /// be sent. |
79 |
| - public var metadata: Metadata |
| 68 | + /// Both gRPC Swift and its transport layer may insert additional metadata. Keys prefixed with |
| 69 | + /// "grpc-" are prohibited and may result in undefined behaviour. Transports may also insert |
| 70 | + /// their own metadata, you should avoid using key names which may clash with transport specific |
| 71 | + /// metadata. Note that transports may also impose limits in the amount of metadata which may |
| 72 | + /// be sent. |
| 73 | + public var metadata: Metadata |
80 | 74 |
|
81 |
| - /// A closure which, when called, writes messages in the writer. |
82 |
| - /// |
83 |
| - /// The producer will only be consumed once by gRPC and therefore isn't required to be |
84 |
| - /// idempotent. If the producer throws an error then the RPC will be cancelled. Once the |
85 |
| - /// producer returns the request stream is closed. |
86 |
| - public var producer: @Sendable (RPCWriter<Message>) async throws -> Void |
| 75 | + /// A closure which, when called, writes messages in the writer. |
| 76 | + /// |
| 77 | + /// The producer will only be consumed once by gRPC and therefore isn't required to be |
| 78 | + /// idempotent. If the producer throws an error then the RPC will be cancelled. Once the |
| 79 | + /// producer returns the request stream is closed. |
| 80 | + public var producer: @Sendable (RPCWriter<Message>) async throws -> Void |
87 | 81 |
|
88 |
| - /// Create a new streaming client request. |
89 |
| - /// |
90 |
| - /// - Parameters: |
91 |
| - /// - messageType: The type of message contained in this request, defaults to `Message.self`. |
92 |
| - /// - metadata: Metadata to send to the server at the start of the request. Defaults to empty. |
93 |
| - /// - producer: A closure which writes messages to send to the server. The closure is called |
94 |
| - /// at most once and may not be called. |
95 |
| - public init( |
96 |
| - of messageType: Message.Type = Message.self, |
97 |
| - metadata: Metadata = [:], |
98 |
| - producer: @escaping @Sendable (RPCWriter<Message>) async throws -> Void |
99 |
| - ) { |
100 |
| - self.metadata = metadata |
101 |
| - self.producer = producer |
102 |
| - } |
| 82 | + /// Create a new streaming client request. |
| 83 | + /// |
| 84 | + /// - Parameters: |
| 85 | + /// - messageType: The type of message contained in this request, defaults to `Message.self`. |
| 86 | + /// - metadata: Metadata to send to the server at the start of the request. Defaults to empty. |
| 87 | + /// - producer: A closure which writes messages to send to the server. The closure is called |
| 88 | + /// at most once and may not be called. |
| 89 | + public init( |
| 90 | + of messageType: Message.Type = Message.self, |
| 91 | + metadata: Metadata = [:], |
| 92 | + producer: @escaping @Sendable (RPCWriter<Message>) async throws -> Void |
| 93 | + ) { |
| 94 | + self.metadata = metadata |
| 95 | + self.producer = producer |
103 | 96 | }
|
104 | 97 | }
|
0 commit comments