mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-01 19:58:15 +00:00
Run clang-format -i **/*.cpp (#8865)
This commit is contained in:
@@ -15,15 +15,17 @@
|
||||
*/
|
||||
|
||||
#include <jni.h>
|
||||
#include <string>
|
||||
#include <search.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "generated/animal_generated.h"
|
||||
|
||||
using namespace com::fbs::app;
|
||||
using namespace flatbuffers;
|
||||
|
||||
extern "C" JNIEXPORT jbyteArray JNICALL Java_com_flatbuffers_app_MainActivity_createAnimalFromJNI(
|
||||
JNIEnv* env,
|
||||
extern "C" JNIEXPORT jbyteArray JNICALL
|
||||
Java_com_flatbuffers_app_MainActivity_createAnimalFromJNI(JNIEnv* env,
|
||||
jobject /* this */) {
|
||||
// create a new animal flatbuffers
|
||||
auto fb = FlatBufferBuilder(1024);
|
||||
|
||||
@@ -33,7 +33,9 @@ static inline void Use(benchmark::State &state, std::unique_ptr<Bench> &bench,
|
||||
|
||||
int64_t sum = 0;
|
||||
|
||||
for (auto _ : state) { sum = bench->Use(decoded); }
|
||||
for (auto _ : state) {
|
||||
sum = bench->Use(decoded);
|
||||
}
|
||||
|
||||
EXPECT_EQ(sum, check_sum);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include "greeter.grpc.fb.h"
|
||||
#include "greeter_generated.h"
|
||||
|
||||
#include <grpcpp/grpcpp.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "greeter.grpc.fb.h"
|
||||
#include "greeter_generated.h"
|
||||
|
||||
class GreeterClient {
|
||||
public:
|
||||
GreeterClient(std::shared_ptr<grpc::Channel> channel)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include "greeter.grpc.fb.h"
|
||||
#include "greeter_generated.h"
|
||||
|
||||
#include <grpcpp/grpcpp.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "greeter.grpc.fb.h"
|
||||
#include "greeter_generated.h"
|
||||
|
||||
class GreeterServiceImpl final : public Greeter::Service {
|
||||
virtual grpc::Status SayHello(
|
||||
grpc::ServerContext* context,
|
||||
|
||||
@@ -470,7 +470,8 @@ class FlatBufferBuilderImpl {
|
||||
for (auto it = buf_.scratch_data(); it < buf_.scratch_end();
|
||||
it += sizeof(uoffset_t)) {
|
||||
auto vt_offset_ptr = reinterpret_cast<uoffset_t*>(it);
|
||||
auto vt2 = reinterpret_cast<voffset_t *>(buf_.data_at(*vt_offset_ptr + length_of_64_bit_region_));
|
||||
auto vt2 = reinterpret_cast<voffset_t*>(
|
||||
buf_.data_at(*vt_offset_ptr + length_of_64_bit_region_));
|
||||
auto vt2_size = ReadScalar<voffset_t>(vt2);
|
||||
if (vt1_size != vt2_size || 0 != memcmp(vt2, vt1, vt1_size)) continue;
|
||||
vt_use = *vt_offset_ptr;
|
||||
|
||||
@@ -410,7 +410,6 @@ FLATBUFFERS_CONSTEXPR_CPP11 flatbuffers::span<const U> make_structs_span(
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// Represent a vector much like the template above, but in this case we
|
||||
// don't know what the element types are (used with reflection.h).
|
||||
class VectorOfAny {
|
||||
|
||||
@@ -14,12 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "flatbuffers/file_manager.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "flatbuffers/file_manager.h"
|
||||
|
||||
namespace flatbuffers {
|
||||
|
||||
bool RealFileSaver::SaveFile(const char* name, const char* buf, size_t len,
|
||||
|
||||
@@ -652,17 +652,21 @@ class CSharpGenerator : public BaseGenerator {
|
||||
// Get the getter for the key of the struct.
|
||||
if (IsString(key_field->value.type)) {
|
||||
return "string.CompareOrdinal(" +
|
||||
GenGetterForLookupByKey(struct_def, key_field, "builder.DataBuffer",
|
||||
GenGetterForLookupByKey(struct_def, key_field,
|
||||
"builder.DataBuffer",
|
||||
"builder.DataBuffer.Length - o1.Value") +
|
||||
", " +
|
||||
GenGetterForLookupByKey(struct_def, key_field, "builder.DataBuffer",
|
||||
GenGetterForLookupByKey(struct_def, key_field,
|
||||
"builder.DataBuffer",
|
||||
"builder.DataBuffer.Length - o2.Value") +
|
||||
")";
|
||||
} else {
|
||||
return GenGetterForLookupByKey(struct_def, key_field, "builder.DataBuffer",
|
||||
return GenGetterForLookupByKey(struct_def, key_field,
|
||||
"builder.DataBuffer",
|
||||
"builder.DataBuffer.Length - o1.Value") +
|
||||
".CompareTo(" +
|
||||
GenGetterForLookupByKey(struct_def, key_field, "builder.DataBuffer",
|
||||
GenGetterForLookupByKey(struct_def, key_field,
|
||||
"builder.DataBuffer",
|
||||
"builder.DataBuffer.Length - o2.Value") +
|
||||
")";
|
||||
}
|
||||
@@ -1596,7 +1600,8 @@ class CSharpGenerator : public BaseGenerator {
|
||||
|
||||
code += " obj_.__assign(tableOffset, bb);\n";
|
||||
if (IsString(key_field->value.type)) {
|
||||
code += " int comp = string.CompareOrdinal(obj_." + name + ", key);\n";
|
||||
code +=
|
||||
" int comp = string.CompareOrdinal(obj_." + name + ", key);\n";
|
||||
} else {
|
||||
code += " int comp = obj_." + name + ".CompareTo(key);\n";
|
||||
}
|
||||
|
||||
@@ -1468,7 +1468,8 @@ class JavaGenerator : public BaseGenerator {
|
||||
" " + variable_name + "Type = " + field_name + "Type(" +
|
||||
type_params + ");\n";
|
||||
code += indent + variable_name + ".setType(" + variable_name + "Type);\n";
|
||||
code += indent + "com.google.flatbuffers.Table " + variable_name + "Value;\n";
|
||||
code +=
|
||||
indent + "com.google.flatbuffers.Table " + variable_name + "Value;\n";
|
||||
code += indent + "switch (" + variable_name + "Type) {\n";
|
||||
for (auto eit = enum_def.Vals().begin(); eit != enum_def.Vals().end();
|
||||
++eit) {
|
||||
|
||||
@@ -1216,8 +1216,8 @@ class KotlinGenerator : public BaseGenerator {
|
||||
// fun inventoryInByteBuffer(_bb: Bytebuffer):
|
||||
// ByteBuffer? = __vector_as_bytebuffer(_bb, 14, 1)
|
||||
GenerateFunOneLine(
|
||||
writer, field_name + "InByteBuffer", "_bb: ByteBuffer",
|
||||
buffer_type, [&]() {
|
||||
writer, field_name + "InByteBuffer", "_bb: ByteBuffer", buffer_type,
|
||||
[&]() {
|
||||
writer.SetValue("end", end_idx);
|
||||
writer += "__vector_in_bytebuffer(_bb, {{offset}}, {{end}})";
|
||||
});
|
||||
|
||||
@@ -2885,8 +2885,7 @@ class PythonGenerator : public BaseGenerator {
|
||||
EnsureDirExists(directories);
|
||||
|
||||
for (size_t i = directories.find(kPathSeparator, path_.size());
|
||||
i != std::string::npos;
|
||||
i = directories.find(kPathSeparator, i + 1)) {
|
||||
i != std::string::npos; i = directories.find(kPathSeparator, i + 1)) {
|
||||
const std::string init_py =
|
||||
directories.substr(0, i) + kPathSeparator + "__init__.py";
|
||||
parser_.opts.file_saver->SaveFile(init_py.c_str(), "", false);
|
||||
@@ -2913,7 +2912,8 @@ static const char* GeneratePython(const Parser& parser, const std::string& path,
|
||||
|
||||
if (parser.opts.python_typing) {
|
||||
python::PythonStubGenerator stub_generator(parser, path, version);
|
||||
if (!stub_generator.Generate()) return "could not generate Python type stubs";
|
||||
if (!stub_generator.Generate())
|
||||
return "could not generate Python type stubs";
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -2948,7 +2948,8 @@ class PythonCodeGenerator : public CodeGenerator {
|
||||
|
||||
Status GenerateGrpcCode(const Parser& parser, const std::string& path,
|
||||
const std::string& filename) override {
|
||||
if (!GeneratePythonGRPC(parser, path, filename)) { // TODO add status GeneratePythonGRPC
|
||||
if (!GeneratePythonGRPC(parser, path,
|
||||
filename)) { // TODO add status GeneratePythonGRPC
|
||||
return Status::ERROR;
|
||||
}
|
||||
return Status::OK;
|
||||
|
||||
@@ -1347,7 +1347,8 @@ class SwiftGenerator : public BaseGenerator {
|
||||
}
|
||||
|
||||
void GenerateObjectAPIStructConstructor(const StructDef& struct_def) {
|
||||
code_ += "{{ACCESS_TYPE}} init(_ _t: borrowing {{STRUCTNAME}}" + Mutable() + ") {";
|
||||
code_ += "{{ACCESS_TYPE}} init(_ _t: borrowing {{STRUCTNAME}}" + Mutable() +
|
||||
") {";
|
||||
Indent();
|
||||
for (auto it = struct_def.fields.vec.begin();
|
||||
it != struct_def.fields.vec.end(); ++it) {
|
||||
@@ -1393,7 +1394,8 @@ class SwiftGenerator : public BaseGenerator {
|
||||
base_constructor);
|
||||
}
|
||||
code_ += "";
|
||||
BuildObjectConstructor(buffer_constructor,
|
||||
BuildObjectConstructor(
|
||||
buffer_constructor,
|
||||
"_ _t: borrowing " + namer_.NamespacedType(struct_def));
|
||||
BuildObjectConstructor(base_constructor);
|
||||
if (!struct_def.fixed)
|
||||
|
||||
@@ -339,8 +339,7 @@ class TsGenerator : public BaseGenerator {
|
||||
for (auto it = dc.begin(); it != dc.end(); ++it) {
|
||||
if (indent) code += indent;
|
||||
std::string safe = *it;
|
||||
for (size_t pos = 0;
|
||||
(pos = safe.find("*/", pos)) != std::string::npos;) {
|
||||
for (size_t pos = 0; (pos = safe.find("*/", pos)) != std::string::npos;) {
|
||||
safe.replace(pos, 2, "*\\/");
|
||||
pos += 3;
|
||||
}
|
||||
|
||||
@@ -1,31 +1,32 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include "flatbuffers/idl.h" // For Parser and generation functions
|
||||
#include "test_init.h"
|
||||
#include <memory>
|
||||
#include <bfbs_gen_lua.h>
|
||||
#include <bfbs_gen_nim.h>
|
||||
#include <flatbuffers/flatc.h>
|
||||
#include "idl_gen_cpp.h" // For C++ generator
|
||||
#include <idl_gen_csharp.h>
|
||||
#include <iostream>
|
||||
#include "flatbuffers/code_generator.h"
|
||||
#include <idl_gen_binary.h>
|
||||
#include <idl_gen_csharp.h>
|
||||
#include <idl_gen_dart.h>
|
||||
#include <idl_gen_fbs.h>
|
||||
#include <idl_gen_go.h>
|
||||
#include <idl_gen_java.h>
|
||||
#include <idl_gen_json_schema.h>
|
||||
#include <idl_gen_kotlin.h>
|
||||
#include <idl_gen_kotlin.h>
|
||||
#include <idl_gen_lobster.h>
|
||||
#include <bfbs_gen_lua.h>
|
||||
#include <bfbs_gen_nim.h>
|
||||
#include <idl_gen_python.h>
|
||||
#include <idl_gen_php.h>
|
||||
#include <idl_gen_python.h>
|
||||
#include <idl_gen_rust.h>
|
||||
#include <idl_gen_text.h>
|
||||
#include <idl_gen_swift.h>
|
||||
#include <idl_gen_text.h>
|
||||
#include <idl_gen_ts.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "flatbuffers/code_generator.h"
|
||||
#include "flatbuffers/idl.h" // For Parser and generation functions
|
||||
#include "idl_gen_cpp.h" // For C++ generator
|
||||
#include "test_init.h"
|
||||
|
||||
static constexpr size_t kMinInputLength = 1;
|
||||
static constexpr size_t kMaxInputLength = 16384;
|
||||
@@ -98,8 +99,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
if (parser.Parse(parse_input)) {
|
||||
parser.Serialize();
|
||||
const uint8_t* buf = parser.builder_.GetBufferPointer();
|
||||
flatbuffers::Verifier verifier(buf,
|
||||
parser.builder_.GetSize());
|
||||
flatbuffers::Verifier verifier(buf, parser.builder_.GetSize());
|
||||
TEST_EQ(true, reflection::VerifySchemaBuffer(verifier));
|
||||
|
||||
auto root = flatbuffers::GetRoot<flatbuffers::Table>(buf);
|
||||
@@ -126,8 +126,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
generators.emplace_back(flatbuffers::NewKotlinCodeGenerator());
|
||||
generators.emplace_back(flatbuffers::NewKotlinKMPCodeGenerator());
|
||||
generators.emplace_back(flatbuffers::NewLobsterCodeGenerator());
|
||||
generators.emplace_back(flatbuffers::NewLuaBfbsGenerator(flatbuffers_version));
|
||||
generators.emplace_back(flatbuffers::NewNimBfbsGenerator(flatbuffers_version));
|
||||
generators.emplace_back(
|
||||
flatbuffers::NewLuaBfbsGenerator(flatbuffers_version));
|
||||
generators.emplace_back(
|
||||
flatbuffers::NewNimBfbsGenerator(flatbuffers_version));
|
||||
generators.emplace_back(flatbuffers::NewPythonCodeGenerator());
|
||||
generators.emplace_back(flatbuffers::NewPhpCodeGenerator());
|
||||
generators.emplace_back(flatbuffers::NewRustCodeGenerator());
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <assert.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "flatbuffers/util.h"
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "flatbuffers/util.h"
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
|
||||
|
||||
@@ -27,10 +27,14 @@ void Matrix::UnPackTo(
|
||||
(void)_resolver;
|
||||
|
||||
auto _rows = rows();
|
||||
if (_rows) { _o->rows = _rows; }
|
||||
if (_rows) {
|
||||
_o->rows = _rows;
|
||||
}
|
||||
|
||||
auto _columns = columns();
|
||||
if (_columns) { _o->columns = _columns; }
|
||||
if (_columns) {
|
||||
_o->columns = _columns;
|
||||
}
|
||||
|
||||
auto _values = values();
|
||||
if (_values) {
|
||||
|
||||
@@ -771,14 +771,14 @@ void FixedLengthArrayTest() {
|
||||
// set memory chunk of size ArrayStruct to 1's
|
||||
std::memset(static_cast<void*>(non_zero_memory), 1, arr_size);
|
||||
// after placement-new it should be all 0's
|
||||
#if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING) && \
|
||||
defined(_MSC_VER) && defined(_DEBUG)
|
||||
#if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING) && defined(_MSC_VER) && \
|
||||
defined(_DEBUG)
|
||||
#undef new
|
||||
#endif
|
||||
MyGame::Example::ArrayStruct* ap =
|
||||
new (non_zero_memory) MyGame::Example::ArrayStruct;
|
||||
#if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING) && \
|
||||
defined(_MSC_VER) && defined(_DEBUG)
|
||||
#if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING) && defined(_MSC_VER) && \
|
||||
defined(_DEBUG)
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
(void)ap;
|
||||
@@ -925,7 +925,8 @@ void NativeTypeTest() {
|
||||
src_data.matrix->values = {3, 4};
|
||||
|
||||
for (int i = 0; i < N; ++i) {
|
||||
src_data.matrices.push_back(std::unique_ptr<Native::Matrix>(new Native::Matrix(1, i)));
|
||||
src_data.matrices.push_back(
|
||||
std::unique_ptr<Native::Matrix>(new Native::Matrix(1, i)));
|
||||
std::fill(src_data.matrices[i]->values.begin(),
|
||||
src_data.matrices[i]->values.end(), i + 0.5f);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user