mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 04:04:19 +00:00
FlatBuffers 64 for C++ (#7935)
* First working hack of adding 64-bit. Don't judge :) * Made vector_downward work on 64 bit types * vector_downward uses size_t, added offset64 to reflection * cleaned up adding offset64 in parser * Add C++ testing skeleton for 64-bit * working test for CreateVector64 * working >2 GiB buffers * support for large strings * simplified CreateString<> to just provide the offset type * generalize CreateVector template * update test_64.afb due to upstream format change * Added Vector64 type, which is just an alias for vector ATM * Switch to Offset64 for Vector64 * Update for reflection bfbs output change * Starting to add support for vector64 type in C++ * made a generic CreateVector that can handle different offsets and vector types * Support for 32-vector with 64-addressing * Vector64 basic builder + tests working * basic support for json vector64 support * renamed fields in test_64bit.fbs to better reflect their use * working C++ vector64 builder * Apply --annotate-sparse-vector to 64-bit tests * Enable Vector64 for --annotate-sparse-vectors * Merged from upstream * Add `near_string` field for testing 32-bit offsets alongside * keep track of where the 32-bit and 64-bit regions are for flatbufferbuilder * move template<> outside class body for GCC * update run.sh to build and run tests * basic assertion for adding 64-bit offset at the wrong time * started to separate `FlatBufferBuilder` into two classes, 1 64-bit aware, the other not * add test for nested flatbuffer vector64, fix bug in alignment of big vectors * fixed CreateDirect method by iterating by Offset64 first * internal refactoring of flatbufferbuilder * block not supported languages in the parser from using 64-bit * evolution tests for adding a vector64 field * conformity tests for adding/removing offset64 attributes * ensure test is for a big buffer * add parser error tests for `offset64` and `vector64` attributes * add missing static that GCC only complains about * remove stdint-uintn.h header that gets automatically added * move 64-bit CalculateOffset internal * fixed return size of EndVector * various fixes on windows * add SizeT to vector_downward * minimze range of size changes in vector and builder * reworked how tracking if 64-offsets are added * Add ReturnT to EndVector * small cleanups * remove need for second Array definition * combine IndirectHelpers into one definition * started support for vector of struct * Support for 32/64-vectors of structs + Offset64 * small cleanups * add verification for vector64 * add sized prefix for 64-bit buffers * add fuzzer for 64-bit * add example of adding many vectors using a wrapper table * run the new -bfbs-gen-embed logic on the 64-bit tests * remove run.sh and fix cmakelist issue * fixed bazel rules * fixed some PR comments * add 64-bit tests to cmakelist
This commit is contained in:
@@ -16,8 +16,9 @@ static const auto infinity_f = std::numeric_limits<float>::infinity();
|
||||
static const auto infinity_d = std::numeric_limits<double>::infinity();
|
||||
|
||||
// Test that parser errors are actually generated.
|
||||
static void TestError_(const char *src, const char *error_substr, bool strict_json,
|
||||
const char *file, int line, const char *func) {
|
||||
static void TestError_(const char *src, const char *error_substr,
|
||||
bool strict_json, const char *file, int line,
|
||||
const char *func) {
|
||||
flatbuffers::IDLOptions opts;
|
||||
opts.strict_json = strict_json;
|
||||
flatbuffers::Parser parser(opts);
|
||||
@@ -32,8 +33,8 @@ static void TestError_(const char *src, const char *error_substr, bool strict_js
|
||||
}
|
||||
}
|
||||
|
||||
static void TestError_(const char *src, const char *error_substr, const char *file,
|
||||
int line, const char *func) {
|
||||
static void TestError_(const char *src, const char *error_substr,
|
||||
const char *file, int line, const char *func) {
|
||||
TestError_(src, error_substr, false, file, line, func);
|
||||
}
|
||||
|
||||
@@ -47,7 +48,7 @@ static void TestError_(const char *src, const char *error_substr, const char *fi
|
||||
|
||||
static bool FloatCompare(float a, float b) { return fabs(a - b) < 0.001; }
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
// Test that parsing errors occur as we'd expect.
|
||||
// Also useful for coverage, making sure these paths are run.
|
||||
@@ -124,6 +125,34 @@ void ErrorTest() {
|
||||
// An identifier can't start from sign (+|-)
|
||||
TestError("table X { -Y: int; } root_type Y: {Y:1.0}", "identifier");
|
||||
TestError("table X { +Y: int; } root_type Y: {Y:1.0}", "identifier");
|
||||
|
||||
// Offset64
|
||||
TestError("table X { a:int (vector64); }", "`vector64` attribute");
|
||||
TestError("table X { a:int (offset64); }", "`offset64` attribute");
|
||||
TestError("table X { a:string (vector64); }", "`vector64` attribute");
|
||||
TestError("table y { a:int; } table X { a:y (offset64); }",
|
||||
"`offset64` attribute");
|
||||
TestError("struct y { a:int; } table X { a:y (offset64); }",
|
||||
"`offset64` attribute");
|
||||
TestError("table y { a:int; } table X { a:y (vector64); }",
|
||||
"`vector64` attribute");
|
||||
TestError("union Y { } table X { ys:Y (offset64); }", "`offset64` attribute");
|
||||
|
||||
TestError("table Y { a:int; } table X { ys:[Y] (offset64); }",
|
||||
"only vectors of scalars are allowed to be 64-bit.");
|
||||
TestError("table Y { a:int; } table X { ys:[Y] (vector64); }",
|
||||
"only vectors of scalars are allowed to be 64-bit.");
|
||||
TestError("union Y { } table X { ys:[Y] (vector64); }",
|
||||
"only vectors of scalars are allowed to be 64-bit.");
|
||||
|
||||
// TOOD(derekbailey): the following three could be allowed once the code gen
|
||||
// supports the output.
|
||||
TestError("table X { y:[string] (offset64); }",
|
||||
"only vectors of scalars are allowed to be 64-bit.");
|
||||
TestError("table X { y:[string] (vector64); }",
|
||||
"only vectors of scalars are allowed to be 64-bit.");
|
||||
TestError("enum X:byte {Z} table X { y:[X] (offset64); }",
|
||||
"only vectors of scalars are allowed to be 64-bit.");
|
||||
}
|
||||
|
||||
void EnumOutOfRangeTest() {
|
||||
@@ -776,8 +805,6 @@ void UnicodeSurrogatesTest() {
|
||||
TEST_EQ_STR(string->c_str(), "\xF0\x9F\x92\xA9");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void UnknownFieldsTest() {
|
||||
flatbuffers::IDLOptions opts;
|
||||
opts.skip_unexpected_fields_in_json = true;
|
||||
|
||||
Reference in New Issue
Block a user