Added doc comments to the binary schema.

Change-Id: I87f291ab6e07b1425850cae25ed500db594f17c8
Tested: on Linux.
parent 2d6e8f09
...@@ -114,6 +114,8 @@ Additional options: ...@@ -114,6 +114,8 @@ Additional options:
to the reflection/reflection.fbs schema. Loading this binary file is the to the reflection/reflection.fbs schema. Loading this binary file is the
basis for reflection functionality. basis for reflection functionality.
- `--bfbs-comments`: Add doc comments to the binary schema files.
- `--conform FILE` : Specify a schema the following schemas should be - `--conform FILE` : Specify a schema the following schemas should be
an evolution of. Gives errors if not. Useful to check if schema an evolution of. Gives errors if not. Useful to check if schema
modifications don't break schema evolution rules. modifications don't break schema evolution rules.
......
...@@ -356,6 +356,7 @@ struct IDLOptions { ...@@ -356,6 +356,7 @@ struct IDLOptions {
bool union_value_namespacing; bool union_value_namespacing;
bool allow_non_utf8; bool allow_non_utf8;
std::string include_prefix; std::string include_prefix;
bool binary_schema_comments;
// Possible options for the more general generator below. // Possible options for the more general generator below.
enum Language { enum Language {
...@@ -396,6 +397,7 @@ struct IDLOptions { ...@@ -396,6 +397,7 @@ struct IDLOptions {
cpp_object_api_pointer_type("std::unique_ptr"), cpp_object_api_pointer_type("std::unique_ptr"),
union_value_namespacing(true), union_value_namespacing(true),
allow_non_utf8(false), allow_non_utf8(false),
binary_schema_comments(false),
lang(IDLOptions::kJava), lang(IDLOptions::kJava),
lang_to_generate(0) {} lang_to_generate(0) {}
}; };
......
This diff is collapsed.
...@@ -51,6 +51,7 @@ table Enum { ...@@ -51,6 +51,7 @@ table Enum {
is_union:bool = false; is_union:bool = false;
underlying_type:Type (required); underlying_type:Type (required);
attributes:[KeyValue]; attributes:[KeyValue];
documentation:[string];
} }
table Field { table Field {
...@@ -64,6 +65,7 @@ table Field { ...@@ -64,6 +65,7 @@ table Field {
required:bool = false; required:bool = false;
key:bool = false; key:bool = false;
attributes:[KeyValue]; attributes:[KeyValue];
documentation:[string];
} }
table Object { // Used for both tables and structs. table Object { // Used for both tables and structs.
...@@ -73,6 +75,7 @@ table Object { // Used for both tables and structs. ...@@ -73,6 +75,7 @@ table Object { // Used for both tables and structs.
minalign:int; minalign:int;
bytesize:int; // For structs. bytesize:int; // For structs.
attributes:[KeyValue]; attributes:[KeyValue];
documentation:[string];
} }
table Schema { table Schema {
......
...@@ -93,6 +93,7 @@ std::string FlatCompiler::GetUsageString(const char* program_name) const { ...@@ -93,6 +93,7 @@ std::string FlatCompiler::GetUsageString(const char* program_name) const {
" --proto Input is a .proto, translate to .fbs.\n" " --proto Input is a .proto, translate to .fbs.\n"
" --grpc Generate GRPC interfaces for the specified languages\n" " --grpc Generate GRPC interfaces for the specified languages\n"
" --schema Serialize schemas instead of JSON (use with -b)\n" " --schema Serialize schemas instead of JSON (use with -b)\n"
" --bfbs-comments Add doc comments to the binary schema files.\n"
" --conform FILE Specify a schema the following schemas should be\n" " --conform FILE Specify a schema the following schemas should be\n"
" an evolution of. Gives errors if not.\n" " an evolution of. Gives errors if not.\n"
" --conform-includes Include path for the schema given with --conform\n" " --conform-includes Include path for the schema given with --conform\n"
...@@ -204,6 +205,8 @@ int FlatCompiler::Compile(int argc, const char** argv) { ...@@ -204,6 +205,8 @@ int FlatCompiler::Compile(int argc, const char** argv) {
exit(0); exit(0);
} else if(arg == "--grpc") { } else if(arg == "--grpc") {
grpc_enabled = true; grpc_enabled = true;
} else if(arg == "--bfbs-comments") {
opts.binary_schema_comments = true;
} else { } else {
for (size_t i = 0; i < params_.num_generators; ++i) { for (size_t i = 0; i < params_.num_generators; ++i) {
if (arg == params_.generators[i].generator_opt_long || if (arg == params_.generators[i].generator_opt_long ||
......
...@@ -2086,7 +2086,11 @@ Offset<reflection::Object> StructDef::Serialize(FlatBufferBuilder *builder, ...@@ -2086,7 +2086,11 @@ Offset<reflection::Object> StructDef::Serialize(FlatBufferBuilder *builder,
fixed, fixed,
static_cast<int>(minalign), static_cast<int>(minalign),
static_cast<int>(bytesize), static_cast<int>(bytesize),
SerializeAttributes(builder, parser)); SerializeAttributes(builder, parser),
parser.opts.binary_schema_comments
? builder->CreateVectorOfStrings(
doc_comment)
: 0);
} }
Offset<reflection::Field> FieldDef::Serialize(FlatBufferBuilder *builder, Offset<reflection::Field> FieldDef::Serialize(FlatBufferBuilder *builder,
...@@ -2106,7 +2110,10 @@ Offset<reflection::Field> FieldDef::Serialize(FlatBufferBuilder *builder, ...@@ -2106,7 +2110,10 @@ Offset<reflection::Field> FieldDef::Serialize(FlatBufferBuilder *builder,
deprecated, deprecated,
required, required,
key, key,
SerializeAttributes(builder, parser)); SerializeAttributes(builder, parser),
parser.opts.binary_schema_comments
? builder->CreateVectorOfStrings(doc_comment)
: 0);
// TODO: value.constant is almost always "0", we could save quite a bit of // TODO: value.constant is almost always "0", we could save quite a bit of
// space by sharing it. Same for common values of value.type. // space by sharing it. Same for common values of value.type.
} }
...@@ -2123,7 +2130,10 @@ Offset<reflection::Enum> EnumDef::Serialize(FlatBufferBuilder *builder, ...@@ -2123,7 +2130,10 @@ Offset<reflection::Enum> EnumDef::Serialize(FlatBufferBuilder *builder,
builder->CreateVector(enumval_offsets), builder->CreateVector(enumval_offsets),
is_union, is_union,
underlying_type.Serialize(builder), underlying_type.Serialize(builder),
SerializeAttributes(builder, parser)); SerializeAttributes(builder, parser),
parser.opts.binary_schema_comments
? builder->CreateVectorOfStrings(doc_comment)
: 0);
} }
Offset<reflection::EnumVal> EnumVal::Serialize(FlatBufferBuilder *builder) const Offset<reflection::EnumVal> EnumVal::Serialize(FlatBufferBuilder *builder) const
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
../flatc --cpp --java --csharp --go --binary --python --js --php --grpc --gen-mutable --gen-object-api --no-includes monster_test.fbs monsterdata_test.json ../flatc --cpp --java --csharp --go --binary --python --js --php --grpc --gen-mutable --gen-object-api --no-includes monster_test.fbs monsterdata_test.json
../flatc --cpp --java --csharp --go --binary --python --js --php --gen-mutable -o namespace_test namespace_test/namespace_test1.fbs namespace_test/namespace_test2.fbs ../flatc --cpp --java --csharp --go --binary --python --js --php --gen-mutable -o namespace_test namespace_test/namespace_test1.fbs namespace_test/namespace_test2.fbs
../flatc --cpp -o union_vector ./union_vector/union_vector.fbs ../flatc --cpp -o union_vector ./union_vector/union_vector.fbs
../flatc -b --schema --bfbs-comments monster_test.fbs
cd ../samples cd ../samples
../flatc --cpp --gen-mutable --gen-object-api monster.fbs ../flatc --cpp --gen-mutable --gen-object-api monster.fbs
cd ../reflection cd ../reflection
......
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment