mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-14 16:36:55 +00:00
* Support for python grpc * add few fixes * Fixes build * Fix python generator * Add tests * Fix grpc python test * Fix tests and add incomplete python generator * Fix python generator * Add python generator methods * Fix Appveyor build * grpc python support v0.1 * Update tests * update grpctest * Remove duplicated code and fix a brace * tests for flatbuffers grpc python * Updated tests + removed SerializeToString, From String * remove pickle import * include missing files in ci - BUILD and generated test result
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
80988ea869
commit
6beb9f49cb
@@ -23,6 +23,8 @@
|
||||
#include "src/compiler/cpp_generator.h"
|
||||
#include "src/compiler/go_generator.h"
|
||||
#include "src/compiler/java_generator.h"
|
||||
#include "src/compiler/python_generator.h"
|
||||
#include "src/compiler/python_private_generator.h"
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# pragma warning(push)
|
||||
@@ -77,6 +79,10 @@ class FlatBufMethod : public grpc_generator::Method {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string get_fb_builder() const {
|
||||
return "builder";
|
||||
}
|
||||
|
||||
std::string input_type_name() const { return GRPCType(*method_->request); }
|
||||
|
||||
std::string output_type_name() const { return GRPCType(*method_->response); }
|
||||
@@ -179,7 +185,9 @@ class FlatBufPrinter : public grpc_generator::Printer {
|
||||
|
||||
class FlatBufFile : public grpc_generator::File {
|
||||
public:
|
||||
enum Language { kLanguageGo, kLanguageCpp, kLanguageJava };
|
||||
enum Language {
|
||||
kLanguageGo, kLanguageCpp, kLanguageJava, kLanguagePython
|
||||
};
|
||||
|
||||
FlatBufFile(const Parser &parser, const std::string &file_name,
|
||||
Language language)
|
||||
@@ -224,6 +232,9 @@ class FlatBufFile : public grpc_generator::File {
|
||||
case kLanguageJava: {
|
||||
return "import com.google.flatbuffers.grpc.FlatbuffersUtils;";
|
||||
}
|
||||
case kLanguagePython: {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
@@ -360,6 +371,38 @@ bool GenerateJavaGRPC(const Parser &parser, const std::string &path,
|
||||
return JavaGRPCGenerator(parser, path, file_name).generate();
|
||||
}
|
||||
|
||||
bool GeneratePythonGRPC(const Parser &parser, const std::string & /*path*/,
|
||||
const std::string &file_name) {
|
||||
|
||||
int nservices = 0;
|
||||
for (auto it = parser.services_.vec.begin(); it != parser.services_.vec.end();
|
||||
++it) {
|
||||
if (!(*it)->generated) nservices++;
|
||||
}
|
||||
if (!nservices) return true;
|
||||
|
||||
grpc_python_generator::GeneratorConfiguration config;
|
||||
config.grpc_package_root = "grpc";
|
||||
config.beta_package_root = "grpc.beta";
|
||||
config.import_prefix = "";
|
||||
|
||||
FlatBufFile fbfile(parser, file_name, FlatBufFile::kLanguagePython);
|
||||
|
||||
grpc_python_generator::PrivateGenerator generator(config, &fbfile);
|
||||
|
||||
std::string code = generator.GetGrpcServices();
|
||||
std::string namespace_dir;
|
||||
auto &namespaces = parser.namespaces_.back()->components;
|
||||
for (auto it = namespaces.begin(); it != namespaces.end(); ++it) {
|
||||
if (it != namespaces.begin()) namespace_dir += kPathSeparator;
|
||||
namespace_dir += *it;
|
||||
}
|
||||
|
||||
std::string grpc_py_filename =
|
||||
namespace_dir + kPathSeparator + file_name + "_grpc_fb.py";
|
||||
return flatbuffers::SaveFile(grpc_py_filename.c_str(), code, false);
|
||||
}
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
|
||||
Reference in New Issue
Block a user