forked from BigfootDev/flatbuffers
Use the Google Style for clang-format without exceptions (#8706)
This reduces the friction when merging from github and google repos by using the exact same clang style guide. MARKDOWN=true
This commit is contained in:
@@ -24,8 +24,8 @@
|
||||
#include <vector>
|
||||
|
||||
#ifndef GRPC_CUSTOM_STRING
|
||||
# include <string>
|
||||
# define GRPC_CUSTOM_STRING std::string
|
||||
#include <string>
|
||||
#define GRPC_CUSTOM_STRING std::string
|
||||
#endif
|
||||
|
||||
namespace grpc {
|
||||
@@ -55,10 +55,10 @@ struct Method : public CommentHolder {
|
||||
virtual grpc::string output_type_name() const = 0;
|
||||
|
||||
virtual bool get_module_and_message_path_input(
|
||||
grpc::string *str, grpc::string generator_file_name,
|
||||
grpc::string* str, grpc::string generator_file_name,
|
||||
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,
|
||||
grpc::string* str, grpc::string generator_file_name,
|
||||
bool generate_in_pb2_grpc, grpc::string import_prefix) const = 0;
|
||||
|
||||
virtual std::vector<grpc::string> get_input_namespace_parts() const = 0;
|
||||
@@ -89,9 +89,9 @@ struct Service : public CommentHolder {
|
||||
struct Printer {
|
||||
virtual ~Printer() {}
|
||||
|
||||
virtual void Print(const std::map<grpc::string, grpc::string> &vars,
|
||||
const char *template_string) = 0;
|
||||
virtual void Print(const char *string) = 0;
|
||||
virtual void Print(const std::map<grpc::string, grpc::string>& vars,
|
||||
const char* template_string) = 0;
|
||||
virtual void Print(const char* string) = 0;
|
||||
virtual void SetIndentationSize(const size_t size) = 0;
|
||||
virtual void Indent() = 0;
|
||||
virtual void Outdent() = 0;
|
||||
@@ -112,7 +112,7 @@ struct File : public CommentHolder {
|
||||
virtual std::unique_ptr<const Service> service(int i) const = 0;
|
||||
|
||||
virtual std::unique_ptr<Printer> CreatePrinter(
|
||||
grpc::string *str, const char indentation_type = ' ') const = 0;
|
||||
grpc::string* str, const char indentation_type = ' ') const = 0;
|
||||
};
|
||||
} // namespace grpc_generator
|
||||
|
||||
|
||||
@@ -33,9 +33,9 @@ void message_builder_tests();
|
||||
// code. It implements all rpcs specified in the FlatBuffers schema.
|
||||
class ServiceImpl final : public MyGame::Example::MonsterStorage::Service {
|
||||
virtual ::grpc::Status Store(
|
||||
::grpc::ServerContext *context,
|
||||
const flatbuffers::grpc::Message<Monster> *request,
|
||||
flatbuffers::grpc::Message<Stat> *response) override {
|
||||
::grpc::ServerContext* context,
|
||||
const flatbuffers::grpc::Message<Monster>* request,
|
||||
flatbuffers::grpc::Message<Stat>* response) override {
|
||||
// Create a response from the incoming request name.
|
||||
fbb_.Clear();
|
||||
auto stat_offset = CreateStat(
|
||||
@@ -46,9 +46,9 @@ class ServiceImpl final : public MyGame::Example::MonsterStorage::Service {
|
||||
return grpc::Status::OK;
|
||||
}
|
||||
virtual ::grpc::Status Retrieve(
|
||||
::grpc::ServerContext *context,
|
||||
const flatbuffers::grpc::Message<Stat> *request,
|
||||
::grpc::ServerWriter<flatbuffers::grpc::Message<Monster>> *writer)
|
||||
::grpc::ServerContext* context,
|
||||
const flatbuffers::grpc::Message<Stat>* request,
|
||||
::grpc::ServerWriter<flatbuffers::grpc::Message<Monster>>* writer)
|
||||
override {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
fbb_.Clear();
|
||||
@@ -73,7 +73,7 @@ class ServiceImpl final : public MyGame::Example::MonsterStorage::Service {
|
||||
};
|
||||
|
||||
// Track the server instance, so we can terminate it later.
|
||||
grpc::Server *server_instance = nullptr;
|
||||
grpc::Server* server_instance = nullptr;
|
||||
// Mutex to protec this variable.
|
||||
std::mutex wait_for_server;
|
||||
std::condition_variable server_instance_cv;
|
||||
@@ -98,7 +98,8 @@ void RunServer() {
|
||||
server_instance->Wait();
|
||||
}
|
||||
|
||||
template<class Builder> void StoreRPC(MonsterStorage::Stub *stub) {
|
||||
template <class Builder>
|
||||
void StoreRPC(MonsterStorage::Stub* stub) {
|
||||
Builder fbb;
|
||||
grpc::ClientContext context;
|
||||
// Build a request with the name set.
|
||||
@@ -119,7 +120,8 @@ template<class Builder> void StoreRPC(MonsterStorage::Stub *stub) {
|
||||
}
|
||||
}
|
||||
|
||||
template<class Builder> void RetrieveRPC(MonsterStorage::Stub *stub) {
|
||||
template <class Builder>
|
||||
void RetrieveRPC(MonsterStorage::Stub* stub) {
|
||||
Builder fbb;
|
||||
grpc::ClientContext context;
|
||||
fbb.Clear();
|
||||
@@ -179,7 +181,7 @@ int grpc_server_test() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int /*argc*/, const char * /*argv*/[]) {
|
||||
int main(int /*argc*/, const char* /*argv*/[]) {
|
||||
message_builder_tests();
|
||||
grpc_server_test();
|
||||
|
||||
|
||||
@@ -15,44 +15,43 @@ 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> *,
|
||||
::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");
|
||||
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::ClientContext*,
|
||||
const flatbuffers::grpc::Message<Stat>&,
|
||||
::grpc::ClientReadReactor<flatbuffers::grpc::Message<
|
||||
Monster> > *)>(&Stub::async_Retrieve))>::value,
|
||||
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::ClientContext*, flatbuffers::grpc::Message<Stat>*,
|
||||
::grpc::ClientWriteReactor<flatbuffers::grpc::Message<
|
||||
Monster> > *)>(&Stub::async_GetMaxHitPoint))>::value,
|
||||
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::ClientContext*,
|
||||
::grpc::ClientBidiReactor<
|
||||
flatbuffers::grpc::Message<Monster>,
|
||||
flatbuffers::grpc::Message<Stat> > *)>(
|
||||
flatbuffers::grpc::Message<Stat> >*)>(
|
||||
&Stub::async_GetMinMaxHitPoints))>::value,
|
||||
"Bidi streaming reactor async_GetMinMaxHitPoints missing");
|
||||
#endif // FLATBUFFERS_GENERATED_GRPC_CALLBACK_API &&
|
||||
|
||||
@@ -7,9 +7,9 @@ using MyGame::Example::Any_NONE;
|
||||
using MyGame::Example::CreateStat;
|
||||
using MyGame::Example::Vec3;
|
||||
|
||||
bool verify(flatbuffers::grpc::Message<Monster> &msg,
|
||||
const std::string &expected_name, Color expected_color) {
|
||||
const Monster *monster = msg.GetRoot();
|
||||
bool verify(flatbuffers::grpc::Message<Monster>& msg,
|
||||
const std::string& expected_name, Color expected_color) {
|
||||
const Monster* monster = msg.GetRoot();
|
||||
const auto name = monster->name()->str();
|
||||
const auto color = monster->color();
|
||||
TEST_EQ(name, expected_name);
|
||||
@@ -17,8 +17,8 @@ bool verify(flatbuffers::grpc::Message<Monster> &msg,
|
||||
return (name == expected_name) && (color == expected_color);
|
||||
}
|
||||
|
||||
bool release_n_verify(flatbuffers::grpc::MessageBuilder &mbb,
|
||||
const std::string &expected_name, Color expected_color) {
|
||||
bool release_n_verify(flatbuffers::grpc::MessageBuilder& mbb,
|
||||
const std::string& expected_name, Color expected_color) {
|
||||
flatbuffers::grpc::Message<Monster> msg = mbb.ReleaseMessage<Monster>();
|
||||
return verify(msg, expected_name, expected_color);
|
||||
}
|
||||
@@ -41,11 +41,13 @@ void builder_move_assign_after_releaseraw_test(
|
||||
TEST_EQ(src.GetSize(), 0);
|
||||
}
|
||||
|
||||
template<class SrcBuilder>
|
||||
template <class SrcBuilder>
|
||||
struct BuilderReuseTests<flatbuffers::grpc::MessageBuilder, SrcBuilder> {
|
||||
static void builder_reusable_after_release_message_test(
|
||||
TestSelector selector) {
|
||||
if (!selector.count(REUSABLE_AFTER_RELEASE_MESSAGE)) { return; }
|
||||
if (!selector.count(REUSABLE_AFTER_RELEASE_MESSAGE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
flatbuffers::grpc::MessageBuilder mb;
|
||||
std::vector<flatbuffers::grpc::Message<Monster>> buffers;
|
||||
@@ -58,7 +60,9 @@ struct BuilderReuseTests<flatbuffers::grpc::MessageBuilder, SrcBuilder> {
|
||||
}
|
||||
|
||||
static void builder_reusable_after_release_test(TestSelector selector) {
|
||||
if (!selector.count(REUSABLE_AFTER_RELEASE)) { return; }
|
||||
if (!selector.count(REUSABLE_AFTER_RELEASE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME: Populate-Release loop fails assert(GRPC_SLICE_IS_EMPTY(slice_)) in
|
||||
// SliceAllocator::allocate in the second iteration.
|
||||
@@ -74,7 +78,9 @@ struct BuilderReuseTests<flatbuffers::grpc::MessageBuilder, SrcBuilder> {
|
||||
}
|
||||
|
||||
static void builder_reusable_after_releaseraw_test(TestSelector selector) {
|
||||
if (!selector.count(REUSABLE_AFTER_RELEASE_RAW)) { return; }
|
||||
if (!selector.count(REUSABLE_AFTER_RELEASE_RAW)) {
|
||||
return;
|
||||
}
|
||||
|
||||
flatbuffers::grpc::MessageBuilder mb;
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
@@ -82,14 +88,16 @@ struct BuilderReuseTests<flatbuffers::grpc::MessageBuilder, SrcBuilder> {
|
||||
mb.Finish(root_offset1);
|
||||
size_t size, offset;
|
||||
::grpc::Slice slice;
|
||||
const uint8_t *buf = mb.ReleaseRaw(size, offset, slice);
|
||||
const uint8_t* buf = mb.ReleaseRaw(size, offset, slice);
|
||||
TEST_ASSERT_FUNC(verify(buf, offset, m1_name(), m1_color()));
|
||||
}
|
||||
}
|
||||
|
||||
static void builder_reusable_after_release_and_move_assign_test(
|
||||
TestSelector selector) {
|
||||
if (!selector.count(REUSABLE_AFTER_RELEASE_AND_MOVE_ASSIGN)) { return; }
|
||||
if (!selector.count(REUSABLE_AFTER_RELEASE_AND_MOVE_ASSIGN)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME: Release-move_assign loop fails assert(p ==
|
||||
// GRPC_SLICE_START_PTR(slice_)) in DetachedBuffer destructor after all the
|
||||
@@ -137,7 +145,9 @@ struct BuilderReuseTests<flatbuffers::grpc::MessageBuilder, SrcBuilder> {
|
||||
|
||||
static void builder_reusable_after_releaseraw_and_move_assign_test(
|
||||
TestSelector selector) {
|
||||
if (!selector.count(REUSABLE_AFTER_RELEASE_RAW_AND_MOVE_ASSIGN)) { return; }
|
||||
if (!selector.count(REUSABLE_AFTER_RELEASE_RAW_AND_MOVE_ASSIGN)) {
|
||||
return;
|
||||
}
|
||||
|
||||
flatbuffers::grpc::MessageBuilder dst;
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
@@ -145,7 +155,7 @@ struct BuilderReuseTests<flatbuffers::grpc::MessageBuilder, SrcBuilder> {
|
||||
dst.Finish(root_offset1);
|
||||
size_t size, offset;
|
||||
::grpc::Slice slice;
|
||||
const uint8_t *buf = dst.ReleaseRaw(size, offset, slice);
|
||||
const uint8_t* buf = dst.ReleaseRaw(size, offset, slice);
|
||||
TEST_ASSERT_FUNC(verify(buf, offset, m1_name(), m1_color()));
|
||||
|
||||
SrcBuilder src;
|
||||
@@ -170,7 +180,7 @@ void slice_allocator_tests() {
|
||||
{
|
||||
size_t size = 2048;
|
||||
flatbuffers::grpc::SliceAllocator sa1;
|
||||
uint8_t *buf = sa1.allocate(size);
|
||||
uint8_t* buf = sa1.allocate(size);
|
||||
TEST_ASSERT_FUNC(buf != 0);
|
||||
buf[0] = 100;
|
||||
buf[size - 1] = 200;
|
||||
@@ -184,7 +194,7 @@ void slice_allocator_tests() {
|
||||
// move-assign test
|
||||
{
|
||||
flatbuffers::grpc::SliceAllocator sa1, sa2;
|
||||
uint8_t *buf = sa1.allocate(2048);
|
||||
uint8_t* buf = sa1.allocate(2048);
|
||||
sa1 = std::move(sa2);
|
||||
// sa1 deletes previously allocated memory in move-assign.
|
||||
// So buf is no longer usable here.
|
||||
@@ -194,7 +204,7 @@ void slice_allocator_tests() {
|
||||
|
||||
/// This function does not populate exactly the first half of the table. But it
|
||||
/// could.
|
||||
void populate_first_half(MyGame::Example::MonsterBuilder &wrapper,
|
||||
void populate_first_half(MyGame::Example::MonsterBuilder& wrapper,
|
||||
flatbuffers::Offset<flatbuffers::String> name_offset) {
|
||||
wrapper.add_name(name_offset);
|
||||
wrapper.add_color(m1_color());
|
||||
@@ -202,7 +212,7 @@ void populate_first_half(MyGame::Example::MonsterBuilder &wrapper,
|
||||
|
||||
/// This function does not populate exactly the second half of the table. But it
|
||||
/// could.
|
||||
void populate_second_half(MyGame::Example::MonsterBuilder &wrapper) {
|
||||
void populate_second_half(MyGame::Example::MonsterBuilder& wrapper) {
|
||||
wrapper.add_hp(77);
|
||||
wrapper.add_mana(88);
|
||||
Vec3 vec3;
|
||||
@@ -216,9 +226,9 @@ void populate_second_half(MyGame::Example::MonsterBuilder &wrapper) {
|
||||
/// between FlatBufferBuilders. If MonsterBuilder had a fbb_ pointer, this hack
|
||||
/// would be unnecessary. That involves a code-generator change though.
|
||||
void test_only_hack_update_fbb_reference(
|
||||
MyGame::Example::MonsterBuilder &monsterBuilder,
|
||||
flatbuffers::grpc::MessageBuilder &mb) {
|
||||
*reinterpret_cast<flatbuffers::FlatBufferBuilder **>(&monsterBuilder) = &mb;
|
||||
MyGame::Example::MonsterBuilder& monsterBuilder,
|
||||
flatbuffers::grpc::MessageBuilder& mb) {
|
||||
*reinterpret_cast<flatbuffers::FlatBufferBuilder**>(&monsterBuilder) = &mb;
|
||||
}
|
||||
|
||||
/// This test validates correctness of move conversion of FlatBufferBuilder to a
|
||||
@@ -351,15 +361,14 @@ void message_builder_tests() {
|
||||
BuilderTests<MessageBuilder, FlatBufferBuilder>::all_tests();
|
||||
|
||||
BuilderReuseTestSelector tests[6] = {
|
||||
// REUSABLE_AFTER_RELEASE, // Assertion failed:
|
||||
// (GRPC_SLICE_IS_EMPTY(slice_))
|
||||
// REUSABLE_AFTER_RELEASE_AND_MOVE_ASSIGN, // Assertion failed: (p ==
|
||||
// GRPC_SLICE_START_PTR(slice_)
|
||||
// REUSABLE_AFTER_RELEASE, // Assertion failed:
|
||||
// (GRPC_SLICE_IS_EMPTY(slice_))
|
||||
// REUSABLE_AFTER_RELEASE_AND_MOVE_ASSIGN, // Assertion failed: (p ==
|
||||
// GRPC_SLICE_START_PTR(slice_)
|
||||
|
||||
REUSABLE_AFTER_RELEASE_RAW, REUSABLE_AFTER_RELEASE_MESSAGE,
|
||||
REUSABLE_AFTER_RELEASE_MESSAGE_AND_MOVE_ASSIGN,
|
||||
REUSABLE_AFTER_RELEASE_RAW_AND_MOVE_ASSIGN
|
||||
};
|
||||
REUSABLE_AFTER_RELEASE_RAW, REUSABLE_AFTER_RELEASE_MESSAGE,
|
||||
REUSABLE_AFTER_RELEASE_MESSAGE_AND_MOVE_ASSIGN,
|
||||
REUSABLE_AFTER_RELEASE_RAW_AND_MOVE_ASSIGN};
|
||||
|
||||
BuilderReuseTests<MessageBuilder, MessageBuilder>::run_tests(
|
||||
TestSelector(tests, tests + 6));
|
||||
|
||||
Reference in New Issue
Block a user