Add support for using array of scalar as key field in Cpp (#7623)

* add support for using array of scalar as key field

* update cmakelist and test.cpp to include the tests

* update bazel rule

* address comments

* clang format

* delete comment

* delete comment

* address the rest of the commnets

* address comments

* update naming in test file

* format build file

* buildifier

* make keycomparelessthan call keycomparewithvalue

* update to use flatbuffer array instead of raw pointer

* clang

* format

* revert format

* revert format

* update

* run generate_code.py

* run code generator

* revert changes by generate_code.py

* fist run make flatc and then run generate_code.py

Co-authored-by: Wen Sun <sunwen@google.com>
This commit is contained in:
Wen Sun
2022-11-18 11:04:46 -08:00
committed by GitHub
parent 1fa6091000
commit eb1abb51ea
15 changed files with 471 additions and 62 deletions

View File

@@ -20,8 +20,8 @@
#include <memory>
#include <string>
#include "evolution_test.h"
#include "alignment_test.h"
#include "evolution_test.h"
#include "flatbuffers/flatbuffers.h"
#include "flatbuffers/idl.h"
#include "flatbuffers/minireflect.h"
@@ -29,10 +29,11 @@
#include "flatbuffers/util.h"
#include "fuzz_test.h"
#include "json_test.h"
#include "key_field_test.h"
#include "monster_test.h"
#include "monster_test_generated.h"
#include "optional_scalars_test.h"
#include "native_inline_table_test_generated.h"
#include "optional_scalars_test.h"
#include "parser_test.h"
#include "proto_test.h"
#include "reflection_test.h"
@@ -1418,7 +1419,7 @@ void NativeInlineTableVectorTest() {
TEST_ASSERT(unpacked.t == test.t);
}
void DoNotRequireEofTest(const std::string& tests_data_path) {
void DoNotRequireEofTest(const std::string &tests_data_path) {
std::string schemafile;
bool ok = flatbuffers::LoadFile(
(tests_data_path + "monster_test.fbs").c_str(), false, &schemafile);
@@ -1432,7 +1433,7 @@ void DoNotRequireEofTest(const std::string& tests_data_path) {
flatbuffers::Parser parser(opt);
ok = parser.Parse(schemafile.c_str(), include_directories);
TEST_EQ(ok, true);
const char *str = R"(This string contains two monsters, the first one is {
"name": "Blob",
"hp": 5
@@ -1449,7 +1450,7 @@ void DoNotRequireEofTest(const std::string& tests_data_path) {
const Monster *monster = GetMonster(parser.builder_.GetBufferPointer());
TEST_EQ_STR(monster->name()->c_str(), "Blob");
TEST_EQ(monster->hp(), 5);
tableStart += parser.BytesConsumed();
tableStart = std::strchr(tableStart + 1, '{');
@@ -1564,6 +1565,7 @@ int FlatBufferTests(const std::string &tests_data_path) {
JsonUnsortedArrayTest();
VectorSpanTest();
NativeInlineTableVectorTest();
FixedSizedScalarKeyInStructTest();
return 0;
}
} // namespace