mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-11 23:40:57 +00:00
Add --force-defaults option to flatc [C++, parser] (#4729)
* Add --force-defaults option to flatc To emit default values for fields which are not present or which are set to the default value. * flatc option --force-defaults should have a default value (false) and take action on the builder_ within the Parser constructor * Add help text from flatc --force-defaults to Compiler.md doc * Clarified docs for flatc --force-defaults, and imply that this behaviour is not normally needed. * Updated docs and flatc help text for --force-defaults option
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
e9912e9298
commit
741c63052d
@@ -392,6 +392,7 @@ struct IDLOptions {
|
||||
bool protobuf_ascii_alike;
|
||||
bool size_prefixed;
|
||||
std::string root_type;
|
||||
bool force_defaults;
|
||||
|
||||
// Possible options for the more general generator below.
|
||||
enum Language {
|
||||
@@ -452,6 +453,7 @@ struct IDLOptions {
|
||||
reexport_ts_modules(true),
|
||||
protobuf_ascii_alike(false),
|
||||
size_prefixed(false),
|
||||
force_defaults(false),
|
||||
lang(IDLOptions::kJava),
|
||||
mini_reflect(IDLOptions::kNone),
|
||||
lang_to_generate(0) {}
|
||||
@@ -527,6 +529,9 @@ class Parser : public ParserState {
|
||||
source_(nullptr),
|
||||
anonymous_counter(0),
|
||||
recurse_protection_counter(0) {
|
||||
if (opts.force_defaults) {
|
||||
builder_.ForceDefaults(true);
|
||||
}
|
||||
// Start out with the empty namespace being current.
|
||||
empty_namespace_ = new Namespace();
|
||||
namespaces_.push_back(empty_namespace_);
|
||||
|
||||
Reference in New Issue
Block a user