Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
---
Language: Cpp
BasedOnStyle: Google
DerivePointerAlignment: false
PointerAlignment: Right
IndentPPDirectives: AfterHash
Cpp11BracedListStyle: false
AlwaysBreakTemplateDeclarations: false
AllowShortCaseLabelsOnASingleLine: true
SpaceAfterTemplateKeyword: false
AllowShortBlocksOnASingleLine: true
...

4 changes: 4 additions & 0 deletions goldens/swift/basic_generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// swiftlint:disable all
// swiftformat:disable all

#if canImport(Common)
import Common
#endif

import FlatBuffers

public struct flatbuffers_goldens_Galaxy: FlatBufferObject, Verifiable {
Expand Down
16 changes: 8 additions & 8 deletions grpc/src/compiler/schema_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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

Expand Down
22 changes: 12 additions & 10 deletions grpc/tests/grpctest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -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.
Expand All @@ -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();
Expand Down Expand Up @@ -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();

Expand Down
37 changes: 18 additions & 19 deletions grpc/tests/grpctest_callback_client_compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
67 changes: 38 additions & 29 deletions grpc/tests/message_builder_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ 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);
TEST_EQ(color, expected_color);
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);
}
Expand All @@ -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;
Expand All @@ -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.
Expand All @@ -74,22 +78,26 @@ 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) {
auto root_offset1 = populate1(mb);
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
Expand Down Expand Up @@ -137,15 +145,17 @@ 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) {
auto root_offset1 = populate1(dst);
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;
Expand All @@ -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;
Expand All @@ -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.
Expand All @@ -194,15 +204,15 @@ 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());
}

/// 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;
Expand All @@ -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
Expand Down Expand Up @@ -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_RAW, REUSABLE_AFTER_RELEASE_MESSAGE,
REUSABLE_AFTER_RELEASE_MESSAGE_AND_MOVE_ASSIGN,
REUSABLE_AFTER_RELEASE_RAW_AND_MOVE_ASSIGN
};
// 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};

BuilderReuseTests<MessageBuilder, MessageBuilder>::run_tests(
TestSelector(tests, tests + 6));
Expand Down
Loading
Loading