mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-29 13:42:00 +00:00
C++/Go: Update gRPC related code to work with gRPC 1.3+ (#4305)
* Don't fail the build on unused parameters gRPC headers have unused parameters so this breaks the test build. * Pull in updated compiler files from gRPC There have been some API breaks in gRPC lately. This commit pulls in the most recent version of the files in this repo that are just copied from gRPC. * Modify the gRPC files so that they can work with Flatbuffers The files taken from gRPC do not work out-of-the-box with Flatbuffers. This commit modifies them so that they work. Hopefully this commit will be able to serve as a guide or maybe even be cherry-picked on top of new versions of those files as newer versions from gRPC are pulled in. * Adjust the rest of Flatbuffers to work with the new gRPC * Change idl_gen_grpc.cpp to work with the new API * Add missing #include in flatbuffers/grpc.h * Run tests/generate_code.sh and check in the results * Don't link with grpc++_unsecure and (secure) grpc. That's just weird * Revert unrelated JS/TS test changes * Simplify compiler/config.h There is no need to import this file from gRPC. In fact, it probably makes sense to not do so, since it seems to be intended to have project specific configuration in it. * Don't emit C++ types in the Go gRPC code generator * Don't emit C++ #includes in generated gRPC code Before this PR, there was a Go-specific additional_includes method in schema_interface.h, which is shared with the gRPC repo. The additional parameter to FlatBufFile in idl_gen_grpc.cpp makes that unnecessary, which means we need less Flatbuffer-specific changes in gRPC.
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
c7bfe06c54
commit
9aeeddf5ac
@@ -102,7 +102,7 @@ if(EXISTS "${CMAKE_TOOLCHAIN_FILE}")
|
|||||||
# is being configured externally
|
# is being configured externally
|
||||||
elseif(APPLE)
|
elseif(APPLE)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Wno-unused-parameter")
|
||||||
elseif(CMAKE_COMPILER_IS_GNUCXX)
|
elseif(CMAKE_COMPILER_IS_GNUCXX)
|
||||||
if(CYGWIN)
|
if(CYGWIN)
|
||||||
set(CMAKE_CXX_FLAGS
|
set(CMAKE_CXX_FLAGS
|
||||||
@@ -127,7 +127,7 @@ elseif(CMAKE_COMPILER_IS_GNUCXX)
|
|||||||
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
|
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
|
||||||
set(CMAKE_CXX_FLAGS
|
set(CMAKE_CXX_FLAGS
|
||||||
"${CMAKE_CXX_FLAGS} -std=c++0x -Wall -pedantic -Werror \
|
"${CMAKE_CXX_FLAGS} -std=c++0x -Wall -pedantic -Werror \
|
||||||
-Wextra")
|
-Wextra -Wno-unused-parameter")
|
||||||
if(NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
|
if(NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
|
||||||
set(CMAKE_CXX_FLAGS
|
set(CMAKE_CXX_FLAGS
|
||||||
"${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
"${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
||||||
@@ -228,7 +228,7 @@ if(FLATBUFFERS_BUILD_GRPCTEST)
|
|||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter")
|
||||||
endif()
|
endif()
|
||||||
add_executable(grpctest ${FlatBuffers_GRPCTest_SRCS})
|
add_executable(grpctest ${FlatBuffers_GRPCTest_SRCS})
|
||||||
target_link_libraries(grpctest grpc++_unsecure grpc pthread dl)
|
target_link_libraries(grpctest grpc++_unsecure pthread dl)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(FLATBUFFERS_INSTALL)
|
if(FLATBUFFERS_INSTALL)
|
||||||
|
|||||||
40
grpc/src/compiler/config.h
Normal file
40
grpc/src/compiler/config.h
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2015, Google Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of Google Inc. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SRC_COMPILER_CONFIG_H
|
||||||
|
#define SRC_COMPILER_CONFIG_H
|
||||||
|
|
||||||
|
// This file is here only because schema_interface.h, which is copied from gRPC,
|
||||||
|
// includes it. There is nothing for Flatbuffers to configure.
|
||||||
|
|
||||||
|
#endif // SRC_COMPILER_CONFIG_H
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -41,8 +41,20 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "src/compiler/config.h"
|
||||||
#include "src/compiler/schema_interface.h"
|
#include "src/compiler/schema_interface.h"
|
||||||
|
|
||||||
|
#ifndef GRPC_CUSTOM_STRING
|
||||||
|
#include <string>
|
||||||
|
#define GRPC_CUSTOM_STRING std::string
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace grpc {
|
||||||
|
|
||||||
|
typedef GRPC_CUSTOM_STRING string;
|
||||||
|
|
||||||
|
} // namespace grpc
|
||||||
|
|
||||||
namespace grpc_cpp_generator {
|
namespace grpc_cpp_generator {
|
||||||
|
|
||||||
// Contains all the parameters that are parsed from the command line.
|
// Contains all the parameters that are parsed from the command line.
|
||||||
@@ -53,31 +65,73 @@ struct Parameters {
|
|||||||
bool use_system_headers;
|
bool use_system_headers;
|
||||||
// Prefix to any grpc include
|
// Prefix to any grpc include
|
||||||
grpc::string grpc_search_path;
|
grpc::string grpc_search_path;
|
||||||
|
// Generate GMOCK code to facilitate unit testing.
|
||||||
|
bool generate_mock_code;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Return the prologue of the generated header file.
|
// Return the prologue of the generated header file.
|
||||||
grpc::string GetHeaderPrologue(grpc_generator::File *file, const Parameters ¶ms);
|
grpc::string GetHeaderPrologue(grpc_generator::File *file,
|
||||||
|
const Parameters ¶ms);
|
||||||
|
|
||||||
// Return the includes needed for generated header file.
|
// Return the includes needed for generated header file.
|
||||||
grpc::string GetHeaderIncludes(grpc_generator::File *file, const Parameters ¶ms);
|
grpc::string GetHeaderIncludes(grpc_generator::File *file,
|
||||||
|
const Parameters ¶ms);
|
||||||
|
|
||||||
// Return the includes needed for generated source file.
|
// Return the includes needed for generated source file.
|
||||||
grpc::string GetSourceIncludes(grpc_generator::File *file, const Parameters ¶ms);
|
grpc::string GetSourceIncludes(grpc_generator::File *file,
|
||||||
|
const Parameters ¶ms);
|
||||||
|
|
||||||
// Return the epilogue of the generated header file.
|
// Return the epilogue of the generated header file.
|
||||||
grpc::string GetHeaderEpilogue(grpc_generator::File *file, const Parameters ¶ms);
|
grpc::string GetHeaderEpilogue(grpc_generator::File *file,
|
||||||
|
const Parameters ¶ms);
|
||||||
|
|
||||||
// Return the prologue of the generated source file.
|
// Return the prologue of the generated source file.
|
||||||
grpc::string GetSourcePrologue(grpc_generator::File *file, const Parameters ¶ms);
|
grpc::string GetSourcePrologue(grpc_generator::File *file,
|
||||||
|
const Parameters ¶ms);
|
||||||
|
|
||||||
// Return the services for generated header file.
|
// Return the services for generated header file.
|
||||||
grpc::string GetHeaderServices(grpc_generator::File *file, const Parameters ¶ms);
|
grpc::string GetHeaderServices(grpc_generator::File *file,
|
||||||
|
const Parameters ¶ms);
|
||||||
|
|
||||||
// Return the services for generated source file.
|
// Return the services for generated source file.
|
||||||
grpc::string GetSourceServices(grpc_generator::File *file, const Parameters ¶ms);
|
grpc::string GetSourceServices(grpc_generator::File *file,
|
||||||
|
const Parameters ¶ms);
|
||||||
|
|
||||||
// Return the epilogue of the generated source file.
|
// Return the epilogue of the generated source file.
|
||||||
grpc::string GetSourceEpilogue(grpc_generator::File *file, const Parameters ¶ms);
|
grpc::string GetSourceEpilogue(grpc_generator::File *file,
|
||||||
|
const Parameters ¶ms);
|
||||||
|
|
||||||
|
// Return the prologue of the generated mock file.
|
||||||
|
grpc::string GetMockPrologue(grpc_generator::File *file,
|
||||||
|
const Parameters ¶ms);
|
||||||
|
|
||||||
|
// Return the includes needed for generated mock file.
|
||||||
|
grpc::string GetMockIncludes(grpc_generator::File *file,
|
||||||
|
const Parameters ¶ms);
|
||||||
|
|
||||||
|
// Return the services for generated mock file.
|
||||||
|
grpc::string GetMockServices(grpc_generator::File *file,
|
||||||
|
const Parameters ¶ms);
|
||||||
|
|
||||||
|
// Return the epilogue of generated mock file.
|
||||||
|
grpc::string GetMockEpilogue(grpc_generator::File *file,
|
||||||
|
const Parameters ¶ms);
|
||||||
|
|
||||||
|
// Return the prologue of the generated mock file.
|
||||||
|
grpc::string GetMockPrologue(grpc_generator::File *file,
|
||||||
|
const Parameters ¶ms);
|
||||||
|
|
||||||
|
// Return the includes needed for generated mock file.
|
||||||
|
grpc::string GetMockIncludes(grpc_generator::File *file,
|
||||||
|
const Parameters ¶ms);
|
||||||
|
|
||||||
|
// Return the services for generated mock file.
|
||||||
|
grpc::string GetMockServices(grpc_generator::File *file,
|
||||||
|
const Parameters ¶ms);
|
||||||
|
|
||||||
|
// Return the epilogue of generated mock file.
|
||||||
|
grpc::string GetMockEpilogue(grpc_generator::File *file,
|
||||||
|
const Parameters ¶ms);
|
||||||
|
|
||||||
} // namespace grpc_cpp_generator
|
} // namespace grpc_cpp_generator
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,14 @@ grpc::string as_string(T x) {
|
|||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool ClientOnlyStreaming(const grpc_generator::Method *method) {
|
||||||
|
return method->ClientStreaming() && !method->ServerStreaming();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool ServerOnlyStreaming(const grpc_generator::Method *method) {
|
||||||
|
return !method->ClientStreaming() && method->ServerStreaming();
|
||||||
|
}
|
||||||
|
|
||||||
namespace grpc_go_generator {
|
namespace grpc_go_generator {
|
||||||
|
|
||||||
// Returns string with first letter to lowerCase
|
// Returns string with first letter to lowerCase
|
||||||
@@ -70,8 +78,8 @@ void GenerateImports(grpc_generator::File *file, grpc_generator::Printer *printe
|
|||||||
printer->Print("//If you make any local changes, they will be lost\n");
|
printer->Print("//If you make any local changes, they will be lost\n");
|
||||||
printer->Print(vars, "//source: $filename$\n\n");
|
printer->Print(vars, "//source: $filename$\n\n");
|
||||||
printer->Print(vars, "package $Package$\n\n");
|
printer->Print(vars, "package $Package$\n\n");
|
||||||
if (file->additional_imports() != "") {
|
if (file->additional_headers() != "") {
|
||||||
printer->Print(file->additional_imports().c_str());
|
printer->Print(file->additional_headers().c_str());
|
||||||
printer->Print("\n\n");
|
printer->Print("\n\n");
|
||||||
}
|
}
|
||||||
printer->Print("import (\n");
|
printer->Print("import (\n");
|
||||||
@@ -86,11 +94,11 @@ void GenerateImports(grpc_generator::File *file, grpc_generator::Printer *printe
|
|||||||
void GenerateServerMethodSignature(const grpc_generator::Method *method, grpc_generator::Printer *printer,
|
void GenerateServerMethodSignature(const grpc_generator::Method *method, grpc_generator::Printer *printer,
|
||||||
std::map<grpc::string, grpc::string> vars) {
|
std::map<grpc::string, grpc::string> vars) {
|
||||||
vars["Method"] = exportName(method->name());
|
vars["Method"] = exportName(method->name());
|
||||||
vars["Request"] = method->input_name();
|
vars["Request"] = method->get_input_type_name();
|
||||||
vars["Response"] = (vars["CustomMethodIO"] == "") ? method->output_name() : vars["CustomMethodIO"];
|
vars["Response"] = (vars["CustomMethodIO"] == "") ? method->get_output_type_name() : vars["CustomMethodIO"];
|
||||||
if (method->NoStreaming()) {
|
if (method->NoStreaming()) {
|
||||||
printer->Print(vars, "$Method$($context$.Context, *$Request$) (*$Response$, error)");
|
printer->Print(vars, "$Method$($context$.Context, *$Request$) (*$Response$, error)");
|
||||||
} else if (method->ServerOnlyStreaming()) {
|
} else if (ServerOnlyStreaming(method)) {
|
||||||
printer->Print(vars, "$Method$(*$Request$, $Service$_$Method$Server) error");
|
printer->Print(vars, "$Method$(*$Request$, $Service$_$Method$Server) error");
|
||||||
} else {
|
} else {
|
||||||
printer->Print(vars, "$Method$($Service$_$Method$Server) error");
|
printer->Print(vars, "$Method$($Service$_$Method$Server) error");
|
||||||
@@ -100,8 +108,8 @@ void GenerateServerMethodSignature(const grpc_generator::Method *method, grpc_ge
|
|||||||
void GenerateServerMethod(const grpc_generator::Method *method, grpc_generator::Printer *printer,
|
void GenerateServerMethod(const grpc_generator::Method *method, grpc_generator::Printer *printer,
|
||||||
std::map<grpc::string, grpc::string> vars) {
|
std::map<grpc::string, grpc::string> vars) {
|
||||||
vars["Method"] = exportName(method->name());
|
vars["Method"] = exportName(method->name());
|
||||||
vars["Request"] = method->input_name();
|
vars["Request"] = method->get_input_type_name();
|
||||||
vars["Response"] = (vars["CustomMethodIO"] == "") ? method->output_name() : vars["CustomMethodIO"];
|
vars["Response"] = (vars["CustomMethodIO"] == "") ? method->get_output_type_name() : vars["CustomMethodIO"];
|
||||||
vars["FullMethodName"] = "/" + vars["Package"] + "." + vars["Service"] + "/" + vars["Method"];
|
vars["FullMethodName"] = "/" + vars["Package"] + "." + vars["Service"] + "/" + vars["Method"];
|
||||||
vars["Handler"] = "_" + vars["Service"] + "_" + vars["Method"] + "_Handler";
|
vars["Handler"] = "_" + vars["Service"] + "_" + vars["Method"] + "_Handler";
|
||||||
if (method->NoStreaming()) {
|
if (method->NoStreaming()) {
|
||||||
@@ -129,7 +137,7 @@ void GenerateServerMethod(const grpc_generator::Method *method, grpc_generator::
|
|||||||
vars["StreamType"] = vars["ServiceUnexported"] + vars["Method"] + "Server";
|
vars["StreamType"] = vars["ServiceUnexported"] + vars["Method"] + "Server";
|
||||||
printer->Print(vars, "func $Handler$(srv interface{}, stream $grpc$.ServerStream) error {\n");
|
printer->Print(vars, "func $Handler$(srv interface{}, stream $grpc$.ServerStream) error {\n");
|
||||||
printer->Indent();
|
printer->Indent();
|
||||||
if (method->ServerOnlyStreaming()) {
|
if (ServerOnlyStreaming(method)) {
|
||||||
printer->Print(vars, "m := new($Request$)\n");
|
printer->Print(vars, "m := new($Request$)\n");
|
||||||
printer->Print(vars, "if err := stream.RecvMsg(m); err != nil { return err }\n");
|
printer->Print(vars, "if err := stream.RecvMsg(m); err != nil { return err }\n");
|
||||||
printer->Print(vars, "return srv.($Service$Server).$Method$(m, &$StreamType${stream})\n");
|
printer->Print(vars, "return srv.($Service$Server).$Method$(m, &$StreamType${stream})\n");
|
||||||
@@ -139,9 +147,9 @@ void GenerateServerMethod(const grpc_generator::Method *method, grpc_generator::
|
|||||||
printer->Outdent();
|
printer->Outdent();
|
||||||
printer->Print("}\n\n");
|
printer->Print("}\n\n");
|
||||||
|
|
||||||
bool genSend = method->BidiStreaming() || method->ServerOnlyStreaming();
|
bool genSend = method->BidiStreaming() || ServerOnlyStreaming(method);
|
||||||
bool genRecv = method->BidiStreaming() || method->ClientOnlyStreaming();
|
bool genRecv = method->BidiStreaming() || ClientOnlyStreaming(method);
|
||||||
bool genSendAndClose = method->ClientOnlyStreaming();
|
bool genSendAndClose = ClientOnlyStreaming(method);
|
||||||
|
|
||||||
printer->Print(vars, "type $Service$_$Method$Server interface { \n");
|
printer->Print(vars, "type $Service$_$Method$Server interface { \n");
|
||||||
printer->Indent();
|
printer->Indent();
|
||||||
@@ -194,12 +202,12 @@ void GenerateServerMethod(const grpc_generator::Method *method, grpc_generator::
|
|||||||
void GenerateClientMethodSignature(const grpc_generator::Method *method, grpc_generator::Printer *printer,
|
void GenerateClientMethodSignature(const grpc_generator::Method *method, grpc_generator::Printer *printer,
|
||||||
std::map<grpc::string, grpc::string> vars) {
|
std::map<grpc::string, grpc::string> vars) {
|
||||||
vars["Method"] = exportName(method->name());
|
vars["Method"] = exportName(method->name());
|
||||||
vars["Request"] = ", in *" + ((vars["CustomMethodIO"] == "") ? method->input_name() : vars["CustomMethodIO"]);
|
vars["Request"] = ", in *" + ((vars["CustomMethodIO"] == "") ? method->get_input_type_name() : vars["CustomMethodIO"]);
|
||||||
if (method->ClientOnlyStreaming() || method->BidiStreaming()) {
|
if (ClientOnlyStreaming(method) || method->BidiStreaming()) {
|
||||||
vars["Request"] = "";
|
vars["Request"] = "";
|
||||||
}
|
}
|
||||||
vars["Response"] = "* " + method->output_name();
|
vars["Response"] = "* " + method->get_output_type_name();
|
||||||
if (method->ClientOnlyStreaming() || method->BidiStreaming() || method->ServerOnlyStreaming()) {
|
if (ClientOnlyStreaming(method) || method->BidiStreaming() || ServerOnlyStreaming(method)) {
|
||||||
vars["Response"] = vars["Service"] + "_" + vars["Method"] + "Client" ;
|
vars["Response"] = vars["Service"] + "_" + vars["Method"] + "Client" ;
|
||||||
}
|
}
|
||||||
printer->Print(vars, "$Method$(ctx $context$.Context$Request$, \n\topts... $grpc$.CallOption) ($Response$, error)");
|
printer->Print(vars, "$Method$(ctx $context$.Context$Request$, \n\topts... $grpc$.CallOption) ($Response$, error)");
|
||||||
@@ -213,8 +221,8 @@ void GenerateClientMethod(const grpc_generator::Method *method, grpc_generator::
|
|||||||
printer->Print(" {\n");
|
printer->Print(" {\n");
|
||||||
printer->Indent();
|
printer->Indent();
|
||||||
vars["Method"] = exportName(method->name());
|
vars["Method"] = exportName(method->name());
|
||||||
vars["Request"] = (vars["CustomMethodIO"] == "") ? method->input_name() : vars["CustomMethodIO"];
|
vars["Request"] = (vars["CustomMethodIO"] == "") ? method->get_input_type_name() : vars["CustomMethodIO"];
|
||||||
vars["Response"] = method->output_name();
|
vars["Response"] = method->get_output_type_name();
|
||||||
vars["FullMethodName"] = "/" + vars["Package"] + "." + vars["Service"] + "/" + vars["Method"];
|
vars["FullMethodName"] = "/" + vars["Package"] + "." + vars["Service"] + "/" + vars["Method"];
|
||||||
if (method->NoStreaming()) {
|
if (method->NoStreaming()) {
|
||||||
printer->Print(vars, "out := new($Response$)\n");
|
printer->Print(vars, "out := new($Response$)\n");
|
||||||
@@ -230,7 +238,7 @@ void GenerateClientMethod(const grpc_generator::Method *method, grpc_generator::
|
|||||||
printer->Print("if err != nil { return nil, err }\n");
|
printer->Print("if err != nil { return nil, err }\n");
|
||||||
|
|
||||||
printer->Print(vars, "x := &$StreamType${stream}\n");
|
printer->Print(vars, "x := &$StreamType${stream}\n");
|
||||||
if (method->ServerOnlyStreaming()) {
|
if (ServerOnlyStreaming(method)) {
|
||||||
printer->Print("if err := x.ClientStream.SendMsg(in); err != nil { return nil, err }\n");
|
printer->Print("if err := x.ClientStream.SendMsg(in); err != nil { return nil, err }\n");
|
||||||
printer->Print("if err := x.ClientStream.CloseSend(); err != nil { return nil, err }\n");
|
printer->Print("if err := x.ClientStream.CloseSend(); err != nil { return nil, err }\n");
|
||||||
}
|
}
|
||||||
@@ -238,9 +246,9 @@ void GenerateClientMethod(const grpc_generator::Method *method, grpc_generator::
|
|||||||
printer->Outdent();
|
printer->Outdent();
|
||||||
printer->Print("}\n\n");
|
printer->Print("}\n\n");
|
||||||
|
|
||||||
bool genSend = method->BidiStreaming() || method->ClientOnlyStreaming();
|
bool genSend = method->BidiStreaming() || ClientOnlyStreaming(method);
|
||||||
bool genRecv = method->BidiStreaming() || method->ServerOnlyStreaming();
|
bool genRecv = method->BidiStreaming() || ServerOnlyStreaming(method);
|
||||||
bool genCloseAndRecv = method->ClientOnlyStreaming();
|
bool genCloseAndRecv = ClientOnlyStreaming(method);
|
||||||
|
|
||||||
//Stream interface
|
//Stream interface
|
||||||
printer->Print(vars, "type $Service$_$Method$Client interface {\n");
|
printer->Print(vars, "type $Service$_$Method$Client interface {\n");
|
||||||
@@ -396,9 +404,9 @@ void GenerateService(const grpc_generator::Service *service, grpc_generator::Pri
|
|||||||
printer->Indent();
|
printer->Indent();
|
||||||
printer->Print(vars, "StreamName: \"$Method$\",\n");
|
printer->Print(vars, "StreamName: \"$Method$\",\n");
|
||||||
printer->Print(vars, "Handler: $Handler$, \n");
|
printer->Print(vars, "Handler: $Handler$, \n");
|
||||||
if (method->ClientOnlyStreaming()) {
|
if (ClientOnlyStreaming(method.get())) {
|
||||||
printer->Print("ClientStreams: true,\n");
|
printer->Print("ClientStreams: true,\n");
|
||||||
} else if (method->ServerOnlyStreaming()) {
|
} else if (ServerOnlyStreaming(method.get())) {
|
||||||
printer->Print("ServerStreams: true,\n");
|
printer->Print("ServerStreams: true,\n");
|
||||||
} else {
|
} else {
|
||||||
printer->Print("ServerStreams: true,\n");
|
printer->Print("ServerStreams: true,\n");
|
||||||
|
|||||||
@@ -43,12 +43,12 @@
|
|||||||
namespace grpc_go_generator {
|
namespace grpc_go_generator {
|
||||||
|
|
||||||
struct Parameters {
|
struct Parameters {
|
||||||
//Defines the custom parameter types for methods
|
//Defines the custom parameter types for methods
|
||||||
//eg: flatbuffers uses flatbuffers.Builder as input for the client and output for the server
|
//eg: flatbuffers uses flatbuffers.Builder as input for the client and output for the server
|
||||||
grpc::string custom_method_io_type;
|
grpc::string custom_method_io_type;
|
||||||
|
|
||||||
//Package name for the service
|
//Package name for the service
|
||||||
grpc::string package_name;
|
grpc::string package_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Return the source of the generated service file.
|
// Return the source of the generated service file.
|
||||||
|
|||||||
@@ -34,79 +34,93 @@
|
|||||||
#ifndef GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H
|
#ifndef GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H
|
||||||
#define GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H
|
#define GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H
|
||||||
|
|
||||||
#include <map>
|
#include "src/compiler/config.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#ifndef GRPC_CUSTOM_STRING
|
#ifndef GRPC_CUSTOM_STRING
|
||||||
#include <string>
|
#include <string>
|
||||||
#define GRPC_CUSTOM_STRING std::string
|
#define GRPC_CUSTOM_STRING std::string
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace grpc {
|
namespace grpc {
|
||||||
|
|
||||||
typedef GRPC_CUSTOM_STRING string;
|
typedef GRPC_CUSTOM_STRING string;
|
||||||
|
|
||||||
} // namespace grpc
|
} // namespace grpc
|
||||||
|
|
||||||
namespace grpc_generator {
|
namespace grpc_generator {
|
||||||
|
|
||||||
// An abstract interface representing a method.
|
// A common interface for objects having comments in the source.
|
||||||
struct Method {
|
// Return formatted comments to be inserted in generated code.
|
||||||
virtual ~Method() {}
|
struct CommentHolder {
|
||||||
|
virtual ~CommentHolder() {}
|
||||||
|
virtual grpc::string GetLeadingComments(const grpc::string prefix) const = 0;
|
||||||
|
virtual grpc::string GetTrailingComments(const grpc::string prefix) const = 0;
|
||||||
|
virtual std::vector<grpc::string> GetAllComments() const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
virtual grpc::string name() const = 0;
|
// An abstract interface representing a method.
|
||||||
|
struct Method : public CommentHolder {
|
||||||
|
virtual ~Method() {}
|
||||||
|
|
||||||
virtual grpc::string input_type_name() const = 0;
|
virtual grpc::string name() const = 0;
|
||||||
virtual grpc::string output_type_name() const = 0;
|
|
||||||
virtual grpc::string input_name() const = 0;
|
|
||||||
virtual grpc::string output_name() const = 0;
|
|
||||||
|
|
||||||
virtual bool NoStreaming() const = 0;
|
virtual grpc::string input_type_name() const = 0;
|
||||||
virtual bool ClientOnlyStreaming() const = 0;
|
virtual grpc::string output_type_name() const = 0;
|
||||||
virtual bool ServerOnlyStreaming() const = 0;
|
|
||||||
virtual bool BidiStreaming() const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
// An abstract interface representing a service.
|
virtual bool get_module_and_message_path_input(
|
||||||
struct Service {
|
grpc::string *str, grpc::string generator_file_name,
|
||||||
virtual ~Service() {}
|
bool generate_in_pb2_grpc, grpc::string import_prefix) const = 0;
|
||||||
|
virtual bool get_module_and_message_path_output(
|
||||||
|
grpc::string *str, grpc::string generator_file_name,
|
||||||
|
bool generate_in_pb2_grpc, grpc::string import_prefix) const = 0;
|
||||||
|
|
||||||
virtual grpc::string name() const = 0;
|
virtual grpc::string get_input_type_name() const = 0;
|
||||||
|
virtual grpc::string get_output_type_name() const = 0;
|
||||||
|
virtual bool NoStreaming() const = 0;
|
||||||
|
virtual bool ClientStreaming() const = 0;
|
||||||
|
virtual bool ServerStreaming() const = 0;
|
||||||
|
virtual bool BidiStreaming() const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
virtual int method_count() const = 0;
|
// An abstract interface representing a service.
|
||||||
virtual std::unique_ptr<const Method> method(int i) const = 0;
|
struct Service : public CommentHolder {
|
||||||
};
|
virtual ~Service() {}
|
||||||
|
|
||||||
struct Printer {
|
virtual grpc::string name() const = 0;
|
||||||
virtual ~Printer() {}
|
|
||||||
|
|
||||||
virtual void Print(const std::map<grpc::string, grpc::string> &vars,
|
virtual int method_count() const = 0;
|
||||||
const char *template_string) = 0;
|
virtual std::unique_ptr<const Method> method(int i) const = 0;
|
||||||
virtual void Print(const char *string) = 0;
|
};
|
||||||
virtual void Indent() = 0;
|
|
||||||
virtual void Outdent() = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
// An interface that allows the source generated to be output using various
|
struct Printer {
|
||||||
// libraries/idls/serializers.
|
virtual ~Printer() {}
|
||||||
struct File {
|
|
||||||
virtual ~File() {}
|
|
||||||
|
|
||||||
virtual grpc::string filename() const = 0;
|
virtual void Print(const std::map<grpc::string, grpc::string> &vars,
|
||||||
virtual grpc::string filename_without_ext() const = 0;
|
const char *template_string) = 0;
|
||||||
virtual grpc::string message_header_ext() const = 0;
|
virtual void Print(const char *string) = 0;
|
||||||
virtual grpc::string service_header_ext() const = 0;
|
virtual void Indent() = 0;
|
||||||
virtual grpc::string package() const = 0;
|
virtual void Outdent() = 0;
|
||||||
virtual std::vector<grpc::string> package_parts() const = 0;
|
};
|
||||||
virtual grpc::string additional_headers() const = 0;
|
|
||||||
virtual grpc::string additional_imports() const = 0;
|
|
||||||
|
|
||||||
virtual int service_count() const = 0;
|
// An interface that allows the source generated to be output using various
|
||||||
virtual std::unique_ptr<const Service> service(int i) const = 0;
|
// libraries/idls/serializers.
|
||||||
|
struct File : public CommentHolder {
|
||||||
|
virtual ~File() {}
|
||||||
|
|
||||||
virtual std::unique_ptr<Printer> CreatePrinter(grpc::string *str) const = 0;
|
virtual grpc::string filename() const = 0;
|
||||||
};
|
virtual grpc::string filename_without_ext() const = 0;
|
||||||
} // namespace grpc_generator
|
virtual grpc::string package() const = 0;
|
||||||
|
virtual std::vector<grpc::string> package_parts() const = 0;
|
||||||
|
virtual grpc::string additional_headers() const = 0;
|
||||||
|
|
||||||
|
virtual int service_count() const = 0;
|
||||||
|
virtual std::unique_ptr<const Service> service(int i) const = 0;
|
||||||
|
|
||||||
|
virtual std::unique_ptr<Printer> CreatePrinter(grpc::string *str) const = 0;
|
||||||
|
};
|
||||||
|
} // namespace grpc_generator
|
||||||
|
|
||||||
#endif // GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H
|
#endif // GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
// Helper functionality to glue FlatBuffers and GRPC.
|
// Helper functionality to glue FlatBuffers and GRPC.
|
||||||
|
|
||||||
|
#include "flatbuffers/flatbuffers.h"
|
||||||
#include "grpc++/support/byte_buffer.h"
|
#include "grpc++/support/byte_buffer.h"
|
||||||
#include "grpc/byte_buffer_reader.h"
|
#include "grpc/byte_buffer_reader.h"
|
||||||
|
|
||||||
|
|||||||
@@ -46,30 +46,52 @@ class FlatBufMethod : public grpc_generator::Method {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
grpc::string GetLeadingComments(const grpc::string) const {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
grpc::string GetTrailingComments(const grpc::string) const {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
std::vector<grpc::string> GetAllComments() const {
|
||||||
|
return std::vector<grpc::string>();
|
||||||
|
}
|
||||||
|
|
||||||
std::string name() const { return method_->name; }
|
std::string name() const { return method_->name; }
|
||||||
|
|
||||||
std::string GRPCType(const StructDef &sd) const {
|
std::string GRPCType(const StructDef &sd) const {
|
||||||
return "flatbuffers::BufferRef<" + sd.name + ">";
|
return "flatbuffers::BufferRef<" + sd.name + ">";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string get_input_type_name() const {
|
||||||
|
return (*method_->request).name;
|
||||||
|
}
|
||||||
|
std::string get_output_type_name() const {
|
||||||
|
return (*method_->response).name;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool get_module_and_message_path_input(
|
||||||
|
grpc::string * /*str*/, grpc::string /*generator_file_name*/,
|
||||||
|
bool /*generate_in_pb2_grpc*/, grpc::string /*import_prefix*/) const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool get_module_and_message_path_output(
|
||||||
|
grpc::string * /*str*/, grpc::string /*generator_file_name*/,
|
||||||
|
bool /*generate_in_pb2_grpc*/, grpc::string /*import_prefix*/) const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
std::string input_type_name() const {
|
std::string input_type_name() const {
|
||||||
return GRPCType(*method_->request);
|
return GRPCType(*method_->request);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string output_type_name() const {
|
std::string output_type_name() const {
|
||||||
return GRPCType(*method_->response);
|
return GRPCType(*method_->response);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string input_name() const {
|
|
||||||
return (*method_->request).name;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string output_name() const {
|
|
||||||
return (*method_->response).name;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NoStreaming() const { return streaming_ == kNone; }
|
bool NoStreaming() const { return streaming_ == kNone; }
|
||||||
bool ClientOnlyStreaming() const { return streaming_ == kClient; }
|
bool ClientStreaming() const { return streaming_ == kClient; }
|
||||||
bool ServerOnlyStreaming() const { return streaming_ == kServer; }
|
bool ServerStreaming() const { return streaming_ == kServer; }
|
||||||
bool BidiStreaming() const { return streaming_ == kBiDi; }
|
bool BidiStreaming() const { return streaming_ == kBiDi; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -81,6 +103,16 @@ class FlatBufService : public grpc_generator::Service {
|
|||||||
public:
|
public:
|
||||||
FlatBufService(const ServiceDef *service) : service_(service) {}
|
FlatBufService(const ServiceDef *service) : service_(service) {}
|
||||||
|
|
||||||
|
grpc::string GetLeadingComments(const grpc::string) const {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
grpc::string GetTrailingComments(const grpc::string) const {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
std::vector<grpc::string> GetAllComments() const {
|
||||||
|
return std::vector<grpc::string>();
|
||||||
|
}
|
||||||
|
|
||||||
std::string name() const { return service_->name; }
|
std::string name() const { return service_->name; }
|
||||||
|
|
||||||
int method_count() const {
|
int method_count() const {
|
||||||
@@ -150,10 +182,26 @@ class FlatBufPrinter : public grpc_generator::Printer {
|
|||||||
|
|
||||||
class FlatBufFile : public grpc_generator::File {
|
class FlatBufFile : public grpc_generator::File {
|
||||||
public:
|
public:
|
||||||
FlatBufFile(const Parser &parser, const std::string &file_name)
|
enum Language {
|
||||||
: parser_(parser), file_name_(file_name) {}
|
kLanguageGo,
|
||||||
|
kLanguageCpp
|
||||||
|
};
|
||||||
|
|
||||||
|
FlatBufFile(
|
||||||
|
const Parser &parser, const std::string &file_name, Language language)
|
||||||
|
: parser_(parser), file_name_(file_name), language_(language) {}
|
||||||
FlatBufFile &operator=(const FlatBufFile &);
|
FlatBufFile &operator=(const FlatBufFile &);
|
||||||
|
|
||||||
|
grpc::string GetLeadingComments(const grpc::string) const {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
grpc::string GetTrailingComments(const grpc::string) const {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
std::vector<grpc::string> GetAllComments() const {
|
||||||
|
return std::vector<grpc::string>();
|
||||||
|
}
|
||||||
|
|
||||||
std::string filename() const { return file_name_; }
|
std::string filename() const { return file_name_; }
|
||||||
std::string filename_without_ext() const {
|
std::string filename_without_ext() const {
|
||||||
return StripExtension(file_name_);
|
return StripExtension(file_name_);
|
||||||
@@ -171,11 +219,15 @@ class FlatBufFile : public grpc_generator::File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string additional_headers() const {
|
std::string additional_headers() const {
|
||||||
return "#include \"flatbuffers/grpc.h\"\n";
|
switch (language_) {
|
||||||
}
|
case kLanguageCpp: {
|
||||||
|
return "#include \"flatbuffers/grpc.h\"\n";
|
||||||
std::string additional_imports() const {
|
}
|
||||||
return "import \"github.com/google/flatbuffers/go\"";
|
case kLanguageGo: {
|
||||||
|
return "import \"github.com/google/flatbuffers/go\"";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
int service_count() const {
|
int service_count() const {
|
||||||
@@ -195,6 +247,7 @@ class FlatBufFile : public grpc_generator::File {
|
|||||||
private:
|
private:
|
||||||
const Parser &parser_;
|
const Parser &parser_;
|
||||||
const std::string &file_name_;
|
const std::string &file_name_;
|
||||||
|
const Language language_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GoGRPCGenerator : public flatbuffers::BaseGenerator {
|
class GoGRPCGenerator : public flatbuffers::BaseGenerator {
|
||||||
@@ -205,7 +258,7 @@ class GoGRPCGenerator : public flatbuffers::BaseGenerator {
|
|||||||
parser_(parser), path_(path), file_name_(file_name) {}
|
parser_(parser), path_(path), file_name_(file_name) {}
|
||||||
|
|
||||||
bool generate() {
|
bool generate() {
|
||||||
FlatBufFile file(parser_, file_name_);
|
FlatBufFile file(parser_, file_name_, FlatBufFile::kLanguageGo);
|
||||||
grpc_go_generator::Parameters p;
|
grpc_go_generator::Parameters p;
|
||||||
p.custom_method_io_type = "flatbuffers.Builder";
|
p.custom_method_io_type = "flatbuffers.Builder";
|
||||||
for (int i = 0; i < file.service_count(); i++) {
|
for (int i = 0; i < file.service_count(); i++) {
|
||||||
@@ -252,7 +305,7 @@ bool GenerateCppGRPC(const Parser &parser,
|
|||||||
// TODO(wvo): make the other parameters in this struct configurable.
|
// TODO(wvo): make the other parameters in this struct configurable.
|
||||||
generator_parameters.use_system_headers = true;
|
generator_parameters.use_system_headers = true;
|
||||||
|
|
||||||
FlatBufFile fbfile(parser, file_name);
|
FlatBufFile fbfile(parser, file_name, FlatBufFile::kLanguageCpp);
|
||||||
|
|
||||||
std::string header_code =
|
std::string header_code =
|
||||||
grpc_cpp_generator::GetHeaderPrologue(&fbfile, generator_parameters) +
|
grpc_cpp_generator::GetHeaderPrologue(&fbfile, generator_parameters) +
|
||||||
|
|||||||
Binary file not shown.
@@ -1,4 +1,4 @@
|
|||||||
// Generated by the gRPC protobuf plugin.
|
// Generated by the gRPC C++ plugin.
|
||||||
// If you make any local change, they will be lost.
|
// If you make any local change, they will be lost.
|
||||||
// source: monster_test
|
// source: monster_test
|
||||||
|
|
||||||
@@ -13,7 +13,6 @@
|
|||||||
#include <grpc++/impl/codegen/rpc_service_method.h>
|
#include <grpc++/impl/codegen/rpc_service_method.h>
|
||||||
#include <grpc++/impl/codegen/service_type.h>
|
#include <grpc++/impl/codegen/service_type.h>
|
||||||
#include <grpc++/impl/codegen/sync_stream.h>
|
#include <grpc++/impl/codegen/sync_stream.h>
|
||||||
|
|
||||||
namespace MyGame {
|
namespace MyGame {
|
||||||
namespace Example {
|
namespace Example {
|
||||||
|
|
||||||
@@ -37,7 +36,7 @@ MonsterStorage::Stub::Stub(const std::shared_ptr< ::grpc::ChannelInterface>& cha
|
|||||||
}
|
}
|
||||||
|
|
||||||
::grpc::ClientAsyncResponseReader< flatbuffers::BufferRef<Stat>>* MonsterStorage::Stub::AsyncStoreRaw(::grpc::ClientContext* context, const flatbuffers::BufferRef<Monster>& request, ::grpc::CompletionQueue* cq) {
|
::grpc::ClientAsyncResponseReader< flatbuffers::BufferRef<Stat>>* MonsterStorage::Stub::AsyncStoreRaw(::grpc::ClientContext* context, const flatbuffers::BufferRef<Monster>& request, ::grpc::CompletionQueue* cq) {
|
||||||
return new ::grpc::ClientAsyncResponseReader< flatbuffers::BufferRef<Stat>>(channel_.get(), cq, rpcmethod_Store_, context, request);
|
return ::grpc::ClientAsyncResponseReader< flatbuffers::BufferRef<Stat>>::Create(channel_.get(), cq, rpcmethod_Store_, context, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
::grpc::ClientReader< flatbuffers::BufferRef<Monster>>* MonsterStorage::Stub::RetrieveRaw(::grpc::ClientContext* context, const flatbuffers::BufferRef<Stat>& request) {
|
::grpc::ClientReader< flatbuffers::BufferRef<Monster>>* MonsterStorage::Stub::RetrieveRaw(::grpc::ClientContext* context, const flatbuffers::BufferRef<Stat>& request) {
|
||||||
@@ -45,11 +44,10 @@ MonsterStorage::Stub::Stub(const std::shared_ptr< ::grpc::ChannelInterface>& cha
|
|||||||
}
|
}
|
||||||
|
|
||||||
::grpc::ClientAsyncReader< flatbuffers::BufferRef<Monster>>* MonsterStorage::Stub::AsyncRetrieveRaw(::grpc::ClientContext* context, const flatbuffers::BufferRef<Stat>& request, ::grpc::CompletionQueue* cq, void* tag) {
|
::grpc::ClientAsyncReader< flatbuffers::BufferRef<Monster>>* MonsterStorage::Stub::AsyncRetrieveRaw(::grpc::ClientContext* context, const flatbuffers::BufferRef<Stat>& request, ::grpc::CompletionQueue* cq, void* tag) {
|
||||||
return new ::grpc::ClientAsyncReader< flatbuffers::BufferRef<Monster>>(channel_.get(), cq, rpcmethod_Retrieve_, context, request, tag);
|
return ::grpc::ClientAsyncReader< flatbuffers::BufferRef<Monster>>::Create(channel_.get(), cq, rpcmethod_Retrieve_, context, request, tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
MonsterStorage::Service::Service() {
|
MonsterStorage::Service::Service() {
|
||||||
(void)MonsterStorage_method_names;
|
|
||||||
AddMethod(new ::grpc::RpcServiceMethod(
|
AddMethod(new ::grpc::RpcServiceMethod(
|
||||||
MonsterStorage_method_names[0],
|
MonsterStorage_method_names[0],
|
||||||
::grpc::RpcMethod::NORMAL_RPC,
|
::grpc::RpcMethod::NORMAL_RPC,
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
// Generated by the gRPC protobuf plugin.
|
// Generated by the gRPC C++ plugin.
|
||||||
// If you make any local change, they will be lost.
|
// If you make any local change, they will be lost.
|
||||||
// source: monster_test
|
// source: monster_test
|
||||||
#ifndef GRPC_monster_5ftest__INCLUDED
|
#ifndef GRPC_monster_5ftest__INCLUDED
|
||||||
#define GRPC_monster_5ftest__INCLUDED
|
#define GRPC_monster_5ftest__INCLUDED
|
||||||
|
|
||||||
#include "monster_test_generated.h"
|
|
||||||
#include "flatbuffers/grpc.h"
|
#include "flatbuffers/grpc.h"
|
||||||
|
#include "monster_test_generated.h"
|
||||||
|
|
||||||
#include <grpc++/impl/codegen/async_stream.h>
|
#include <grpc++/impl/codegen/async_stream.h>
|
||||||
#include <grpc++/impl/codegen/async_unary_call.h>
|
#include <grpc++/impl/codegen/async_unary_call.h>
|
||||||
|
#include <grpc++/impl/codegen/method_handler_impl.h>
|
||||||
|
#include <grpc++/impl/codegen/proto_utils.h>
|
||||||
#include <grpc++/impl/codegen/rpc_method.h>
|
#include <grpc++/impl/codegen/rpc_method.h>
|
||||||
#include <grpc++/impl/codegen/service_type.h>
|
#include <grpc++/impl/codegen/service_type.h>
|
||||||
#include <grpc++/impl/codegen/status.h>
|
#include <grpc++/impl/codegen/status.h>
|
||||||
@@ -26,30 +28,33 @@ class ServerContext;
|
|||||||
namespace MyGame {
|
namespace MyGame {
|
||||||
namespace Example {
|
namespace Example {
|
||||||
|
|
||||||
class MonsterStorage GRPC_FINAL {
|
class MonsterStorage final {
|
||||||
public:
|
public:
|
||||||
|
static constexpr char const* service_full_name() {
|
||||||
|
return "MyGame.Example.MonsterStorage";
|
||||||
|
}
|
||||||
class StubInterface {
|
class StubInterface {
|
||||||
public:
|
public:
|
||||||
virtual ~StubInterface() {}
|
virtual ~StubInterface() {}
|
||||||
virtual ::grpc::Status Store(::grpc::ClientContext* context, const flatbuffers::BufferRef<Monster>& request, flatbuffers::BufferRef<Stat>* response) = 0;
|
virtual ::grpc::Status Store(::grpc::ClientContext* context, const flatbuffers::BufferRef<Monster>& request, flatbuffers::BufferRef<Stat>* response) = 0;
|
||||||
std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< flatbuffers::BufferRef<Stat>>> AsyncStore(::grpc::ClientContext* context, const flatbuffers::BufferRef<Monster>& request, ::grpc::CompletionQueue* cq) {
|
std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< flatbuffers::BufferRef<Stat>>> AsyncStore(::grpc::ClientContext* context, const flatbuffers::BufferRef<Monster>& request, ::grpc::CompletionQueue* cq) {
|
||||||
return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< flatbuffers::BufferRef<Stat>>>(AsyncStoreRaw(context, request, cq));
|
return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< flatbuffers::BufferRef<Stat>>>(AsyncStoreRaw(context, request, cq));
|
||||||
}
|
}
|
||||||
std::unique_ptr< ::grpc::ClientReaderInterface< flatbuffers::BufferRef<Monster>>> Retrieve(::grpc::ClientContext* context, const flatbuffers::BufferRef<Stat>& request) {
|
std::unique_ptr< ::grpc::ClientReaderInterface< flatbuffers::BufferRef<Monster>>> Retrieve(::grpc::ClientContext* context, const flatbuffers::BufferRef<Stat>& request) {
|
||||||
return std::unique_ptr< ::grpc::ClientReaderInterface< flatbuffers::BufferRef<Monster>>>(RetrieveRaw(context, request));
|
return std::unique_ptr< ::grpc::ClientReaderInterface< flatbuffers::BufferRef<Monster>>>(RetrieveRaw(context, request));
|
||||||
}
|
}
|
||||||
std::unique_ptr< ::grpc::ClientAsyncReaderInterface< flatbuffers::BufferRef<Monster>>> AsyncRetrieve(::grpc::ClientContext* context, const flatbuffers::BufferRef<Stat>& request, ::grpc::CompletionQueue* cq, void* tag) {
|
std::unique_ptr< ::grpc::ClientAsyncReaderInterface< flatbuffers::BufferRef<Monster>>> AsyncRetrieve(::grpc::ClientContext* context, const flatbuffers::BufferRef<Stat>& request, ::grpc::CompletionQueue* cq, void* tag) {
|
||||||
return std::unique_ptr< ::grpc::ClientAsyncReaderInterface< flatbuffers::BufferRef<Monster>>>(AsyncRetrieveRaw(context, request, cq, tag));
|
return std::unique_ptr< ::grpc::ClientAsyncReaderInterface< flatbuffers::BufferRef<Monster>>>(AsyncRetrieveRaw(context, request, cq, tag));
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
virtual ::grpc::ClientAsyncResponseReaderInterface< flatbuffers::BufferRef<Stat>>* AsyncStoreRaw(::grpc::ClientContext* context, const flatbuffers::BufferRef<Monster>& request, ::grpc::CompletionQueue* cq) = 0;
|
virtual ::grpc::ClientAsyncResponseReaderInterface< flatbuffers::BufferRef<Stat>>* AsyncStoreRaw(::grpc::ClientContext* context, const flatbuffers::BufferRef<Monster>& request, ::grpc::CompletionQueue* cq) = 0;
|
||||||
virtual ::grpc::ClientReaderInterface< flatbuffers::BufferRef<Monster>>* RetrieveRaw(::grpc::ClientContext* context, const flatbuffers::BufferRef<Stat>& request) = 0;
|
virtual ::grpc::ClientReaderInterface< flatbuffers::BufferRef<Monster>>* RetrieveRaw(::grpc::ClientContext* context, const flatbuffers::BufferRef<Stat>& request) = 0;
|
||||||
virtual ::grpc::ClientAsyncReaderInterface< flatbuffers::BufferRef<Monster>>* AsyncRetrieveRaw(::grpc::ClientContext* context, const flatbuffers::BufferRef<Stat>& request, ::grpc::CompletionQueue* cq, void* tag) = 0;
|
virtual ::grpc::ClientAsyncReaderInterface< flatbuffers::BufferRef<Monster>>* AsyncRetrieveRaw(::grpc::ClientContext* context, const flatbuffers::BufferRef<Stat>& request, ::grpc::CompletionQueue* cq, void* tag) = 0;
|
||||||
};
|
};
|
||||||
class Stub GRPC_FINAL : public StubInterface {
|
class Stub final : public StubInterface {
|
||||||
public:
|
public:
|
||||||
Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel);
|
Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel);
|
||||||
::grpc::Status Store(::grpc::ClientContext* context, const flatbuffers::BufferRef<Monster>& request, flatbuffers::BufferRef<Stat>* response) GRPC_OVERRIDE;
|
::grpc::Status Store(::grpc::ClientContext* context, const flatbuffers::BufferRef<Monster>& request, flatbuffers::BufferRef<Stat>* response) override;
|
||||||
std::unique_ptr< ::grpc::ClientAsyncResponseReader< flatbuffers::BufferRef<Stat>>> AsyncStore(::grpc::ClientContext* context, const flatbuffers::BufferRef<Monster>& request, ::grpc::CompletionQueue* cq) {
|
std::unique_ptr< ::grpc::ClientAsyncResponseReader< flatbuffers::BufferRef<Stat>>> AsyncStore(::grpc::ClientContext* context, const flatbuffers::BufferRef<Monster>& request, ::grpc::CompletionQueue* cq) {
|
||||||
return std::unique_ptr< ::grpc::ClientAsyncResponseReader< flatbuffers::BufferRef<Stat>>>(AsyncStoreRaw(context, request, cq));
|
return std::unique_ptr< ::grpc::ClientAsyncResponseReader< flatbuffers::BufferRef<Stat>>>(AsyncStoreRaw(context, request, cq));
|
||||||
}
|
}
|
||||||
@@ -62,9 +67,9 @@ class MonsterStorage GRPC_FINAL {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr< ::grpc::ChannelInterface> channel_;
|
std::shared_ptr< ::grpc::ChannelInterface> channel_;
|
||||||
::grpc::ClientAsyncResponseReader< flatbuffers::BufferRef<Stat>>* AsyncStoreRaw(::grpc::ClientContext* context, const flatbuffers::BufferRef<Monster>& request, ::grpc::CompletionQueue* cq) GRPC_OVERRIDE;
|
::grpc::ClientAsyncResponseReader< flatbuffers::BufferRef<Stat>>* AsyncStoreRaw(::grpc::ClientContext* context, const flatbuffers::BufferRef<Monster>& request, ::grpc::CompletionQueue* cq) override;
|
||||||
::grpc::ClientReader< flatbuffers::BufferRef<Monster>>* RetrieveRaw(::grpc::ClientContext* context, const flatbuffers::BufferRef<Stat>& request) GRPC_OVERRIDE;
|
::grpc::ClientReader< flatbuffers::BufferRef<Monster>>* RetrieveRaw(::grpc::ClientContext* context, const flatbuffers::BufferRef<Stat>& request) override;
|
||||||
::grpc::ClientAsyncReader< flatbuffers::BufferRef<Monster>>* AsyncRetrieveRaw(::grpc::ClientContext* context, const flatbuffers::BufferRef<Stat>& request, ::grpc::CompletionQueue* cq, void* tag) GRPC_OVERRIDE;
|
::grpc::ClientAsyncReader< flatbuffers::BufferRef<Monster>>* AsyncRetrieveRaw(::grpc::ClientContext* context, const flatbuffers::BufferRef<Stat>& request, ::grpc::CompletionQueue* cq, void* tag) override;
|
||||||
const ::grpc::RpcMethod rpcmethod_Store_;
|
const ::grpc::RpcMethod rpcmethod_Store_;
|
||||||
const ::grpc::RpcMethod rpcmethod_Retrieve_;
|
const ::grpc::RpcMethod rpcmethod_Retrieve_;
|
||||||
};
|
};
|
||||||
@@ -74,9 +79,9 @@ class MonsterStorage GRPC_FINAL {
|
|||||||
public:
|
public:
|
||||||
Service();
|
Service();
|
||||||
virtual ~Service();
|
virtual ~Service();
|
||||||
virtual ::grpc::Status Store(::grpc::ServerContext* context, const flatbuffers::BufferRef<Monster>* request, flatbuffers::BufferRef<Stat>* response);
|
virtual ::grpc::Status Store(::grpc::ServerContext* context, const flatbuffers::BufferRef<Monster>* request, flatbuffers::BufferRef<Stat>* response);
|
||||||
virtual ::grpc::Status Retrieve(::grpc::ServerContext* context, const flatbuffers::BufferRef<Stat>* request, ::grpc::ServerWriter< flatbuffers::BufferRef<Monster>>* writer);
|
virtual ::grpc::Status Retrieve(::grpc::ServerContext* context, const flatbuffers::BufferRef<Stat>* request, ::grpc::ServerWriter< flatbuffers::BufferRef<Monster>>* writer);
|
||||||
};
|
};
|
||||||
template <class BaseClass>
|
template <class BaseClass>
|
||||||
class WithAsyncMethod_Store : public BaseClass {
|
class WithAsyncMethod_Store : public BaseClass {
|
||||||
private:
|
private:
|
||||||
@@ -85,11 +90,11 @@ class MonsterStorage GRPC_FINAL {
|
|||||||
WithAsyncMethod_Store() {
|
WithAsyncMethod_Store() {
|
||||||
::grpc::Service::MarkMethodAsync(0);
|
::grpc::Service::MarkMethodAsync(0);
|
||||||
}
|
}
|
||||||
~WithAsyncMethod_Store() GRPC_OVERRIDE {
|
~WithAsyncMethod_Store() override {
|
||||||
BaseClassMustBeDerivedFromService(this);
|
BaseClassMustBeDerivedFromService(this);
|
||||||
}
|
}
|
||||||
// disable synchronous version of this method
|
// disable synchronous version of this method
|
||||||
::grpc::Status Store(::grpc::ServerContext* context, const flatbuffers::BufferRef<Monster>* request, flatbuffers::BufferRef<Stat>* response) GRPC_FINAL GRPC_OVERRIDE {
|
::grpc::Status Store(::grpc::ServerContext* context, const flatbuffers::BufferRef<Monster>* request, flatbuffers::BufferRef<Stat>* response) final override {
|
||||||
abort();
|
abort();
|
||||||
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
|
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
|
||||||
}
|
}
|
||||||
@@ -105,11 +110,11 @@ class MonsterStorage GRPC_FINAL {
|
|||||||
WithAsyncMethod_Retrieve() {
|
WithAsyncMethod_Retrieve() {
|
||||||
::grpc::Service::MarkMethodAsync(1);
|
::grpc::Service::MarkMethodAsync(1);
|
||||||
}
|
}
|
||||||
~WithAsyncMethod_Retrieve() GRPC_OVERRIDE {
|
~WithAsyncMethod_Retrieve() override {
|
||||||
BaseClassMustBeDerivedFromService(this);
|
BaseClassMustBeDerivedFromService(this);
|
||||||
}
|
}
|
||||||
// disable synchronous version of this method
|
// disable synchronous version of this method
|
||||||
::grpc::Status Retrieve(::grpc::ServerContext* context, const flatbuffers::BufferRef<Stat>* request, ::grpc::ServerWriter< flatbuffers::BufferRef<Monster>>* writer) GRPC_FINAL GRPC_OVERRIDE {
|
::grpc::Status Retrieve(::grpc::ServerContext* context, const flatbuffers::BufferRef<Stat>* request, ::grpc::ServerWriter< flatbuffers::BufferRef<Monster>>* writer) final override {
|
||||||
abort();
|
abort();
|
||||||
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
|
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
|
||||||
}
|
}
|
||||||
@@ -126,11 +131,11 @@ class MonsterStorage GRPC_FINAL {
|
|||||||
WithGenericMethod_Store() {
|
WithGenericMethod_Store() {
|
||||||
::grpc::Service::MarkMethodGeneric(0);
|
::grpc::Service::MarkMethodGeneric(0);
|
||||||
}
|
}
|
||||||
~WithGenericMethod_Store() GRPC_OVERRIDE {
|
~WithGenericMethod_Store() override {
|
||||||
BaseClassMustBeDerivedFromService(this);
|
BaseClassMustBeDerivedFromService(this);
|
||||||
}
|
}
|
||||||
// disable synchronous version of this method
|
// disable synchronous version of this method
|
||||||
::grpc::Status Store(::grpc::ServerContext* context, const flatbuffers::BufferRef<Monster>* request, flatbuffers::BufferRef<Stat>* response) GRPC_FINAL GRPC_OVERRIDE {
|
::grpc::Status Store(::grpc::ServerContext* context, const flatbuffers::BufferRef<Monster>* request, flatbuffers::BufferRef<Stat>* response) final override {
|
||||||
abort();
|
abort();
|
||||||
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
|
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
|
||||||
}
|
}
|
||||||
@@ -143,15 +148,58 @@ class MonsterStorage GRPC_FINAL {
|
|||||||
WithGenericMethod_Retrieve() {
|
WithGenericMethod_Retrieve() {
|
||||||
::grpc::Service::MarkMethodGeneric(1);
|
::grpc::Service::MarkMethodGeneric(1);
|
||||||
}
|
}
|
||||||
~WithGenericMethod_Retrieve() GRPC_OVERRIDE {
|
~WithGenericMethod_Retrieve() override {
|
||||||
BaseClassMustBeDerivedFromService(this);
|
BaseClassMustBeDerivedFromService(this);
|
||||||
}
|
}
|
||||||
// disable synchronous version of this method
|
// disable synchronous version of this method
|
||||||
::grpc::Status Retrieve(::grpc::ServerContext* context, const flatbuffers::BufferRef<Stat>* request, ::grpc::ServerWriter< flatbuffers::BufferRef<Monster>>* writer) GRPC_FINAL GRPC_OVERRIDE {
|
::grpc::Status Retrieve(::grpc::ServerContext* context, const flatbuffers::BufferRef<Stat>* request, ::grpc::ServerWriter< flatbuffers::BufferRef<Monster>>* writer) final override {
|
||||||
abort();
|
abort();
|
||||||
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
|
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
template <class BaseClass>
|
||||||
|
class WithStreamedUnaryMethod_Store : public BaseClass {
|
||||||
|
private:
|
||||||
|
void BaseClassMustBeDerivedFromService(const Service *service) {}
|
||||||
|
public:
|
||||||
|
WithStreamedUnaryMethod_Store() {
|
||||||
|
::grpc::Service::MarkMethodStreamed(0,
|
||||||
|
new ::grpc::StreamedUnaryHandler< flatbuffers::BufferRef<Monster>, flatbuffers::BufferRef<Stat>>(std::bind(&WithStreamedUnaryMethod_Store<BaseClass>::StreamedStore, this, std::placeholders::_1, std::placeholders::_2)));
|
||||||
|
}
|
||||||
|
~WithStreamedUnaryMethod_Store() override {
|
||||||
|
BaseClassMustBeDerivedFromService(this);
|
||||||
|
}
|
||||||
|
// disable regular version of this method
|
||||||
|
::grpc::Status Store(::grpc::ServerContext* context, const flatbuffers::BufferRef<Monster>* request, flatbuffers::BufferRef<Stat>* response) final override {
|
||||||
|
abort();
|
||||||
|
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
|
||||||
|
}
|
||||||
|
// replace default version of method with streamed unary
|
||||||
|
virtual ::grpc::Status StreamedStore(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< flatbuffers::BufferRef<Monster>,flatbuffers::BufferRef<Stat>>* server_unary_streamer) = 0;
|
||||||
|
};
|
||||||
|
typedef WithStreamedUnaryMethod_Store< Service > StreamedUnaryService;
|
||||||
|
template <class BaseClass>
|
||||||
|
class WithSplitStreamingMethod_Retrieve : public BaseClass {
|
||||||
|
private:
|
||||||
|
void BaseClassMustBeDerivedFromService(const Service *service) {}
|
||||||
|
public:
|
||||||
|
WithSplitStreamingMethod_Retrieve() {
|
||||||
|
::grpc::Service::MarkMethodStreamed(1,
|
||||||
|
new ::grpc::SplitServerStreamingHandler< flatbuffers::BufferRef<Stat>, flatbuffers::BufferRef<Monster>>(std::bind(&WithSplitStreamingMethod_Retrieve<BaseClass>::StreamedRetrieve, this, std::placeholders::_1, std::placeholders::_2)));
|
||||||
|
}
|
||||||
|
~WithSplitStreamingMethod_Retrieve() override {
|
||||||
|
BaseClassMustBeDerivedFromService(this);
|
||||||
|
}
|
||||||
|
// disable regular version of this method
|
||||||
|
::grpc::Status Retrieve(::grpc::ServerContext* context, const flatbuffers::BufferRef<Stat>* request, ::grpc::ServerWriter< flatbuffers::BufferRef<Monster>>* writer) final override {
|
||||||
|
abort();
|
||||||
|
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
|
||||||
|
}
|
||||||
|
// replace default version of method with split streamed
|
||||||
|
virtual ::grpc::Status StreamedRetrieve(::grpc::ServerContext* context, ::grpc::ServerSplitStreamer< flatbuffers::BufferRef<Stat>,flatbuffers::BufferRef<Monster>>* server_split_streamer) = 0;
|
||||||
|
};
|
||||||
|
typedef WithSplitStreamingMethod_Retrieve< Service > SplitStreamedService;
|
||||||
|
typedef WithStreamedUnaryMethod_Store< WithSplitStreamingMethod_Retrieve< Service > > StreamedService;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Example
|
} // namespace Example
|
||||||
|
|||||||
Reference in New Issue
Block a user