@@ -22,15 +22,35 @@ package grpc
22
22
// request, many responses) RPC. It is generic over the type of the response
23
23
// message. It is used in generated code.
24
24
type ServerStreamingClient [Res any ] interface {
25
+ // Recv receives the next response message from the server. The client may
26
+ // repeatedly call Recv to read messages from the response stream. If
27
+ // io.EOF is returned, the stream has terminated with an OK status. Any
28
+ // other error is compatible with the status package and indicates the
29
+ // RPC's status code and message.
25
30
Recv () (* Res , error )
31
+
32
+ // ClientStream is embedded to provide Context, Header, and Trailer
33
+ // functionality. No other methods in the ClientStream should be called
34
+ // directly.
26
35
ClientStream
27
36
}
28
37
29
38
// ServerStreamingServer represents the server side of a server-streaming (one
30
39
// request, many responses) RPC. It is generic over the type of the response
31
40
// message. It is used in generated code.
41
+ //
42
+ // To terminate the response stream, return from the handler method and return
43
+ // an error from the status package, or use nil to indicate an OK status code.
32
44
type ServerStreamingServer [Res any ] interface {
45
+ // Send sends a response message to the client. The server handler may
46
+ // call Send multiple times to send multiple messages to the client. An
47
+ // error is returned if the stream was terminated unexpectedly, and the
48
+ // handler method should return, as the stream is no longer usable.
33
49
Send (* Res ) error
50
+
51
+ // ServerStream is embedded to provide Context, SetHeader, SendHeader, and
52
+ // SetTrailer functionality. No other methods in the ServerStream should
53
+ // be called directly.
34
54
ServerStream
35
55
}
36
56
@@ -39,18 +59,51 @@ type ServerStreamingServer[Res any] interface {
39
59
// message stream and the type of the unary response message. It is used in
40
60
// generated code.
41
61
type ClientStreamingClient [Req any , Res any ] interface {
62
+ // Send sends a request message to the server. The client may call Send
63
+ // multiple times to send multiple messages to the server. On error, Send
64
+ // aborts the stream. If the error was generated by the client, the status
65
+ // is returned directly. Otherwise, io.EOF is returned, and the status of
66
+ // the stream may be discovered using CloseAndRecv().
42
67
Send (* Req ) error
68
+
69
+ // CloseAndRecv closes the request stream and waits for the server's
70
+ // response. This method must be called once and only once after sending
71
+ // all request messages. Any error returned is implemented by the status
72
+ // package.
43
73
CloseAndRecv () (* Res , error )
74
+
75
+ // ClientStream is embedded to provide Context, Header, and Trailer
76
+ // functionality. No other methods in the ClientStream should be called
77
+ // directly.
44
78
ClientStream
45
79
}
46
80
47
81
// ClientStreamingServer represents the server side of a client-streaming (many
48
82
// requests, one response) RPC. It is generic over both the type of the request
49
83
// message stream and the type of the unary response message. It is used in
50
84
// generated code.
85
+ //
86
+ // To terminate the RPC, call SendAndClose and return nil from the method
87
+ // handler or do not call SendAndClose and return an error from the status
88
+ // package.
51
89
type ClientStreamingServer [Req any , Res any ] interface {
90
+ // Recv receives the next request message from the client. The server may
91
+ // repeatedly call Recv to read messages from the request stream. If
92
+ // io.EOF is returned, it indicates the client called CloseAndRecv on its
93
+ // ClientStreamingClient. Any other error indicates the stream was
94
+ // terminated unexpectedly, and the handler method should return, as the
95
+ // stream is no longer usable.
52
96
Recv () (* Req , error )
97
+
98
+ // SendAndClose sends a single response message to the client and closes
99
+ // the stream. This method must be called once and only once after all
100
+ // request messages have been processed. Recv should not be called after
101
+ // calling SendAndClose.
53
102
SendAndClose (* Res ) error
103
+
104
+ // ServerStream is embedded to provide Context, SetHeader, SendHeader, and
105
+ // SetTrailer functionality. No other methods in the ServerStream should
106
+ // be called directly.
54
107
ServerStream
55
108
}
56
109
@@ -59,18 +112,51 @@ type ClientStreamingServer[Req any, Res any] interface {
59
112
// request message stream and the type of the response message stream. It is
60
113
// used in generated code.
61
114
type BidiStreamingClient [Req any , Res any ] interface {
115
+ // Send sends a request message to the server. The client may call Send
116
+ // multiple times to send multiple messages to the server. On error, Send
117
+ // aborts the stream. If the error was generated by the client, the status
118
+ // is returned directly. Otherwise, io.EOF is returned, and the status of
119
+ // the stream may be discovered using Recv().
62
120
Send (* Req ) error
121
+
122
+ // Recv receives the next response message from the server. The client may
123
+ // repeatedly call Recv to read messages from the response stream. If
124
+ // io.EOF is returned, the stream has terminated with an OK status. Any
125
+ // other error is compatible with the status package and indicates the
126
+ // RPC's status code and message.
63
127
Recv () (* Res , error )
128
+
129
+ // ClientStream is embedded to provide Context, Header, Trailer, and
130
+ // CloseSend functionality. No other methods in the ClientStream should be
131
+ // called directly.
64
132
ClientStream
65
133
}
66
134
67
135
// BidiStreamingServer represents the server side of a bidirectional-streaming
68
136
// (many requests, many responses) RPC. It is generic over both the type of the
69
137
// request message stream and the type of the response message stream. It is
70
138
// used in generated code.
139
+ //
140
+ // To terminate the stream, return from the handler method and return
141
+ // an error from the status package, or use nil to indicate an OK status code.
71
142
type BidiStreamingServer [Req any , Res any ] interface {
143
+ // Recv receives the next request message from the client. The server may
144
+ // repeatedly call Recv to read messages from the request stream. If
145
+ // io.EOF is returned, it indicates the client called CloseSend on its
146
+ // BidiStreamingClient. Any other error indicates the stream was
147
+ // terminated unexpectedly, and the handler method should return, as the
148
+ // stream is no longer usable.
72
149
Recv () (* Req , error )
150
+
151
+ // Send sends a response message to the client. The server handler may
152
+ // call Send multiple times to send multiple messages to the client. An
153
+ // error is returned if the stream was terminated unexpectedly, and the
154
+ // handler method should return, as the stream is no longer usable.
73
155
Send (* Res ) error
156
+
157
+ // ServerStream is embedded to provide Context, SetHeader, SendHeader, and
158
+ // SetTrailer functionality. No other methods in the ServerStream should
159
+ // be called directly.
74
160
ServerStream
75
161
}
76
162
0 commit comments