|
|
@ -32,24 +32,20 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
#include <cctype> |
|
|
|
#include <cctype> |
|
|
|
#include <string> |
|
|
|
|
|
|
|
#include <map> |
|
|
|
#include <map> |
|
|
|
#include <vector> |
|
|
|
#include <vector> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "src/compiler/config.h" |
|
|
|
#include "src/compiler/ruby_generator.h" |
|
|
|
#include "src/compiler/ruby_generator.h" |
|
|
|
#include "src/compiler/ruby_generator_helpers-inl.h" |
|
|
|
#include "src/compiler/ruby_generator_helpers-inl.h" |
|
|
|
#include "src/compiler/ruby_generator_map-inl.h" |
|
|
|
#include "src/compiler/ruby_generator_map-inl.h" |
|
|
|
#include "src/compiler/ruby_generator_string-inl.h" |
|
|
|
#include "src/compiler/ruby_generator_string-inl.h" |
|
|
|
#include <google/protobuf/io/printer.h> |
|
|
|
|
|
|
|
#include <google/protobuf/io/zero_copy_stream_impl_lite.h> |
|
|
|
using grpc::protobuf::FileDescriptor; |
|
|
|
#include <google/protobuf/descriptor.pb.h> |
|
|
|
using grpc::protobuf::ServiceDescriptor; |
|
|
|
#include <google/protobuf/descriptor.h> |
|
|
|
using grpc::protobuf::MethodDescriptor; |
|
|
|
|
|
|
|
using grpc::protobuf::io::Printer; |
|
|
|
using google::protobuf::FileDescriptor; |
|
|
|
using grpc::protobuf::io::StringOutputStream; |
|
|
|
using google::protobuf::ServiceDescriptor; |
|
|
|
|
|
|
|
using google::protobuf::MethodDescriptor; |
|
|
|
|
|
|
|
using google::protobuf::io::Printer; |
|
|
|
|
|
|
|
using google::protobuf::io::StringOutputStream; |
|
|
|
|
|
|
|
using std::map; |
|
|
|
using std::map; |
|
|
|
using std::vector; |
|
|
|
using std::vector; |
|
|
|
|
|
|
|
|
|
|
@ -57,38 +53,38 @@ namespace grpc_ruby_generator { |
|
|
|
namespace { |
|
|
|
namespace { |
|
|
|
|
|
|
|
|
|
|
|
// Prints out the method using the ruby gRPC DSL.
|
|
|
|
// Prints out the method using the ruby gRPC DSL.
|
|
|
|
void PrintMethod(const MethodDescriptor *method, const std::string &package, |
|
|
|
void PrintMethod(const MethodDescriptor *method, const grpc::string &package, |
|
|
|
Printer *out) { |
|
|
|
Printer *out) { |
|
|
|
std::string input_type = RubyTypeOf(method->input_type()->name(), package); |
|
|
|
grpc::string input_type = RubyTypeOf(method->input_type()->name(), package); |
|
|
|
if (method->client_streaming()) { |
|
|
|
if (method->client_streaming()) { |
|
|
|
input_type = "stream(" + input_type + ")"; |
|
|
|
input_type = "stream(" + input_type + ")"; |
|
|
|
} |
|
|
|
} |
|
|
|
std::string output_type = RubyTypeOf(method->output_type()->name(), package); |
|
|
|
grpc::string output_type = RubyTypeOf(method->output_type()->name(), package); |
|
|
|
if (method->server_streaming()) { |
|
|
|
if (method->server_streaming()) { |
|
|
|
output_type = "stream(" + output_type + ")"; |
|
|
|
output_type = "stream(" + output_type + ")"; |
|
|
|
} |
|
|
|
} |
|
|
|
std::map<std::string, std::string> method_vars = |
|
|
|
std::map<grpc::string, grpc::string> method_vars = |
|
|
|
ListToDict({"mth.name", method->name(), "input.type", input_type, |
|
|
|
ListToDict({"mth.name", method->name(), "input.type", input_type, |
|
|
|
"output.type", output_type, }); |
|
|
|
"output.type", output_type, }); |
|
|
|
out->Print(method_vars, "rpc :$mth.name$, $input.type$, $output.type$\n"); |
|
|
|
out->Print(method_vars, "rpc :$mth.name$, $input.type$, $output.type$\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Prints out the service using the ruby gRPC DSL.
|
|
|
|
// Prints out the service using the ruby gRPC DSL.
|
|
|
|
void PrintService(const ServiceDescriptor *service, const std::string &package, |
|
|
|
void PrintService(const ServiceDescriptor *service, const grpc::string &package, |
|
|
|
Printer *out) { |
|
|
|
Printer *out) { |
|
|
|
if (service->method_count() == 0) { |
|
|
|
if (service->method_count() == 0) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Begin the service module
|
|
|
|
// Begin the service module
|
|
|
|
std::map<std::string, std::string> module_vars = |
|
|
|
std::map<grpc::string, grpc::string> module_vars = |
|
|
|
ListToDict({"module.name", CapitalizeFirst(service->name()), }); |
|
|
|
ListToDict({"module.name", CapitalizeFirst(service->name()), }); |
|
|
|
out->Print(module_vars, "module $module.name$\n"); |
|
|
|
out->Print(module_vars, "module $module.name$\n"); |
|
|
|
out->Indent(); |
|
|
|
out->Indent(); |
|
|
|
|
|
|
|
|
|
|
|
// TODO(temiola): add documentation
|
|
|
|
// TODO(temiola): add documentation
|
|
|
|
std::string doc = "TODO: add proto service documentation here"; |
|
|
|
grpc::string doc = "TODO: add proto service documentation here"; |
|
|
|
std::map<std::string, std::string> template_vars = |
|
|
|
std::map<grpc::string, grpc::string> template_vars = |
|
|
|
ListToDict({"Documentation", doc, }); |
|
|
|
ListToDict({"Documentation", doc, }); |
|
|
|
out->Print("\n"); |
|
|
|
out->Print("\n"); |
|
|
|
out->Print(template_vars, "# $Documentation$\n"); |
|
|
|
out->Print(template_vars, "# $Documentation$\n"); |
|
|
@ -101,7 +97,7 @@ void PrintService(const ServiceDescriptor *service, const std::string &package, |
|
|
|
out->Print("\n"); |
|
|
|
out->Print("\n"); |
|
|
|
out->Print("self.marshal_class_method = :encode\n"); |
|
|
|
out->Print("self.marshal_class_method = :encode\n"); |
|
|
|
out->Print("self.unmarshal_class_method = :decode\n"); |
|
|
|
out->Print("self.unmarshal_class_method = :decode\n"); |
|
|
|
std::map<std::string, std::string> pkg_vars = |
|
|
|
std::map<grpc::string, grpc::string> pkg_vars = |
|
|
|
ListToDict({"service.name", service->name(), "pkg.name", package, }); |
|
|
|
ListToDict({"service.name", service->name(), "pkg.name", package, }); |
|
|
|
out->Print(pkg_vars, "self.service_name = '$pkg.name$.$service.name$'\n"); |
|
|
|
out->Print(pkg_vars, "self.service_name = '$pkg.name$.$service.name$'\n"); |
|
|
|
out->Print("\n"); |
|
|
|
out->Print("\n"); |
|
|
@ -121,8 +117,8 @@ void PrintService(const ServiceDescriptor *service, const std::string &package, |
|
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
std::string GetServices(const FileDescriptor *file) { |
|
|
|
grpc::string GetServices(const FileDescriptor *file) { |
|
|
|
std::string output; |
|
|
|
grpc::string output; |
|
|
|
StringOutputStream output_stream(&output); |
|
|
|
StringOutputStream output_stream(&output); |
|
|
|
Printer out(&output_stream, '$'); |
|
|
|
Printer out(&output_stream, '$'); |
|
|
|
|
|
|
|
|
|
|
@ -133,7 +129,7 @@ std::string GetServices(const FileDescriptor *file) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Write out a file header.
|
|
|
|
// Write out a file header.
|
|
|
|
std::map<std::string, std::string> header_comment_vars = ListToDict( |
|
|
|
std::map<grpc::string, grpc::string> header_comment_vars = ListToDict( |
|
|
|
{"file.name", file->name(), "file.package", file->package(), }); |
|
|
|
{"file.name", file->name(), "file.package", file->package(), }); |
|
|
|
out.Print("# Generated by the protocol buffer compiler. DO NOT EDIT!\n"); |
|
|
|
out.Print("# Generated by the protocol buffer compiler. DO NOT EDIT!\n"); |
|
|
|
out.Print(header_comment_vars, |
|
|
|
out.Print(header_comment_vars, |
|
|
@ -144,15 +140,15 @@ std::string GetServices(const FileDescriptor *file) { |
|
|
|
// Write out require statemment to import the separately generated file
|
|
|
|
// Write out require statemment to import the separately generated file
|
|
|
|
// that defines the messages used by the service. This is generated by the
|
|
|
|
// that defines the messages used by the service. This is generated by the
|
|
|
|
// main ruby plugin.
|
|
|
|
// main ruby plugin.
|
|
|
|
std::map<std::string, std::string> dep_vars = |
|
|
|
std::map<grpc::string, grpc::string> dep_vars = |
|
|
|
ListToDict({"dep.name", MessagesRequireName(file), }); |
|
|
|
ListToDict({"dep.name", MessagesRequireName(file), }); |
|
|
|
out.Print(dep_vars, "require '$dep.name$'\n"); |
|
|
|
out.Print(dep_vars, "require '$dep.name$'\n"); |
|
|
|
|
|
|
|
|
|
|
|
// Write out services within the modules
|
|
|
|
// Write out services within the modules
|
|
|
|
out.Print("\n"); |
|
|
|
out.Print("\n"); |
|
|
|
std::vector<std::string> modules = Split(file->package(), '.'); |
|
|
|
std::vector<grpc::string> modules = Split(file->package(), '.'); |
|
|
|
for (size_t i = 0; i < modules.size(); ++i) { |
|
|
|
for (size_t i = 0; i < modules.size(); ++i) { |
|
|
|
std::map<std::string, std::string> module_vars = |
|
|
|
std::map<grpc::string, grpc::string> module_vars = |
|
|
|
ListToDict({"module.name", CapitalizeFirst(modules[i]), }); |
|
|
|
ListToDict({"module.name", CapitalizeFirst(modules[i]), }); |
|
|
|
out.Print(module_vars, "module $module.name$\n"); |
|
|
|
out.Print(module_vars, "module $module.name$\n"); |
|
|
|
out.Indent(); |
|
|
|
out.Indent(); |
|
|
|