mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-04 04:33:23 +00:00
Add FLATBUFFERS_COMPATIBILITY string (#5381)
* Add FLATBUFFERS_COMPATIBILITY string - Add a new __reset method NET/JAVA which hides internal state * Resolve PR notes * Use operator new() to __init of Struct and Table * Restrict visibility of C# Table/Struct to internal level
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
a80db8538c
commit
0d2cebccfe
@@ -18,10 +18,10 @@
|
||||
|
||||
#include <list>
|
||||
|
||||
#define FLATC_VERSION "1.11.0"
|
||||
|
||||
namespace flatbuffers {
|
||||
|
||||
const char *FLATC_VERSION() { return FLATBUFFERS_VERSION(); }
|
||||
|
||||
void FlatCompiler::ParseFile(
|
||||
flatbuffers::Parser &parser, const std::string &filename,
|
||||
const std::string &contents,
|
||||
@@ -294,7 +294,7 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
} else if (arg == "-M") {
|
||||
print_make_rules = true;
|
||||
} else if (arg == "--version") {
|
||||
printf("flatc version %s\n", FLATC_VERSION);
|
||||
printf("flatc version %s\n", FLATC_VERSION());
|
||||
exit(0);
|
||||
} else if (arg == "--grpc") {
|
||||
grpc_enabled = true;
|
||||
|
||||
@@ -833,7 +833,18 @@ class GeneralGenerator : public BaseGenerator {
|
||||
code += struct_def.fixed ? "Struct" : "Table";
|
||||
code += lang_.open_curly;
|
||||
}
|
||||
|
||||
if (!struct_def.fixed) {
|
||||
// Generate verson check method.
|
||||
// Force compile time error if not using the same version runtime.
|
||||
code += " public static void ValidateVersion() {";
|
||||
if (lang_.language == IDLOptions::kCSharp)
|
||||
code += " FlatBufferConstants.";
|
||||
else
|
||||
code += " Constants.";
|
||||
code += "FLATBUFFERS_1_11_1(); ";
|
||||
code += "}\n";
|
||||
|
||||
// Generate a special accessor for the table that when used as the root
|
||||
// of a FlatBuffer
|
||||
std::string method_name =
|
||||
@@ -849,11 +860,6 @@ class GeneralGenerator : public BaseGenerator {
|
||||
// create method that allows object reuse
|
||||
code +=
|
||||
method_signature + "(ByteBuffer _bb, " + struct_def.name + " obj) { ";
|
||||
// Force compile time error if not using the same version runtime.
|
||||
if (lang_.language == IDLOptions::kCSharp)
|
||||
code += "FlatBufferConstants.FLATBUFFERS_1_11_1(); ";
|
||||
else
|
||||
code += "Constants.FLATBUFFERS_1_11_1(); ";
|
||||
code += lang_.set_bb_byteorder;
|
||||
code += "return (obj.__assign(_bb." + FunctionStart('G') + "etInt(_bb.";
|
||||
code += lang_.get_bb_position;
|
||||
@@ -875,14 +881,13 @@ class GeneralGenerator : public BaseGenerator {
|
||||
// Generate the __init method that sets the field in a pre-existing
|
||||
// accessor object. This is to allow object reuse.
|
||||
code += " public void __init(int _i, ByteBuffer _bb) ";
|
||||
code += "{ " + lang_.accessor_prefix + "bb_pos = _i; ";
|
||||
code += lang_.accessor_prefix + "bb = _bb; ";
|
||||
if (!struct_def.fixed && lang_.language == IDLOptions::kJava) {
|
||||
code += lang_.accessor_prefix + "vtable_start = " + lang_.accessor_prefix + "bb_pos - ";
|
||||
code += lang_.accessor_prefix + "bb." + FunctionStart('G') + "etInt(";
|
||||
code += lang_.accessor_prefix + "bb_pos); " + lang_.accessor_prefix + "vtable_size = ";
|
||||
code += lang_.accessor_prefix + "bb." + FunctionStart('G') + "etShort(";
|
||||
code += lang_.accessor_prefix + "vtable_start); ";
|
||||
code += "{ ";
|
||||
if (lang_.language == IDLOptions::kCSharp) {
|
||||
code += "__p = new ";
|
||||
code += struct_def.fixed ? "Struct" : "Table";
|
||||
code += "(_i, _bb); ";
|
||||
} else {
|
||||
code += "__reset(_i, _bb); ";
|
||||
}
|
||||
code += "}\n";
|
||||
code +=
|
||||
|
||||
@@ -26,6 +26,16 @@
|
||||
|
||||
namespace flatbuffers {
|
||||
|
||||
// Reflects the version at the compiling time of binary(lib/dll/so).
|
||||
const char *FLATBUFFERS_VERSION() {
|
||||
// clang-format off
|
||||
return
|
||||
FLATBUFFERS_STRING(FLATBUFFERS_VERSION_MAJOR) "."
|
||||
FLATBUFFERS_STRING(FLATBUFFERS_VERSION_MINOR) "."
|
||||
FLATBUFFERS_STRING(FLATBUFFERS_VERSION_REVISION);
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
const double kPi = 3.14159265358979323846;
|
||||
|
||||
const char *const kTypeNames[] = {
|
||||
@@ -1747,7 +1757,7 @@ struct EnumValBuilder {
|
||||
auto ascending = false;
|
||||
if (enum_def.IsUInt64()) {
|
||||
uint64_t u64;
|
||||
fit = StringToNumber(value.c_str(), &u64);
|
||||
fit = StringToNumber(value.c_str(), &u64);
|
||||
ascending = u64 > temp->GetAsUInt64();
|
||||
temp->value = static_cast<int64_t>(u64); // well-defined since C++20.
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user