-
Notifications
You must be signed in to change notification settings - Fork 4.6k
protoc-gen-go-grpc: remove use_generic_streams_experimental flag (defaults to true)
#7654
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a2904f1
make generics default
eshitachandwani 73c695a
remove flag from test.sh
eshitachandwani fbc419d
remove flag from test.sh
eshitachandwani afc2779
Merge branch 'grpc:master' into defualt_generics
eshitachandwani 426be38
Removing spaces
eshitachandwani f21e1fa
remove submodule
eshitachandwani 9a16095
test
eshitachandwani df0fdb8
test
eshitachandwani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -178,13 +178,9 @@ func generateFileContent(gen *protogen.Plugin, file *protogen.File, g *protogen. | |
|
|
||
| g.P("// This is a compile-time assertion to ensure that this generated file") | ||
| g.P("// is compatible with the grpc package it is being compiled against.") | ||
| if *useGenericStreams { | ||
| g.P("// Requires gRPC-Go v1.64.0 or later.") | ||
| g.P("const _ = ", grpcPackage.Ident("SupportPackageIsVersion9")) | ||
| } else { | ||
| g.P("// Requires gRPC-Go v1.62.0 or later.") | ||
| g.P("const _ = ", grpcPackage.Ident("SupportPackageIsVersion8")) // When changing, update version number above. | ||
| } | ||
| g.P("// Requires gRPC-Go v1.64.0 or later.") | ||
| g.P("const _ = ", grpcPackage.Ident("SupportPackageIsVersion9")) | ||
|
|
||
| g.P() | ||
| for _, service := range file.Services { | ||
| genService(gen, file, g, service) | ||
|
|
@@ -333,11 +329,9 @@ func clientSignature(g *protogen.GeneratedFile, method *protogen.Method) string | |
| if !method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() { | ||
| s += "*" + g.QualifiedGoIdent(method.Output.GoIdent) | ||
| } else { | ||
| if *useGenericStreams { | ||
| s += clientStreamInterface(g, method) | ||
| } else { | ||
| s += method.Parent.GoName + "_" + method.GoName + "Client" | ||
| } | ||
|
|
||
|
||
| s += clientStreamInterface(g, method) | ||
|
|
||
| } | ||
| s += ", error)" | ||
| return s | ||
|
|
@@ -373,11 +367,8 @@ func genClientMethod(_ *protogen.Plugin, _ *protogen.File, g *protogen.Generated | |
| return | ||
| } | ||
|
|
||
| streamImpl := unexport(service.GoName) + method.GoName + "Client" | ||
| if *useGenericStreams { | ||
| typeParam := g.QualifiedGoIdent(method.Input.GoIdent) + ", " + g.QualifiedGoIdent(method.Output.GoIdent) | ||
| streamImpl = g.QualifiedGoIdent(grpcPackage.Ident("GenericClientStream")) + "[" + typeParam + "]" | ||
| } | ||
| typeParam := g.QualifiedGoIdent(method.Input.GoIdent) + ", " + g.QualifiedGoIdent(method.Output.GoIdent) | ||
| streamImpl := g.QualifiedGoIdent(grpcPackage.Ident("GenericClientStream")) + "[" + typeParam + "]" | ||
|
|
||
| serviceDescVar := service.GoName + "_ServiceDesc" | ||
| g.P("stream, err := c.cc.NewStream(ctx, &", serviceDescVar, ".Streams[", index, `], `, fmSymbol, `, cOpts...)`) | ||
|
|
@@ -392,61 +383,9 @@ func genClientMethod(_ *protogen.Plugin, _ *protogen.File, g *protogen.Generated | |
| g.P() | ||
|
|
||
| // Auxiliary types aliases, for backwards compatibility. | ||
| if *useGenericStreams { | ||
| g.P("// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.") | ||
| g.P("type ", service.GoName, "_", method.GoName, "Client = ", clientStreamInterface(g, method)) | ||
| g.P() | ||
| return | ||
| } | ||
|
|
||
| // Stream auxiliary types and methods, if we're not taking advantage of the | ||
| // pre-implemented generic types and their methods. | ||
| genSend := method.Desc.IsStreamingClient() | ||
| genRecv := method.Desc.IsStreamingServer() | ||
| genCloseAndRecv := !method.Desc.IsStreamingServer() | ||
|
|
||
| g.P("type ", service.GoName, "_", method.GoName, "Client interface {") | ||
| if genSend { | ||
| g.P("Send(*", method.Input.GoIdent, ") error") | ||
| } | ||
| if genRecv { | ||
| g.P("Recv() (*", method.Output.GoIdent, ", error)") | ||
| } | ||
| if genCloseAndRecv { | ||
| g.P("CloseAndRecv() (*", method.Output.GoIdent, ", error)") | ||
| } | ||
| g.P(grpcPackage.Ident("ClientStream")) | ||
| g.P("}") | ||
| g.P() | ||
|
|
||
| g.P("type ", streamImpl, " struct {") | ||
| g.P(grpcPackage.Ident("ClientStream")) | ||
| g.P("}") | ||
| g.P("// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.") | ||
| g.P("type ", service.GoName, "_", method.GoName, "Client = ", clientStreamInterface(g, method)) | ||
| g.P() | ||
|
|
||
| if genSend { | ||
| g.P("func (x *", streamImpl, ") Send(m *", method.Input.GoIdent, ") error {") | ||
| g.P("return x.ClientStream.SendMsg(m)") | ||
| g.P("}") | ||
| g.P() | ||
| } | ||
| if genRecv { | ||
| g.P("func (x *", streamImpl, ") Recv() (*", method.Output.GoIdent, ", error) {") | ||
| g.P("m := new(", method.Output.GoIdent, ")") | ||
| g.P("if err := x.ClientStream.RecvMsg(m); err != nil { return nil, err }") | ||
| g.P("return m, nil") | ||
| g.P("}") | ||
| g.P() | ||
| } | ||
| if genCloseAndRecv { | ||
| g.P("func (x *", streamImpl, ") CloseAndRecv() (*", method.Output.GoIdent, ", error) {") | ||
| g.P("if err := x.ClientStream.CloseSend(); err != nil { return nil, err }") | ||
| g.P("m := new(", method.Output.GoIdent, ")") | ||
| g.P("if err := x.ClientStream.RecvMsg(m); err != nil { return nil, err }") | ||
| g.P("return m, nil") | ||
| g.P("}") | ||
| g.P() | ||
| } | ||
| } | ||
|
|
||
| func serverSignature(g *protogen.GeneratedFile, method *protogen.Method) string { | ||
|
|
@@ -460,11 +399,8 @@ func serverSignature(g *protogen.GeneratedFile, method *protogen.Method) string | |
| reqArgs = append(reqArgs, "*"+g.QualifiedGoIdent(method.Input.GoIdent)) | ||
| } | ||
| if method.Desc.IsStreamingClient() || method.Desc.IsStreamingServer() { | ||
| if *useGenericStreams { | ||
| reqArgs = append(reqArgs, serverStreamInterface(g, method)) | ||
| } else { | ||
| reqArgs = append(reqArgs, method.Parent.GoName+"_"+method.GoName+"Server") | ||
| } | ||
| reqArgs = append(reqArgs, serverStreamInterface(g, method)) | ||
|
|
||
arvindbr8 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| return method.GoName + "(" + strings.Join(reqArgs, ", ") + ") " + ret | ||
| } | ||
|
|
@@ -545,11 +481,8 @@ func genServerMethod(_ *protogen.Plugin, _ *protogen.File, g *protogen.Generated | |
| return hname | ||
| } | ||
|
|
||
| streamImpl := unexport(service.GoName) + method.GoName + "Server" | ||
| if *useGenericStreams { | ||
| typeParam := g.QualifiedGoIdent(method.Input.GoIdent) + ", " + g.QualifiedGoIdent(method.Output.GoIdent) | ||
| streamImpl = g.QualifiedGoIdent(grpcPackage.Ident("GenericServerStream")) + "[" + typeParam + "]" | ||
| } | ||
| typeParam := g.QualifiedGoIdent(method.Input.GoIdent) + ", " + g.QualifiedGoIdent(method.Output.GoIdent) | ||
| streamImpl := g.QualifiedGoIdent(grpcPackage.Ident("GenericServerStream")) + "[" + typeParam + "]" | ||
|
|
||
| g.P("func ", hnameFuncNameFormatter(hname), "(srv interface{}, stream ", grpcPackage.Ident("ServerStream"), ") error {") | ||
| if !method.Desc.IsStreamingClient() { | ||
|
|
@@ -563,59 +496,9 @@ func genServerMethod(_ *protogen.Plugin, _ *protogen.File, g *protogen.Generated | |
| g.P() | ||
|
|
||
| // Auxiliary types aliases, for backwards compatibility. | ||
| if *useGenericStreams { | ||
| g.P("// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.") | ||
| g.P("type ", service.GoName, "_", method.GoName, "Server = ", serverStreamInterface(g, method)) | ||
| g.P() | ||
| return hname | ||
| } | ||
|
|
||
| // Stream auxiliary types and methods, if we're not taking advantage of the | ||
| // pre-implemented generic types and their methods. | ||
| genSend := method.Desc.IsStreamingServer() | ||
| genSendAndClose := !method.Desc.IsStreamingServer() | ||
| genRecv := method.Desc.IsStreamingClient() | ||
|
|
||
| g.P("type ", service.GoName, "_", method.GoName, "Server interface {") | ||
| if genSend { | ||
| g.P("Send(*", method.Output.GoIdent, ") error") | ||
| } | ||
| if genSendAndClose { | ||
| g.P("SendAndClose(*", method.Output.GoIdent, ") error") | ||
| } | ||
| if genRecv { | ||
| g.P("Recv() (*", method.Input.GoIdent, ", error)") | ||
| } | ||
| g.P(grpcPackage.Ident("ServerStream")) | ||
| g.P("}") | ||
| g.P("// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.") | ||
| g.P("type ", service.GoName, "_", method.GoName, "Server = ", serverStreamInterface(g, method)) | ||
| g.P() | ||
|
|
||
| g.P("type ", streamImpl, " struct {") | ||
| g.P(grpcPackage.Ident("ServerStream")) | ||
| g.P("}") | ||
| g.P() | ||
|
|
||
| if genSend { | ||
| g.P("func (x *", streamImpl, ") Send(m *", method.Output.GoIdent, ") error {") | ||
| g.P("return x.ServerStream.SendMsg(m)") | ||
| g.P("}") | ||
| g.P() | ||
| } | ||
| if genSendAndClose { | ||
| g.P("func (x *", streamImpl, ") SendAndClose(m *", method.Output.GoIdent, ") error {") | ||
| g.P("return x.ServerStream.SendMsg(m)") | ||
| g.P("}") | ||
| g.P() | ||
| } | ||
| if genRecv { | ||
| g.P("func (x *", streamImpl, ") Recv() (*", method.Input.GoIdent, ", error) {") | ||
| g.P("m := new(", method.Input.GoIdent, ")") | ||
| g.P("if err := x.ServerStream.RecvMsg(m); err != nil { return nil, err }") | ||
| g.P("return m, nil") | ||
| g.P("}") | ||
| g.P() | ||
| } | ||
|
|
||
| return hname | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.