mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-11 15:37:27 +00:00
has_method support for primitive fields in java runtime. Changed: idl.h, FlatBufferBuilder.java , idl_gen_general.cpp, idl_parser.cpp, flatc.cpp (#5468)
* has_method support for primitive fields in java runtime * adding the new flag to flatc * addressing the review comments
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
acc9990abd
commit
a20e71ac96
@@ -319,6 +319,8 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
opts.force_defaults = true;
|
||||
} else if (arg == "--force-empty") {
|
||||
opts.set_empty_to_null = false;
|
||||
} else if (arg == "--java-primitive-has-method") {
|
||||
opts.java_primitive_has_method = true;
|
||||
} else {
|
||||
for (size_t i = 0; i < params_.num_generators; ++i) {
|
||||
if (arg == params_.generators[i].generator_opt_long ||
|
||||
|
||||
@@ -1323,6 +1323,15 @@ class GeneralGenerator : public BaseGenerator {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (parser_.opts.java_primitive_has_method &&
|
||||
IsScalar(field.value.type.base_type) && !struct_def.fixed) {
|
||||
auto vt_offset_constant = " public static final int VT_" +
|
||||
MakeScreamingCamel(field.name) + " = " +
|
||||
NumToString(field.value.offset) + ";";
|
||||
|
||||
code += vt_offset_constant;
|
||||
code += "\n";
|
||||
}
|
||||
}
|
||||
code += "\n";
|
||||
flatbuffers::FieldDef *key_field = nullptr;
|
||||
|
||||
@@ -102,6 +102,18 @@ std::string MakeCamel(const std::string &in, bool first) {
|
||||
return s;
|
||||
}
|
||||
|
||||
// Convert an underscore_based_identifier in to screaming snake case.
|
||||
std::string MakeScreamingCamel(const std::string &in) {
|
||||
std::string s;
|
||||
for (size_t i = 0; i < in.length(); i++) {
|
||||
if (in[i] != '_')
|
||||
s += static_cast<char>(toupper(in[i]));
|
||||
else
|
||||
s += in[i];
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
void DeserializeDoc( std::vector<std::string> &doc,
|
||||
const Vector<Offset<String>> *documentation) {
|
||||
if (documentation == nullptr) return;
|
||||
|
||||
Reference in New Issue
Block a user