replace framework include of flatbuffers (#7079)

This commit is contained in:
Derek Bailey
2022-02-03 17:40:15 -08:00
committed by GitHub
parent f5664d33fb
commit 4c71c7b023

View File

@@ -23,7 +23,7 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include <flatbuffers/util.h> #include "flatbuffers/util.h"
#define to_string flatbuffers::NumToString #define to_string flatbuffers::NumToString
// Stringify helpers used solely to cast GRPC_VERSION // Stringify helpers used solely to cast GRPC_VERSION
@@ -35,7 +35,6 @@
# define XSTR(s) STR(s) # define XSTR(s) STR(s)
#endif #endif
typedef grpc_generator::Printer Printer; typedef grpc_generator::Printer Printer;
typedef std::map<grpc::string, grpc::string> VARS; typedef std::map<grpc::string, grpc::string> VARS;
typedef grpc_generator::Service ServiceDescriptor; typedef grpc_generator::Service ServiceDescriptor;
@@ -49,8 +48,7 @@ typedef std::string string;
void GenerateImports(grpc_generator::File *file, void GenerateImports(grpc_generator::File *file,
grpc_generator::Printer *printer, VARS &vars) { grpc_generator::Printer *printer, VARS &vars) {
vars["filename"] = file->filename(); vars["filename"] = file->filename();
printer->Print( printer->Print(vars,
vars,
"//Generated by flatc compiler (version $flatc_version$)\n"); "//Generated by flatc compiler (version $flatc_version$)\n");
printer->Print("//If you make any local changes, they will be lost\n"); printer->Print("//If you make any local changes, they will be lost\n");
printer->Print(vars, "//source: $filename$.fbs\n\n"); printer->Print(vars, "//source: $filename$.fbs\n\n");
@@ -219,9 +217,7 @@ static string GrpcEscapeJavadoc(const string& input) {
// Java interprets Unicode escape sequences anywhere! // Java interprets Unicode escape sequences anywhere!
result.append("&#92;"); result.append("&#92;");
break; break;
default: default: result.push_back(c); break;
result.push_back(c);
break;
} }
prev = c; prev = c;
@@ -241,9 +237,7 @@ static std::vector<string> GrpcGetDocLines(const string& comments) {
string escapedComments = GrpcEscapeJavadoc(comments); string escapedComments = GrpcEscapeJavadoc(comments);
std::vector<string> lines = GrpcSplit(escapedComments, "\n"); std::vector<string> lines = GrpcSplit(escapedComments, "\n");
while (!lines.empty() && lines.back().empty()) { while (!lines.empty() && lines.back().empty()) { lines.pop_back(); }
lines.pop_back();
}
return lines; return lines;
} }
return std::vector<string>(); return std::vector<string>();
@@ -259,9 +253,7 @@ static void GrpcWriteDocCommentBody(Printer* printer, VARS& vars,
const std::vector<string> &lines, const std::vector<string> &lines,
bool surroundWithPreTag) { bool surroundWithPreTag) {
if (!lines.empty()) { if (!lines.empty()) {
if (surroundWithPreTag) { if (surroundWithPreTag) { printer->Print(" * <pre>\n"); }
printer->Print(" * <pre>\n");
}
for (size_t i = 0; i < lines.size(); i++) { for (size_t i = 0; i < lines.size(); i++) {
// Most lines should start with a space. Watch out for lines that start // Most lines should start with a space. Watch out for lines that start
@@ -275,9 +267,7 @@ static void GrpcWriteDocCommentBody(Printer* printer, VARS& vars,
} }
} }
if (surroundWithPreTag) { if (surroundWithPreTag) { printer->Print(" * </pre>\n"); }
printer->Print(" * </pre>\n");
}
} }
} }
@@ -305,10 +295,10 @@ void GrpcWriteMethodDocComment(Printer* printer, VARS& vars,
printer->Print(" */\n"); printer->Print(" */\n");
} }
//outputs static singleton extractor for type stored in "extr_type" and "extr_type_name" vars // outputs static singleton extractor for type stored in "extr_type" and
// "extr_type_name" vars
static void PrintTypeExtractor(Printer *p, VARS &vars) { static void PrintTypeExtractor(Printer *p, VARS &vars) {
p->Print( p->Print(vars,
vars,
"private static volatile FlatbuffersUtils.FBExtactor<$extr_type$> " "private static volatile FlatbuffersUtils.FBExtactor<$extr_type$> "
"extractorOf$extr_type_name$;\n" "extractorOf$extr_type_name$;\n"
"private static FlatbuffersUtils.FBExtactor<$extr_type$> " "private static FlatbuffersUtils.FBExtactor<$extr_type$> "
@@ -336,7 +326,8 @@ static void PrintMethodFields(Printer* p, VARS& vars,
// set of names of rpc input- and output- types that were already encountered. // set of names of rpc input- and output- types that were already encountered.
// this is needed to avoid duplicating type extractor since it's possible that // this is needed to avoid duplicating type extractor since it's possible that
//the same type is used as an input or output type of more than a single RPC method // the same type is used as an input or output type of more than a single RPC
// method
std::set<std::string> encounteredTypes; std::set<std::string> encounteredTypes;
for (int i = 0; i < service->method_count(); ++i) { for (int i = 0; i < service->method_count(); ++i) {
@@ -351,8 +342,10 @@ static void PrintMethodFields(Printer* p, VARS& vars,
vars["method_field_name"] = MethodPropertiesFieldName(method.get()); vars["method_field_name"] = MethodPropertiesFieldName(method.get());
vars["method_new_field_name"] = MethodPropertiesGetterName(method.get()); vars["method_new_field_name"] = MethodPropertiesGetterName(method.get());
vars["method_method_name"] = MethodPropertiesGetterName(method.get()); vars["method_method_name"] = MethodPropertiesGetterName(method.get());
bool client_streaming = method->ClientStreaming() || method->BidiStreaming(); bool client_streaming =
bool server_streaming = method->ServerStreaming() || method->BidiStreaming(); method->ClientStreaming() || method->BidiStreaming();
bool server_streaming =
method->ServerStreaming() || method->BidiStreaming();
if (client_streaming) { if (client_streaming) {
if (server_streaming) { if (server_streaming) {
vars["method_type"] = "BIDI_STREAMING"; vars["method_type"] = "BIDI_STREAMING";
@@ -499,9 +492,7 @@ static void PrintStub(Printer* p, VARS& vars, const ServiceDescriptor* service,
vars["client_name"] = client_name; vars["client_name"] = client_name;
// Class head // Class head
if (!interface) { if (!interface) { GrpcWriteServiceDocComment(p, vars, service); }
GrpcWriteServiceDocComment(p, vars, service);
}
if (impl_base) { if (impl_base) {
p->Print(vars, p->Print(vars,
"public static abstract class $abstract_name$ implements " "public static abstract class $abstract_name$ implements "
@@ -544,8 +535,10 @@ static void PrintStub(Printer* p, VARS& vars, const ServiceDescriptor* service,
vars["output_type"] = JavaClassName(vars, method->get_output_type_name()); vars["output_type"] = JavaClassName(vars, method->get_output_type_name());
vars["lower_method_name"] = LowerMethodName(&*method); vars["lower_method_name"] = LowerMethodName(&*method);
vars["method_method_name"] = MethodPropertiesGetterName(&*method); vars["method_method_name"] = MethodPropertiesGetterName(&*method);
bool client_streaming = method->ClientStreaming() || method->BidiStreaming(); bool client_streaming =
bool server_streaming = method->ServerStreaming() || method->BidiStreaming(); method->ClientStreaming() || method->BidiStreaming();
bool server_streaming =
method->ServerStreaming() || method->BidiStreaming();
if (call_type == BLOCKING_CALL && client_streaming) { if (call_type == BLOCKING_CALL && client_streaming) {
// Blocking client interface with client streaming is not available // Blocking client interface with client streaming is not available
@@ -561,9 +554,7 @@ static void PrintStub(Printer* p, VARS& vars, const ServiceDescriptor* service,
p->Print("\n"); p->Print("\n");
// TODO(nmittler): Replace with WriteMethodDocComment once included by the // TODO(nmittler): Replace with WriteMethodDocComment once included by the
// protobuf distro. // protobuf distro.
if (!interface) { if (!interface) { GrpcWriteMethodDocComment(p, vars, &*method); }
GrpcWriteMethodDocComment(p, vars, &*method);
}
p->Print("public "); p->Print("public ");
switch (call_type) { switch (call_type) {
case BLOCKING_CALL: case BLOCKING_CALL:
@@ -628,8 +619,7 @@ static void PrintStub(Printer* p, VARS& vars, const ServiceDescriptor* service,
"responseObserver);\n"); "responseObserver);\n");
} }
break; break;
default: default: break;
break;
} }
} else if (!interface) { } else if (!interface) {
switch (call_type) { switch (call_type) {
@@ -755,9 +745,7 @@ static void PrintMethodHandlerClass(Printer* p, VARS& vars,
for (int i = 0; i < service->method_count(); ++i) { for (int i = 0; i < service->method_count(); ++i) {
auto method = service->method(i); auto method = service->method(i);
if (method->ClientStreaming() || method->BidiStreaming()) { if (method->ClientStreaming() || method->BidiStreaming()) { continue; }
continue;
}
vars["method_id_name"] = MethodIdFieldName(&*method); vars["method_id_name"] = MethodIdFieldName(&*method);
vars["lower_method_name"] = LowerMethodName(&*method); vars["lower_method_name"] = LowerMethodName(&*method);
vars["input_type"] = JavaClassName(vars, method->get_input_type_name()); vars["input_type"] = JavaClassName(vars, method->get_input_type_name());
@@ -789,9 +777,7 @@ static void PrintMethodHandlerClass(Printer* p, VARS& vars,
for (int i = 0; i < service->method_count(); ++i) { for (int i = 0; i < service->method_count(); ++i) {
auto method = service->method(i); auto method = service->method(i);
if (!(method->ClientStreaming() || method->BidiStreaming())) { if (!(method->ClientStreaming() || method->BidiStreaming())) { continue; }
continue;
}
vars["method_id_name"] = MethodIdFieldName(&*method); vars["method_id_name"] = MethodIdFieldName(&*method);
vars["lower_method_name"] = LowerMethodName(&*method); vars["lower_method_name"] = LowerMethodName(&*method);
vars["input_type"] = JavaClassName(vars, method->get_input_type_name()); vars["input_type"] = JavaClassName(vars, method->get_input_type_name());
@@ -925,8 +911,10 @@ static void PrintBindServiceMethodBody(Printer* p, VARS& vars,
vars["input_type"] = JavaClassName(vars, method->get_input_type_name()); vars["input_type"] = JavaClassName(vars, method->get_input_type_name());
vars["output_type"] = JavaClassName(vars, method->get_output_type_name()); vars["output_type"] = JavaClassName(vars, method->get_output_type_name());
vars["method_id_name"] = MethodIdFieldName(&*method); vars["method_id_name"] = MethodIdFieldName(&*method);
bool client_streaming = method->ClientStreaming() || method->BidiStreaming(); bool client_streaming =
bool server_streaming = method->ServerStreaming() || method->BidiStreaming(); method->ClientStreaming() || method->BidiStreaming();
bool server_streaming =
method->ServerStreaming() || method->BidiStreaming();
if (client_streaming) { if (client_streaming) {
if (server_streaming) { if (server_streaming) {
vars["calls_method"] = "asyncBidiStreamingCall"; vars["calls_method"] = "asyncBidiStreamingCall";