Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generated-code: update to include stream generics #1365

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

eshitachandwani
Copy link
Member

@eshitachandwani eshitachandwani commented Sep 25, 2024

Fixes task 3 : grpc-go issue #1894 - update the grpc.io docs to use generics instead of generated interfaces.

@eshitachandwani
Copy link
Member Author

Cannot add reviewer, @purnesh42H please review

@murgatroid99
Copy link
Member

@ejona86 can you take a look at this?

Copy link
Contributor

@purnesh42H purnesh42H left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Contributor

@purnesh42H purnesh42H left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to cross check here if we need to edit/add anything as we recently updated this https://github.com/grpc/grpc-go/blob/00b9e140ce71480ee7ecc6b85317021e0fe11fbb/stream_interfaces.go#L21

messages from the client. `Recv` returns `(nil, io.EOF)` once it has reached the end of the stream.
The single response message from the server is sent by calling the `SendAndClose` method on this `<ServiceName>_FooServer` parameter.
Note that `SendAndClose` must be called once and only once.
The `grpc.ClientStreamingServer` has two methods `Recv()` and `SendAndClose(*MsgB)` , has an embedded `ServerStream`. The server-side handler can repeatedly call `Recv` on `<ServiceName>_FooServer` in order to receive the full stream of messages from the client. `Recv` returns `(nil, io.EOF)` once it has reached the end of the stream. The single response message from the server is sent by calling the `SendAndClose` method on this `<ServiceName>_FooServer` parameter. Note that `SendAndClose` must be called once and only once.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SendAndClose(*MsgB) , -> SendAndClose(*MsgB),

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


In this context, `<ServiceName>_FooClient` represents the server-to-client `stream` of `MsgB` messages.
In this context, `grpc.ServerStreamClient` represents the client side of server-to-client stream of `MsgB` messages.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like there is extra space after grpc.ServerStreamClient

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@dfawley dfawley changed the title genetared-code : updating to include stream generics generated-code: update to include stream generics Oct 14, 2024
Copy link
Member

@dfawley dfawley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please apply the comments throughout, and please review your changes for correctness in light of all the typos. Thanks!


`Foo(*MsgA, <ServiceName>_FooServer) error`
In this context, `MsgA` is the single request from the client, and , and `grpc.ServerStreamingServer` represents the server side of server-to-client stream of response type `MsgB`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also an extra space in the server side

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

of `MsgB` messages.

`<ServiceName>_FooServer` has an embedded `grpc.ServerStream` and the following interface:
`<ServiceName>_FooServer` has a `grpc.SreverStreamingServer` interface that takes `MsgB` i.e. the response type as the input:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Srever -> Server

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

of `MsgB` messages.

`<ServiceName>_FooServer` has an embedded `grpc.ServerStream` and the following interface:
`<ServiceName>_FooServer` has a `grpc.SreverStreamingServer` interface that takes `MsgB` i.e. the response type as the input:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar: please use commas:

MsgB, i.e. the response type, as the input.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

```

The server-side handler can send a stream of protobuf messages to the client through this parameter's `Send` method. End-of-stream for the server-to-client
stream is caused by the `return` of the handler method.
The `grpc.SreverStreamingServer` has a `Send(*MsgB)` method and has `ServerStream` embedded in it.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Send(*MsgB) error
grpc.ServerStream
}
type <ServiceName>_FooServer = grpc.ServerStreamingServer[*MsgB]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put documentation for the ServerStreamingServer here instead and leave out this leftover type alias, which is only there for backward compatibility. We can probably rely heavily on the existing documentation, or maybe even just link it: https://pkg.go.dev/google.golang.org/grpc#ServerStreamingServer


`<ServiceName>_FooClient` has an embedded `grpc.ClientStream` and the following interface:
`<ServiceName>_FooServe`r has a `grpc.ClientStreamingClient` interface that takes `MsgA` and `MsgB` as input:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants