mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-06 12:36:54 +00:00
gRPC callbackService support added (#8666)
* grpc callbackService support added Signed-off-by: shankeleven <shashanksati11@gmail.com> * tests: regenerate C++ gRPC golden with --grpc-callback-api (CallbackService & async_ reactor APIs); update formatting and method placement --------- Signed-off-by: shankeleven <shashanksati11@gmail.com> Co-authored-by: Wouter van Oortmerssen <aardappel@gmail.com>
This commit is contained in:
@@ -17,3 +17,27 @@ cc_test(
|
||||
"@com_github_grpc_grpc//:grpc++",
|
||||
],
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "grpc_callback_compile_test",
|
||||
srcs = ["grpctest_callback_compile.cpp"],
|
||||
copts = ["-Itests"],
|
||||
linkstatic = 1,
|
||||
deps = [
|
||||
"//tests:monster_test_cc_fbs",
|
||||
"//tests:monster_test_grpc",
|
||||
"@com_github_grpc_grpc//:grpc++",
|
||||
],
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "grpc_callback_client_compile_test",
|
||||
srcs = ["grpctest_callback_client_compile.cpp"],
|
||||
copts = ["-Itests"],
|
||||
linkstatic = 1,
|
||||
deps = [
|
||||
"//tests:monster_test_cc_fbs",
|
||||
"//tests:monster_test_grpc",
|
||||
"@com_github_grpc_grpc//:grpc++",
|
||||
],
|
||||
)
|
||||
|
||||
61
grpc/tests/grpctest_callback_client_compile.cpp
Normal file
61
grpc/tests/grpctest_callback_client_compile.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
// Verifies that the generated gRPC callback client stub methods are present.
|
||||
// This is a compile-time only test: it never performs an actual RPC.
|
||||
// It supplements grpctest_callback_compile.cpp (server side) by checking
|
||||
// client-side async_ / reactor entry points.
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include "monster_test.grpc.fb.h"
|
||||
|
||||
#if defined(FLATBUFFERS_GENERATED_GRPC_CALLBACK_API) && \
|
||||
defined(GRPC_CALLBACK_API_NONEXPERIMENTAL)
|
||||
using Stub = MyGame::Example::MonsterStorage::Stub;
|
||||
using namespace MyGame::Example; // NOLINT
|
||||
|
||||
// Unary async overloads
|
||||
static_assert(std::is_member_function_pointer<
|
||||
decltype(static_cast<void (Stub::*)(
|
||||
::grpc::ClientContext *,
|
||||
const flatbuffers::grpc::Message<Monster> &,
|
||||
flatbuffers::grpc::Message<Stat> *,
|
||||
std::function<void(::grpc::Status)>)>(
|
||||
&Stub::async_Store))>::value,
|
||||
"Function-form unary async_Store missing");
|
||||
static_assert(std::is_member_function_pointer<
|
||||
decltype(static_cast<void (Stub::*)(
|
||||
::grpc::ClientContext *,
|
||||
const flatbuffers::grpc::Message<Monster> &,
|
||||
flatbuffers::grpc::Message<Stat> *,
|
||||
::grpc::ClientUnaryReactor *)>(
|
||||
&Stub::async_Store))>::value,
|
||||
"Reactor-form unary async_Store missing");
|
||||
|
||||
// Streaming reactor entry points
|
||||
static_assert(
|
||||
std::is_member_function_pointer<
|
||||
decltype(static_cast<void (Stub::*)(
|
||||
::grpc::ClientContext *,
|
||||
const flatbuffers::grpc::Message<Stat> &,
|
||||
::grpc::ClientReadReactor<flatbuffers::grpc::Message<
|
||||
Monster> > *)>(&Stub::async_Retrieve))>::value,
|
||||
"Server streaming reactor async_Retrieve missing");
|
||||
static_assert(
|
||||
std::is_member_function_pointer<
|
||||
decltype(static_cast<void (Stub::*)(
|
||||
::grpc::ClientContext *,
|
||||
flatbuffers::grpc::Message<Stat> *,
|
||||
::grpc::ClientWriteReactor<flatbuffers::grpc::Message<
|
||||
Monster> > *)>(&Stub::async_GetMaxHitPoint))>::value,
|
||||
"Client streaming reactor async_GetMaxHitPoint missing");
|
||||
static_assert(std::is_member_function_pointer<
|
||||
decltype(static_cast<void (Stub::*)(
|
||||
::grpc::ClientContext *,
|
||||
::grpc::ClientBidiReactor<
|
||||
flatbuffers::grpc::Message<Monster>,
|
||||
flatbuffers::grpc::Message<Stat> > *)>(
|
||||
&Stub::async_GetMinMaxHitPoints))>::value,
|
||||
"Bidi streaming reactor async_GetMinMaxHitPoints missing");
|
||||
#endif // FLATBUFFERS_GENERATED_GRPC_CALLBACK_API &&
|
||||
// GRPC_CALLBACK_API_NONEXPERIMENTAL
|
||||
|
||||
int main() { return 0; }
|
||||
22
grpc/tests/grpctest_callback_compile.cpp
Normal file
22
grpc/tests/grpctest_callback_compile.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "monster_test.grpc.fb.h"
|
||||
|
||||
// This test only verifies that the generated CallbackService compiles when the
|
||||
// callback API is available. It does not run any RPCs.
|
||||
|
||||
#if defined(FLATBUFFERS_GENERATED_GRPC_CALLBACK_API) && \
|
||||
defined(GRPC_CALLBACK_API_NONEXPERIMENTAL)
|
||||
class CallbackServiceImpl
|
||||
: public MyGame::Example::MonsterStorage::CallbackService {
|
||||
public:
|
||||
// For brevity we don't override methods; user code will provide reactors.
|
||||
};
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
#if defined(FLATBUFFERS_GENERATED_GRPC_CALLBACK_API) && \
|
||||
defined(GRPC_CALLBACK_API_NONEXPERIMENTAL)
|
||||
CallbackServiceImpl svc;
|
||||
(void)svc; // suppress unused
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user