Skip to content

Commit 062c184

Browse files
committed
words
1 parent e188b98 commit 062c184

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

docs/streams.md

+16-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ gRPC has a `stream` concept that allows client-streaming, server-streaming, and
44
protobuf-net.Grpc, this is typically exposed via the `IAsyncEnumerable<T>` API, which is an asynchronous sequence of messages of type `T`. For example,
55

66
```
7-
public async IAsyncEnumerable<SomeResponse> SomeDuplexMethod(IAsyncEnumerable<SomeRequest> requests)
7+
public async IAsyncEnumerable<SomeResponse> SomeDuplexMethod(
8+
IAsyncEnumerable<SomeRequest> requests)
89
{
910
// very basic request/response server using streaming
1011
await foreach (var req in requests)
@@ -18,25 +19,35 @@ This is *fine*, but .NET has another "stream", i.e. `System.IO.Stream` - a seque
1819

1920
As of 1.2.2, protobuf-net.Grpc has limited (and growing) support for `Stream` as an exchange mechanism. Currently supported scenarios:
2021

21-
- `Task<Stream> SomeMethod(/* optional single request message, optional context/cancellation */);`
22-
- `ValueTask<Stream> SomeMethod(/* optional single request message, optional context/cancellation */);`
22+
- ```
23+
Task<Stream> SomeMethod(/* optional single request message,
24+
optional context/cancellation */);
25+
```
26+
- ```
27+
ValueTask<Stream> SomeMethod(/* optional single request message,
28+
optional context/cancellation */);
29+
```
2330

2431
For example:
2532

2633
``` c#
2734
public async Task<Stream> GetFileContents(SomeRequest request)
2835
{
29-
var localPath = await CheckAccessAndMapToLocalPath(request.Path);
36+
// validation, etc
37+
var localPath = await CheckAccessAndMapToLocalPathAsync(request.Path);
3038

39+
// return an existing .NET Stream, via gRPC
3140
return File.OpenRead(localPath);
3241
}
3342
```
3443

35-
This hands a `Stream` back to the library, with the library assuming control of how to transmit that, disposing the stream when done (as an implementation detail: it
44+
This hands a `Stream` back to the library, with the library assuming control of how to transmit that, disposing the stream when done, and
45+
handling faults in the expected ways (as an implementation detail: it
3646
is sent as a `stream` of [`BytesValue`](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/wrappers.proto) messages,
3747
with bespoke marshalling). As you would expect, the client can access this data trivially:
3848

3949
``` c#
50+
// write Stream data from gRPC server to a local file
4051
await using var data = proxy.GetFileContents(request);
4152
await using var localFile = File.Create(localCachePath);
4253
await data.CopyToAsync(localFile);

0 commit comments

Comments
 (0)