bool size_prefixed;
std::string root_type;
bool force_defaults;
+ bool java_primitive_has_method;
std::vector<std::string> cpp_includes;
// Possible options for the more general generator below.
protobuf_ascii_alike(false),
size_prefixed(false),
force_defaults(false),
+ java_primitive_has_method(false),
lang(IDLOptions::kJava),
mini_reflect(IDLOptions::kNone),
lang_to_generate(0),
extern std::string MakeCamel(const std::string &in, bool first = true);
+extern std::string MakeScreamingCamel(const std::string &in);
+
// Generate text (JSON) from a given FlatBuffer, and a given Parser
// object that has been populated with the corresponding schema.
// If ident_step is 0, no indentation will be generated. Additionally,
}
}
+ /**
+ * Helper function to test if a field is present in the table
+ *
+ * @param table Flatbuffer table
+ * @param offset virtual table offset
+ * @return true if the filed is present
+ */
+ public static boolean isFieldPresent(Table table, int offset) {
+ return table.__offset(offset) != 0;
+ }
+
/**
* Reset the FlatBufferBuilder by purging all data that it holds.
*/
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 ||
}
}
}
+ 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;
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;