From 1ae0702c8161f46f4f8056b439b8f483aa902192 Mon Sep 17 00:00:00 2001 From: Nikolay Belov Date: Sat, 9 Nov 2019 10:55:52 +0300 Subject: [PATCH 1/2] 1) Add casting callback to void delegate(ubyte[])) in CMA 2) Fix generating service's process method: it should have third argument - ubyte[] complete --- compiler/src/dlang_plugin.cc | 2 +- source/grpc/GrpcCode.d | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/dlang_plugin.cc b/compiler/src/dlang_plugin.cc index 53daeb7..7983628 100644 --- a/compiler/src/dlang_plugin.cc +++ b/compiler/src/dlang_plugin.cc @@ -141,7 +141,7 @@ static void GenerateService(const std::string &module , CodedOutputStream &cos,c cos.WriteString("\n"); /// service's process - cos.WriteString("\tStatus process(string method , GrpcStream stream)\n"); + cos.WriteString("\tStatus process(string method , GrpcStream stream, ubyte[] complete)\n"); cos.WriteString("\t{\n"); cos.WriteString("\t\tswitch(method)\n"); cos.WriteString("\t\t{\n"); diff --git a/source/grpc/GrpcCode.d b/source/grpc/GrpcCode.d index 8d47664..badd67e 100644 --- a/source/grpc/GrpcCode.d +++ b/source/grpc/GrpcCode.d @@ -75,7 +75,7 @@ string CMA(O , string service , string funcs = __FUNCTION__)() string func = GetFunc(funcs); string code = `auto stream = _channel.createStream("/`~ service ~`/`~func~`"); - stream.setCallBack(dele); + stream.setCallBack(cast(void delegate(ubyte[]))dele); stream.write(request , false);`; return code; } From 0444d7622b23b3118320f89ab350daa7fef31557 Mon Sep 17 00:00:00 2001 From: Nikolay Belov Date: Mon, 11 Nov 2019 21:19:17 +0300 Subject: [PATCH 2/2] Fix generating import path to dependency --- compiler/src/dlang_plugin.cc | 4 ++-- compiler/src/generator_helpers.h | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/compiler/src/dlang_plugin.cc b/compiler/src/dlang_plugin.cc index 7983628..088762f 100644 --- a/compiler/src/dlang_plugin.cc +++ b/compiler/src/dlang_plugin.cc @@ -229,9 +229,9 @@ class DlangGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { { auto dep = file->dependency(i); if(dep->package() != "") - cos.WriteString("import " + dep->package() + "." + grpc_generator::StripProto(dep->name()) + ";\n"); + cos.WriteString("import " + dep->package() + "." + grpc_generator::StripProtoAndPath(dep->name()) + ";\n"); else - cos.WriteString("import " + grpc_generator::StripProto(dep->name()) + ";\n"); + cos.WriteString("import " + grpc_generator::StripProtoAndPath(dep->name()) + ";\n"); } cos.WriteString("\n\n"); diff --git a/compiler/src/generator_helpers.h b/compiler/src/generator_helpers.h index 42959a0..58826af 100644 --- a/compiler/src/generator_helpers.h +++ b/compiler/src/generator_helpers.h @@ -58,6 +58,20 @@ inline grpc::string StripProto(grpc::string filename) { return filename; } +inline grpc::string StripProtoAndPath(grpc::string filename) { + if (!StripSuffix(&filename, ".protodevel")) { + StripSuffix(&filename, ".proto"); + } + + for (size_t i = filename.size(); i > 0; --i) { + if (filename[i-1] == '\\' || filename[i-1] == '/') { + return filename.substr(i); + } + } + + return filename; +} + inline grpc::string StringReplace(grpc::string str, const grpc::string& from, const grpc::string& to, bool replace_all) { size_t pos = 0;