|
|
@ -31,8 +31,6 @@ |
|
|
|
* |
|
|
|
* |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
using namespace std; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "src/compiler/go_generator.h" |
|
|
|
#include "src/compiler/go_generator.h" |
|
|
|
|
|
|
|
|
|
|
|
#include <cctype> |
|
|
|
#include <cctype> |
|
|
@ -42,26 +40,24 @@ using namespace std; |
|
|
|
#include <google/protobuf/descriptor.pb.h> |
|
|
|
#include <google/protobuf/descriptor.pb.h> |
|
|
|
#include <google/protobuf/descriptor.h> |
|
|
|
#include <google/protobuf/descriptor.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using namespace std; |
|
|
|
|
|
|
|
|
|
|
|
namespace grpc_go_generator { |
|
|
|
namespace grpc_go_generator { |
|
|
|
|
|
|
|
|
|
|
|
bool NoStreaming(const google::protobuf::MethodDescriptor* method) { |
|
|
|
bool NoStreaming(const google::protobuf::MethodDescriptor* method) { |
|
|
|
return !method->client_streaming() && |
|
|
|
return !method->client_streaming() && !method->server_streaming(); |
|
|
|
!method->server_streaming(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool ClientOnlyStreaming(const google::protobuf::MethodDescriptor* method) { |
|
|
|
bool ClientOnlyStreaming(const google::protobuf::MethodDescriptor* method) { |
|
|
|
return method->client_streaming() && |
|
|
|
return method->client_streaming() && !method->server_streaming(); |
|
|
|
!method->server_streaming(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool ServerOnlyStreaming(const google::protobuf::MethodDescriptor* method) { |
|
|
|
bool ServerOnlyStreaming(const google::protobuf::MethodDescriptor* method) { |
|
|
|
return !method->client_streaming() && |
|
|
|
return !method->client_streaming() && method->server_streaming(); |
|
|
|
method->server_streaming(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool BidiStreaming(const google::protobuf::MethodDescriptor* method) { |
|
|
|
bool BidiStreaming(const google::protobuf::MethodDescriptor* method) { |
|
|
|
return method->client_streaming() && |
|
|
|
return method->client_streaming() && method->server_streaming(); |
|
|
|
method->server_streaming(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool HasClientOnlyStreaming(const google::protobuf::FileDescriptor* file) { |
|
|
|
bool HasClientOnlyStreaming(const google::protobuf::FileDescriptor* file) { |
|
|
@ -91,20 +87,22 @@ void PrintClientMethodDef(google::protobuf::io::Printer* printer, |
|
|
|
(*vars)["Response"] = method->output_type()->name(); |
|
|
|
(*vars)["Response"] = method->output_type()->name(); |
|
|
|
if (NoStreaming(method)) { |
|
|
|
if (NoStreaming(method)) { |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print(*vars, |
|
|
|
"\t$Method$(ctx context.Context, in *$Request$, opts ...rpc.CallOption) " |
|
|
|
"\t$Method$(ctx context.Context, in *$Request$, opts " |
|
|
|
"(*$Response$, error)\n"); |
|
|
|
"...rpc.CallOption) " |
|
|
|
|
|
|
|
"(*$Response$, error)\n"); |
|
|
|
} else if (BidiStreaming(method)) { |
|
|
|
} else if (BidiStreaming(method)) { |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print(*vars, |
|
|
|
"\t$Method$(ctx context.Context, opts ...rpc.CallOption) " |
|
|
|
"\t$Method$(ctx context.Context, opts ...rpc.CallOption) " |
|
|
|
"($Service$_$Method$Client, error)\n"); |
|
|
|
"($Service$_$Method$Client, error)\n"); |
|
|
|
} else if (ServerOnlyStreaming(method)) { |
|
|
|
} else if (ServerOnlyStreaming(method)) { |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print( |
|
|
|
|
|
|
|
*vars, |
|
|
|
"\t$Method$(ctx context.Context, m *$Request$, opts ...rpc.CallOption) " |
|
|
|
"\t$Method$(ctx context.Context, m *$Request$, opts ...rpc.CallOption) " |
|
|
|
"($Service$_$Method$Client, error)\n"); |
|
|
|
"($Service$_$Method$Client, error)\n"); |
|
|
|
} else if (ClientOnlyStreaming(method)) { |
|
|
|
} else if (ClientOnlyStreaming(method)) { |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print(*vars, |
|
|
|
"\t$Method$(ctx context.Context, opts ...rpc.CallOption) " |
|
|
|
"\t$Method$(ctx context.Context, opts ...rpc.CallOption) " |
|
|
|
"($Service$_$Method$Client, error)\n"); |
|
|
|
"($Service$_$Method$Client, error)\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -116,11 +114,11 @@ void PrintClientMethodImpl(google::protobuf::io::Printer* printer, |
|
|
|
(*vars)["Response"] = method->output_type()->name(); |
|
|
|
(*vars)["Response"] = method->output_type()->name(); |
|
|
|
|
|
|
|
|
|
|
|
if (NoStreaming(method)) { |
|
|
|
if (NoStreaming(method)) { |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print( |
|
|
|
|
|
|
|
*vars, |
|
|
|
"func (c *$ServiceStruct$Client) $Method$(ctx context.Context, " |
|
|
|
"func (c *$ServiceStruct$Client) $Method$(ctx context.Context, " |
|
|
|
"in *$Request$, opts ...rpc.CallOption) (*$Response$, error) {\n"); |
|
|
|
"in *$Request$, opts ...rpc.CallOption) (*$Response$, error) {\n"); |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print(*vars, "\tout := new($Response$)\n"); |
|
|
|
"\tout := new($Response$)\n"); |
|
|
|
|
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print(*vars, |
|
|
|
"\terr := rpc.Invoke(ctx, \"/$Package$$Service$/$Method$\", " |
|
|
|
"\terr := rpc.Invoke(ctx, \"/$Package$$Service$/$Method$\", " |
|
|
|
"in, out, c.cc, opts...)\n"); |
|
|
|
"in, out, c.cc, opts...)\n"); |
|
|
@ -142,20 +140,22 @@ void PrintClientMethodImpl(google::protobuf::io::Printer* printer, |
|
|
|
"\treturn &$ServiceStruct$$Method$Client{stream}, nil\n" |
|
|
|
"\treturn &$ServiceStruct$$Method$Client{stream}, nil\n" |
|
|
|
"}\n\n"); |
|
|
|
"}\n\n"); |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print(*vars, |
|
|
|
"type $Service$_$Method$Client interface {\n" |
|
|
|
"type $Service$_$Method$Client interface {\n" |
|
|
|
"\tSend(*$Request$) error\n" |
|
|
|
"\tSend(*$Request$) error\n" |
|
|
|
"\tRecv() (*$Response$, error)\n" |
|
|
|
"\tRecv() (*$Response$, error)\n" |
|
|
|
"\trpc.ClientStream\n" |
|
|
|
"\trpc.ClientStream\n" |
|
|
|
"}\n\n"); |
|
|
|
"}\n\n"); |
|
|
|
printer->Print(*vars, |
|
|
|
|
|
|
|
"type $ServiceStruct$$Method$Client struct {\n" |
|
|
|
|
|
|
|
"\trpc.ClientStream\n" |
|
|
|
|
|
|
|
"}\n\n"); |
|
|
|
|
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print(*vars, |
|
|
|
|
|
|
|
"type $ServiceStruct$$Method$Client struct {\n" |
|
|
|
|
|
|
|
"\trpc.ClientStream\n" |
|
|
|
|
|
|
|
"}\n\n"); |
|
|
|
|
|
|
|
printer->Print( |
|
|
|
|
|
|
|
*vars, |
|
|
|
"func (x *$ServiceStruct$$Method$Client) Send(m *$Request$) error {\n" |
|
|
|
"func (x *$ServiceStruct$$Method$Client) Send(m *$Request$) error {\n" |
|
|
|
"\treturn x.ClientStream.SendProto(m)\n" |
|
|
|
"\treturn x.ClientStream.SendProto(m)\n" |
|
|
|
"}\n\n"); |
|
|
|
"}\n\n"); |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print( |
|
|
|
|
|
|
|
*vars, |
|
|
|
"func (x *$ServiceStruct$$Method$Client) Recv() (*$Response$, error) " |
|
|
|
"func (x *$ServiceStruct$$Method$Client) Recv() (*$Response$, error) " |
|
|
|
"{\n" |
|
|
|
"{\n" |
|
|
|
"\tm := new($Response$)\n" |
|
|
|
"\tm := new($Response$)\n" |
|
|
@ -185,15 +185,16 @@ void PrintClientMethodImpl(google::protobuf::io::Printer* printer, |
|
|
|
"\treturn x, nil\n" |
|
|
|
"\treturn x, nil\n" |
|
|
|
"}\n\n"); |
|
|
|
"}\n\n"); |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print(*vars, |
|
|
|
"type $Service$_$Method$Client interface {\n" |
|
|
|
"type $Service$_$Method$Client interface {\n" |
|
|
|
"\tRecv() (*$Response$, error)\n" |
|
|
|
"\tRecv() (*$Response$, error)\n" |
|
|
|
"\trpc.ClientStream\n" |
|
|
|
"\trpc.ClientStream\n" |
|
|
|
"}\n\n"); |
|
|
|
"}\n\n"); |
|
|
|
printer->Print(*vars, |
|
|
|
|
|
|
|
"type $ServiceStruct$$Method$Client struct {\n" |
|
|
|
|
|
|
|
"\trpc.ClientStream\n" |
|
|
|
|
|
|
|
"}\n\n"); |
|
|
|
|
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print(*vars, |
|
|
|
|
|
|
|
"type $ServiceStruct$$Method$Client struct {\n" |
|
|
|
|
|
|
|
"\trpc.ClientStream\n" |
|
|
|
|
|
|
|
"}\n\n"); |
|
|
|
|
|
|
|
printer->Print( |
|
|
|
|
|
|
|
*vars, |
|
|
|
"func (x *$ServiceStruct$$Method$Client) Recv() (*$Response$, error) " |
|
|
|
"func (x *$ServiceStruct$$Method$Client) Recv() (*$Response$, error) " |
|
|
|
"{\n" |
|
|
|
"{\n" |
|
|
|
"\tm := new($Response$)\n" |
|
|
|
"\tm := new($Response$)\n" |
|
|
@ -215,20 +216,22 @@ void PrintClientMethodImpl(google::protobuf::io::Printer* printer, |
|
|
|
"\treturn &$ServiceStruct$$Method$Client{stream}, nil\n" |
|
|
|
"\treturn &$ServiceStruct$$Method$Client{stream}, nil\n" |
|
|
|
"}\n\n"); |
|
|
|
"}\n\n"); |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print(*vars, |
|
|
|
"type $Service$_$Method$Client interface {\n" |
|
|
|
"type $Service$_$Method$Client interface {\n" |
|
|
|
"\tSend(*$Request$) error\n" |
|
|
|
"\tSend(*$Request$) error\n" |
|
|
|
"\tCloseAndRecv() (*$Response$, error)\n" |
|
|
|
"\tCloseAndRecv() (*$Response$, error)\n" |
|
|
|
"\trpc.ClientStream\n" |
|
|
|
"\trpc.ClientStream\n" |
|
|
|
"}\n\n"); |
|
|
|
"}\n\n"); |
|
|
|
printer->Print(*vars, |
|
|
|
|
|
|
|
"type $ServiceStruct$$Method$Client struct {\n" |
|
|
|
|
|
|
|
"\trpc.ClientStream\n" |
|
|
|
|
|
|
|
"}\n\n"); |
|
|
|
|
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print(*vars, |
|
|
|
|
|
|
|
"type $ServiceStruct$$Method$Client struct {\n" |
|
|
|
|
|
|
|
"\trpc.ClientStream\n" |
|
|
|
|
|
|
|
"}\n\n"); |
|
|
|
|
|
|
|
printer->Print( |
|
|
|
|
|
|
|
*vars, |
|
|
|
"func (x *$ServiceStruct$$Method$Client) Send(m *$Request$) error {\n" |
|
|
|
"func (x *$ServiceStruct$$Method$Client) Send(m *$Request$) error {\n" |
|
|
|
"\treturn x.ClientStream.SendProto(m)\n" |
|
|
|
"\treturn x.ClientStream.SendProto(m)\n" |
|
|
|
"}\n\n"); |
|
|
|
"}\n\n"); |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print( |
|
|
|
|
|
|
|
*vars, |
|
|
|
"func (x *$ServiceStruct$$Method$Client) CloseAndRecv() (*$Response$, " |
|
|
|
"func (x *$ServiceStruct$$Method$Client) CloseAndRecv() (*$Response$, " |
|
|
|
"error) {\n" |
|
|
|
"error) {\n" |
|
|
|
"\tif err := x.ClientStream.CloseSend(); err != nil {\n" |
|
|
|
"\tif err := x.ClientStream.CloseSend(); err != nil {\n" |
|
|
@ -264,7 +267,8 @@ void PrintClient(google::protobuf::io::Printer* printer, |
|
|
|
"type $ServiceStruct$Client struct {\n" |
|
|
|
"type $ServiceStruct$Client struct {\n" |
|
|
|
"\tcc *rpc.ClientConn\n" |
|
|
|
"\tcc *rpc.ClientConn\n" |
|
|
|
"}\n\n"); |
|
|
|
"}\n\n"); |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print( |
|
|
|
|
|
|
|
*vars, |
|
|
|
"func New$Service$Client(cc *rpc.ClientConn) $Service$Client {\n" |
|
|
|
"func New$Service$Client(cc *rpc.ClientConn) $Service$Client {\n" |
|
|
|
"\treturn &$ServiceStruct$Client{cc}\n" |
|
|
|
"\treturn &$ServiceStruct$Client{cc}\n" |
|
|
|
"}\n\n"); |
|
|
|
"}\n\n"); |
|
|
@ -280,17 +284,16 @@ void PrintServerMethodDef(google::protobuf::io::Printer* printer, |
|
|
|
(*vars)["Request"] = method->input_type()->name(); |
|
|
|
(*vars)["Request"] = method->input_type()->name(); |
|
|
|
(*vars)["Response"] = method->output_type()->name(); |
|
|
|
(*vars)["Response"] = method->output_type()->name(); |
|
|
|
if (NoStreaming(method)) { |
|
|
|
if (NoStreaming(method)) { |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print( |
|
|
|
|
|
|
|
*vars, |
|
|
|
"\t$Method$(context.Context, *$Request$) (*$Response$, error)\n"); |
|
|
|
"\t$Method$(context.Context, *$Request$) (*$Response$, error)\n"); |
|
|
|
} else if (BidiStreaming(method)) { |
|
|
|
} else if (BidiStreaming(method)) { |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print(*vars, "\t$Method$($Service$_$Method$Server) error\n"); |
|
|
|
"\t$Method$($Service$_$Method$Server) error\n"); |
|
|
|
|
|
|
|
} else if (ServerOnlyStreaming(method)) { |
|
|
|
} else if (ServerOnlyStreaming(method)) { |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print(*vars, |
|
|
|
"\t$Method$(*$Request$, $Service$_$Method$Server) error\n"); |
|
|
|
"\t$Method$(*$Request$, $Service$_$Method$Server) error\n"); |
|
|
|
} else if (ClientOnlyStreaming(method)) { |
|
|
|
} else if (ClientOnlyStreaming(method)) { |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print(*vars, "\t$Method$($Service$_$Method$Server) error\n"); |
|
|
|
"\t$Method$($Service$_$Method$Server) error\n"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -301,11 +304,11 @@ void PrintServerHandler(google::protobuf::io::Printer* printer, |
|
|
|
(*vars)["Request"] = method->input_type()->name(); |
|
|
|
(*vars)["Request"] = method->input_type()->name(); |
|
|
|
(*vars)["Response"] = method->output_type()->name(); |
|
|
|
(*vars)["Response"] = method->output_type()->name(); |
|
|
|
if (NoStreaming(method)) { |
|
|
|
if (NoStreaming(method)) { |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print( |
|
|
|
|
|
|
|
*vars, |
|
|
|
"func _$Service$_$Method$_Handler(srv interface{}, ctx context.Context," |
|
|
|
"func _$Service$_$Method$_Handler(srv interface{}, ctx context.Context," |
|
|
|
" buf []byte) (proto.Message, error) {\n"); |
|
|
|
" buf []byte) (proto.Message, error) {\n"); |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print(*vars, "\tin := new($Request$)\n"); |
|
|
|
"\tin := new($Request$)\n"); |
|
|
|
|
|
|
|
printer->Print("\tif err := proto.Unmarshal(buf, in); err != nil {\n"); |
|
|
|
printer->Print("\tif err := proto.Unmarshal(buf, in); err != nil {\n"); |
|
|
|
printer->Print("\t\treturn nil, err\n"); |
|
|
|
printer->Print("\t\treturn nil, err\n"); |
|
|
|
printer->Print("\t}\n"); |
|
|
|
printer->Print("\t}\n"); |
|
|
@ -317,27 +320,30 @@ void PrintServerHandler(google::protobuf::io::Printer* printer, |
|
|
|
printer->Print("\treturn out, nil\n"); |
|
|
|
printer->Print("\treturn out, nil\n"); |
|
|
|
printer->Print("}\n\n"); |
|
|
|
printer->Print("}\n\n"); |
|
|
|
} else if (BidiStreaming(method)) { |
|
|
|
} else if (BidiStreaming(method)) { |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print( |
|
|
|
|
|
|
|
*vars, |
|
|
|
"func _$Service$_$Method$_Handler(srv interface{}, stream rpc.Stream) " |
|
|
|
"func _$Service$_$Method$_Handler(srv interface{}, stream rpc.Stream) " |
|
|
|
"error {\n" |
|
|
|
"error {\n" |
|
|
|
"\treturn srv.($Service$Server).$Method$(&$ServiceStruct$$Method$Server" |
|
|
|
"\treturn srv.($Service$Server).$Method$(&$ServiceStruct$$Method$Server" |
|
|
|
"{stream})\n" |
|
|
|
"{stream})\n" |
|
|
|
"}\n\n"); |
|
|
|
"}\n\n"); |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print(*vars, |
|
|
|
"type $Service$_$Method$Server interface {\n" |
|
|
|
"type $Service$_$Method$Server interface {\n" |
|
|
|
"\tSend(*$Response$) error\n" |
|
|
|
"\tSend(*$Response$) error\n" |
|
|
|
"\tRecv() (*$Request$, error)\n" |
|
|
|
"\tRecv() (*$Request$, error)\n" |
|
|
|
"\trpc.Stream\n" |
|
|
|
"\trpc.Stream\n" |
|
|
|
"}\n\n"); |
|
|
|
"}\n\n"); |
|
|
|
printer->Print(*vars, |
|
|
|
|
|
|
|
"type $ServiceStruct$$Method$Server struct {\n" |
|
|
|
|
|
|
|
"\trpc.Stream\n" |
|
|
|
|
|
|
|
"}\n\n"); |
|
|
|
|
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print(*vars, |
|
|
|
|
|
|
|
"type $ServiceStruct$$Method$Server struct {\n" |
|
|
|
|
|
|
|
"\trpc.Stream\n" |
|
|
|
|
|
|
|
"}\n\n"); |
|
|
|
|
|
|
|
printer->Print( |
|
|
|
|
|
|
|
*vars, |
|
|
|
"func (x *$ServiceStruct$$Method$Server) Send(m *$Response$) error {\n" |
|
|
|
"func (x *$ServiceStruct$$Method$Server) Send(m *$Response$) error {\n" |
|
|
|
"\treturn x.Stream.SendProto(m)\n" |
|
|
|
"\treturn x.Stream.SendProto(m)\n" |
|
|
|
"}\n\n"); |
|
|
|
"}\n\n"); |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print( |
|
|
|
|
|
|
|
*vars, |
|
|
|
"func (x *$ServiceStruct$$Method$Server) Recv() (*$Request$, error) " |
|
|
|
"func (x *$ServiceStruct$$Method$Server) Recv() (*$Request$, error) " |
|
|
|
"{\n" |
|
|
|
"{\n" |
|
|
|
"\tm := new($Request$)\n" |
|
|
|
"\tm := new($Request$)\n" |
|
|
@ -347,7 +353,8 @@ void PrintServerHandler(google::protobuf::io::Printer* printer, |
|
|
|
"\treturn m, nil\n" |
|
|
|
"\treturn m, nil\n" |
|
|
|
"}\n\n"); |
|
|
|
"}\n\n"); |
|
|
|
} else if (ServerOnlyStreaming(method)) { |
|
|
|
} else if (ServerOnlyStreaming(method)) { |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print( |
|
|
|
|
|
|
|
*vars, |
|
|
|
"func _$Service$_$Method$_Handler(srv interface{}, stream rpc.Stream) " |
|
|
|
"func _$Service$_$Method$_Handler(srv interface{}, stream rpc.Stream) " |
|
|
|
"error {\n" |
|
|
|
"error {\n" |
|
|
|
"\tm := new($Request$)\n" |
|
|
|
"\tm := new($Request$)\n" |
|
|
@ -358,36 +365,39 @@ void PrintServerHandler(google::protobuf::io::Printer* printer, |
|
|
|
"&$ServiceStruct$$Method$Server{stream})\n" |
|
|
|
"&$ServiceStruct$$Method$Server{stream})\n" |
|
|
|
"}\n\n"); |
|
|
|
"}\n\n"); |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print(*vars, |
|
|
|
"type $Service$_$Method$Server interface {\n" |
|
|
|
"type $Service$_$Method$Server interface {\n" |
|
|
|
"\tSend(*$Response$) error\n" |
|
|
|
"\tSend(*$Response$) error\n" |
|
|
|
"\trpc.Stream\n" |
|
|
|
"\trpc.Stream\n" |
|
|
|
"}\n\n"); |
|
|
|
"}\n\n"); |
|
|
|
printer->Print(*vars, |
|
|
|
|
|
|
|
"type $ServiceStruct$$Method$Server struct {\n" |
|
|
|
|
|
|
|
"\trpc.Stream\n" |
|
|
|
|
|
|
|
"}\n\n"); |
|
|
|
|
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print(*vars, |
|
|
|
|
|
|
|
"type $ServiceStruct$$Method$Server struct {\n" |
|
|
|
|
|
|
|
"\trpc.Stream\n" |
|
|
|
|
|
|
|
"}\n\n"); |
|
|
|
|
|
|
|
printer->Print( |
|
|
|
|
|
|
|
*vars, |
|
|
|
"func (x *$ServiceStruct$$Method$Server) Send(m *$Response$) error {\n" |
|
|
|
"func (x *$ServiceStruct$$Method$Server) Send(m *$Response$) error {\n" |
|
|
|
"\treturn x.Stream.SendProto(m)\n" |
|
|
|
"\treturn x.Stream.SendProto(m)\n" |
|
|
|
"}\n\n"); |
|
|
|
"}\n\n"); |
|
|
|
} else if (ClientOnlyStreaming(method)) { |
|
|
|
} else if (ClientOnlyStreaming(method)) { |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print( |
|
|
|
|
|
|
|
*vars, |
|
|
|
"func _$Service$_$Method$_Handler(srv interface{}, stream rpc.Stream) " |
|
|
|
"func _$Service$_$Method$_Handler(srv interface{}, stream rpc.Stream) " |
|
|
|
"error {\n" |
|
|
|
"error {\n" |
|
|
|
"\treturn srv.($Service$Server).$Method$(&$ServiceStruct$$Method$Server" |
|
|
|
"\treturn srv.($Service$Server).$Method$(&$ServiceStruct$$Method$Server" |
|
|
|
"{stream})\n" |
|
|
|
"{stream})\n" |
|
|
|
"}\n\n"); |
|
|
|
"}\n\n"); |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print(*vars, |
|
|
|
"type $Service$_$Method$Server interface {\n" |
|
|
|
"type $Service$_$Method$Server interface {\n" |
|
|
|
"\tSendAndClose(*$Response$) error\n" |
|
|
|
"\tSendAndClose(*$Response$) error\n" |
|
|
|
"\tRecv() (*$Request$, error)\n" |
|
|
|
"\tRecv() (*$Request$, error)\n" |
|
|
|
"\trpc.Stream\n" |
|
|
|
"\trpc.Stream\n" |
|
|
|
"}\n\n"); |
|
|
|
"}\n\n"); |
|
|
|
printer->Print(*vars, |
|
|
|
|
|
|
|
"type $ServiceStruct$$Method$Server struct {\n" |
|
|
|
|
|
|
|
"\trpc.Stream\n" |
|
|
|
|
|
|
|
"}\n\n"); |
|
|
|
|
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print(*vars, |
|
|
|
|
|
|
|
"type $ServiceStruct$$Method$Server struct {\n" |
|
|
|
|
|
|
|
"\trpc.Stream\n" |
|
|
|
|
|
|
|
"}\n\n"); |
|
|
|
|
|
|
|
printer->Print( |
|
|
|
|
|
|
|
*vars, |
|
|
|
"func (x *$ServiceStruct$$Method$Server) SendAndClose(m *$Response$) " |
|
|
|
"func (x *$ServiceStruct$$Method$Server) SendAndClose(m *$Response$) " |
|
|
|
"error {\n" |
|
|
|
"error {\n" |
|
|
|
"\tif err := x.Stream.SendProto(m); err != nil {\n" |
|
|
|
"\tif err := x.Stream.SendProto(m); err != nil {\n" |
|
|
@ -395,7 +405,8 @@ void PrintServerHandler(google::protobuf::io::Printer* printer, |
|
|
|
"\t}\n" |
|
|
|
"\t}\n" |
|
|
|
"\treturn nil\n" |
|
|
|
"\treturn nil\n" |
|
|
|
"}\n\n"); |
|
|
|
"}\n\n"); |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print( |
|
|
|
|
|
|
|
*vars, |
|
|
|
"func (x *$ServiceStruct$$Method$Server) Recv() (*$Request$, error) {\n" |
|
|
|
"func (x *$ServiceStruct$$Method$Server) Recv() (*$Request$, error) {\n" |
|
|
|
"\tm := new($Request$)\n" |
|
|
|
"\tm := new($Request$)\n" |
|
|
|
"\tif err := x.Stream.RecvProto(m); err != nil {\n" |
|
|
|
"\tif err := x.Stream.RecvProto(m); err != nil {\n" |
|
|
@ -411,22 +422,19 @@ void PrintServerMethodDesc(google::protobuf::io::Printer* printer, |
|
|
|
map<string, string>* vars) { |
|
|
|
map<string, string>* vars) { |
|
|
|
(*vars)["Method"] = method->name(); |
|
|
|
(*vars)["Method"] = method->name(); |
|
|
|
printer->Print("\t\t{\n"); |
|
|
|
printer->Print("\t\t{\n"); |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print(*vars, "\t\t\tMethodName:\t\"$Method$\",\n"); |
|
|
|
"\t\t\tMethodName:\t\"$Method$\",\n"); |
|
|
|
printer->Print(*vars, "\t\t\tHandler:\t_$Service$_$Method$_Handler,\n"); |
|
|
|
printer->Print(*vars, |
|
|
|
|
|
|
|
"\t\t\tHandler:\t_$Service$_$Method$_Handler,\n"); |
|
|
|
|
|
|
|
printer->Print("\t\t},\n"); |
|
|
|
printer->Print("\t\t},\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PrintServerStreamingMethodDesc(google::protobuf::io::Printer* printer, |
|
|
|
void PrintServerStreamingMethodDesc( |
|
|
|
const google::protobuf::MethodDescriptor* method, |
|
|
|
google::protobuf::io::Printer* printer, |
|
|
|
map<string, string>* vars) { |
|
|
|
const google::protobuf::MethodDescriptor* method, |
|
|
|
|
|
|
|
map<string, string>* vars) { |
|
|
|
(*vars)["Method"] = method->name(); |
|
|
|
(*vars)["Method"] = method->name(); |
|
|
|
printer->Print("\t\t{\n"); |
|
|
|
printer->Print("\t\t{\n"); |
|
|
|
printer->Print(*vars, |
|
|
|
printer->Print(*vars, "\t\t\tStreamName:\t\"$Method$\",\n"); |
|
|
|
"\t\t\tStreamName:\t\"$Method$\",\n"); |
|
|
|
printer->Print(*vars, "\t\t\tHandler:\t_$Service$_$Method$_Handler,\n"); |
|
|
|
printer->Print(*vars, |
|
|
|
|
|
|
|
"\t\t\tHandler:\t_$Service$_$Method$_Handler,\n"); |
|
|
|
|
|
|
|
printer->Print("\t\t},\n"); |
|
|
|
printer->Print("\t\t},\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -467,8 +475,9 @@ void PrintServer(google::protobuf::io::Printer* printer, |
|
|
|
PrintServerStreamingMethodDesc(printer, service->method(i), vars); |
|
|
|
PrintServerStreamingMethodDesc(printer, service->method(i), vars); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
printer->Print("\t},\n" |
|
|
|
printer->Print( |
|
|
|
"}\n\n"); |
|
|
|
"\t},\n" |
|
|
|
|
|
|
|
"}\n\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::string BadToUnderscore(std::string str) { |
|
|
|
std::string BadToUnderscore(std::string str) { |
|
|
@ -493,8 +502,9 @@ string GetServices(const google::protobuf::FileDescriptor* file) { |
|
|
|
printer.Print(vars, "package $PackageName$\n\n"); |
|
|
|
printer.Print(vars, "package $PackageName$\n\n"); |
|
|
|
printer.Print("import (\n"); |
|
|
|
printer.Print("import (\n"); |
|
|
|
if (HasClientOnlyStreaming(file)) { |
|
|
|
if (HasClientOnlyStreaming(file)) { |
|
|
|
printer.Print("\t\"fmt\"\n" |
|
|
|
printer.Print( |
|
|
|
"\t\"io\"\n"); |
|
|
|
"\t\"fmt\"\n" |
|
|
|
|
|
|
|
"\t\"io\"\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
printer.Print( |
|
|
|
printer.Print( |
|
|
|
"\t\"google/net/grpc/go/rpc\"\n" |
|
|
|
"\t\"google/net/grpc/go/rpc\"\n" |
|
|
|