summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTobias Oberstein <tobias.oberstein@crossbario.com>2018-04-27 22:31:18 +0200
committerWouter van Oortmerssen <aardappel@gmail.com>2018-04-27 13:31:18 -0700
commit9bb88a026aa3423c2c97c5e74c60f404e62cc688 (patch)
tree70a02adc34d6e16bc41ccb51477e5ed2f1b66e0b /src
parent34cb163e389e928db08ed2bd0e16ee0ac53ab1ce (diff)
downloadflatbuffers-9bb88a026aa3423c2c97c5e74c60f404e62cc688.tar.gz
flatbuffers-9bb88a026aa3423c2c97c5e74c60f404e62cc688.tar.bz2
flatbuffers-9bb88a026aa3423c2c97c5e74c60f404e62cc688.zip
Include services in reflection data (fixes #4639) (#4713)
* include service in reflection data (fixes #4639) * changes from review * regenerated test data
Diffstat (limited to 'src')
-rw-r--r--src/flatc.cpp3
-rw-r--r--src/idl_gen_grpc.cpp2
-rw-r--r--src/idl_parser.cpp84
3 files changed, 71 insertions, 18 deletions
diff --git a/src/flatc.cpp b/src/flatc.cpp
index 8e4906f8..60fabd50 100644
--- a/src/flatc.cpp
+++ b/src/flatc.cpp
@@ -106,6 +106,7 @@ std::string FlatCompiler::GetUsageString(const char *program_name) const {
" --grpc Generate GRPC interfaces for the specified languages\n"
" --schema Serialize schemas instead of JSON (use with -b)\n"
" --bfbs-comments Add doc comments to the binary schema files.\n"
+ " --bfbs-builtins Add builtin attributes to the binary schema files.\n"
" --conform FILE Specify a schema the following schemas should be\n"
" an evolution of. Gives errors if not.\n"
" --conform-includes Include path for the schema given with --conform\n"
@@ -253,6 +254,8 @@ int FlatCompiler::Compile(int argc, const char **argv) {
grpc_enabled = true;
} else if (arg == "--bfbs-comments") {
opts.binary_schema_comments = true;
+ } else if (arg == "--bfbs-builtins") {
+ opts.binary_schema_builtins = true;
} else if (arg == "--no-fb-import") {
opts.skip_flatbuffers_import = true;
} else if (arg == "--no-ts-reexport") {
diff --git a/src/idl_gen_grpc.cpp b/src/idl_gen_grpc.cpp
index 02994bda..b0159341 100644
--- a/src/idl_gen_grpc.cpp
+++ b/src/idl_gen_grpc.cpp
@@ -50,7 +50,7 @@ class FlatBufMethod : public grpc_generator::Method {
grpc::string GetLeadingComments(const grpc::string) const { return ""; }
grpc::string GetTrailingComments(const grpc::string) const { return ""; }
std::vector<grpc::string> GetAllComments() const {
- return method_->rpc_comment;
+ return method_->doc_comment;
}
std::string name() const { return method_->name; }
diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp
index c0fe5335..3102cd61 100644
--- a/src/idl_parser.cpp
+++ b/src/idl_parser.cpp
@@ -1724,7 +1724,7 @@ CheckedError Parser::ParseService() {
ECHECK(ParseMetaData(&service_def.attributes));
EXPECT('{');
do {
- std::vector<std::string> rpc_comment = doc_comment_;
+ std::vector<std::string> doc_comment = doc_comment_;
auto rpc_name = attribute_;
EXPECT(kTokenIdentifier);
EXPECT('(');
@@ -1740,7 +1740,7 @@ CheckedError Parser::ParseService() {
rpc.name = rpc_name;
rpc.request = reqtype.struct_def;
rpc.response = resptype.struct_def;
- rpc.rpc_comment = rpc_comment;
+ rpc.doc_comment = doc_comment;
if (service_def.calls.Add(rpc_name, &rpc))
return Error("rpc already exists: " + rpc_name);
ECHECK(ParseMetaData(&rpc.attributes));
@@ -2527,12 +2527,20 @@ void Parser::Serialize() {
enum_offsets.push_back(offset);
(*it)->serialized_location = offset.o;
}
+ std::vector<Offset<reflection::Service>> service_offsets;
+ for (auto it = services_.vec.begin(); it != services_.vec.end(); ++it) {
+ auto offset = (*it)->Serialize(&builder_, *this);
+ service_offsets.push_back(offset);
+ (*it)->serialized_location = offset.o;
+ }
auto schema_offset = reflection::CreateSchema(
- builder_, builder_.CreateVectorOfSortedTables(&object_offsets),
+ builder_,
+ builder_.CreateVectorOfSortedTables(&object_offsets),
builder_.CreateVectorOfSortedTables(&enum_offsets),
builder_.CreateString(file_identifier_),
builder_.CreateString(file_extension_),
- root_struct_def_ ? root_struct_def_->serialized_location : 0);
+ (root_struct_def_ ? root_struct_def_->serialized_location : 0),
+ builder_.CreateVectorOfSortedTables(&service_offsets));
if (opts.size_prefixed) {
builder_.FinishSizePrefixed(schema_offset, reflection::SchemaIdentifier());
} else {
@@ -2549,9 +2557,12 @@ Offset<reflection::Object> StructDef::Serialize(FlatBufferBuilder *builder,
}
auto qualified_name = defined_namespace->GetFullyQualifiedName(name);
return reflection::CreateObject(
- *builder, builder->CreateString(qualified_name),
- builder->CreateVectorOfSortedTables(&field_offsets), fixed,
- static_cast<int>(minalign), static_cast<int>(bytesize),
+ *builder,
+ builder->CreateString(qualified_name),
+ builder->CreateVectorOfSortedTables(&field_offsets),
+ fixed,
+ static_cast<int>(minalign),
+ static_cast<int>(bytesize),
SerializeAttributes(builder, parser),
parser.opts.binary_schema_comments
? builder->CreateVectorOfStrings(doc_comment)
@@ -2575,33 +2586,72 @@ Offset<reflection::Field> FieldDef::Serialize(FlatBufferBuilder *builder,
// space by sharing it. Same for common values of value.type.
}
+Offset<reflection::RPCCall> RPCCall::Serialize(FlatBufferBuilder *builder,
+ const Parser &parser) const {
+ return reflection::CreateRPCCall(
+ *builder,
+ builder->CreateString(name),
+ request->serialized_location,
+ response->serialized_location,
+ SerializeAttributes(builder, parser),
+ parser.opts.binary_schema_comments
+ ? builder->CreateVectorOfStrings(doc_comment)
+ : 0);
+}
+
+Offset<reflection::Service> ServiceDef::Serialize(FlatBufferBuilder *builder,
+ const Parser &parser) const {
+ std::vector<Offset<reflection::RPCCall>> servicecall_offsets;
+ for (auto it = calls.vec.begin(); it != calls.vec.end(); ++it) {
+ servicecall_offsets.push_back((*it)->Serialize(builder, parser));
+ }
+ auto qualified_name = defined_namespace->GetFullyQualifiedName(name);
+ return reflection::CreateService(
+ *builder,
+ builder->CreateString(qualified_name),
+ builder->CreateVector(servicecall_offsets),
+ SerializeAttributes(builder, parser),
+ parser.opts.binary_schema_comments
+ ? builder->CreateVectorOfStrings(doc_comment)
+ : 0);
+}
+
Offset<reflection::Enum> EnumDef::Serialize(FlatBufferBuilder *builder,
const Parser &parser) const {
std::vector<Offset<reflection::EnumVal>> enumval_offsets;
for (auto it = vals.vec.begin(); it != vals.vec.end(); ++it) {
- enumval_offsets.push_back((*it)->Serialize(builder));
+ enumval_offsets.push_back((*it)->Serialize(builder, parser));
}
auto qualified_name = defined_namespace->GetFullyQualifiedName(name);
return reflection::CreateEnum(
- *builder, builder->CreateString(qualified_name),
- builder->CreateVector(enumval_offsets), is_union,
- underlying_type.Serialize(builder), SerializeAttributes(builder, parser),
+ *builder,
+ builder->CreateString(qualified_name),
+ builder->CreateVector(enumval_offsets),
+ is_union,
+ underlying_type.Serialize(builder),
+ 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 Parser &parser) const {
return reflection::CreateEnumVal(
- *builder, builder->CreateString(name), value,
+ *builder,
+ builder->CreateString(name),
+ value,
union_type.struct_def ? union_type.struct_def->serialized_location : 0,
- union_type.Serialize(builder));
+ union_type.Serialize(builder),
+ parser.opts.binary_schema_comments
+ ? builder->CreateVectorOfStrings(doc_comment)
+ : 0);
}
Offset<reflection::Type> Type::Serialize(FlatBufferBuilder *builder) const {
return reflection::CreateType(
- *builder, static_cast<reflection::BaseType>(base_type),
+ *builder,
+ static_cast<reflection::BaseType>(base_type),
static_cast<reflection::BaseType>(element),
struct_def ? struct_def->index : (enum_def ? enum_def->index : -1));
}
@@ -2614,7 +2664,7 @@ Definition::SerializeAttributes(FlatBufferBuilder *builder,
for (auto kv = attributes.dict.begin(); kv != attributes.dict.end(); ++kv) {
auto it = parser.known_attributes_.find(kv->first);
FLATBUFFERS_ASSERT(it != parser.known_attributes_.end());
- if (!it->second) { // Custom attribute.
+ if (parser.opts.binary_schema_builtins || !it->second) {
attrs.push_back(reflection::CreateKeyValue(
*builder, builder->CreateString(kv->first),
builder->CreateString(kv->second->constant)));