Skip to content

Commit

Permalink
update trpc protocol method name
Browse files Browse the repository at this point in the history
  • Loading branch information
holmes1412 committed Mar 19, 2021
1 parent 999ce77 commit 87f9723
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/generator/printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,16 @@ static inline std::string make_trpc_service_prefix(const std::vector<std::string
return package_prefix + service;
}

static inline std::string make_trpc_method_prefix(const std::string& service,
static inline std::string make_trpc_method_prefix(const std::vector<std::string>& package,
const std::string& service,
const std::string& method)
{
return "/package." + service + "/" + method;
std::string method_prefix = "/";

for (size_t i = 0; i < package.size(); i++)
method_prefix = method_prefix + package[i] + ".";

return method_prefix + service + "/" + method;
}

static inline bool is_simple_type(int8_t data_type)
Expand Down Expand Up @@ -668,7 +674,8 @@ class Printer

void print_client_methods(const std::string& type,
const std::string& service,
const std::vector<rpc_descriptor>& rpcs)
const std::vector<rpc_descriptor>& rpcs,
const std::vector<std::string>& package)
{
for (const auto& rpc : rpcs)
{
Expand All @@ -677,7 +684,7 @@ class Printer

std::string full_method = rpc.method_name;
if (type == "TRPC")
full_method = make_trpc_method_prefix(service, rpc.method_name);
full_method = make_trpc_method_prefix(package, service, rpc.method_name);

fprintf(this->out_file, this->client_method_format.c_str(),
type.c_str(), rpc.method_name.c_str(),
Expand Down Expand Up @@ -759,13 +766,14 @@ class Printer
}

void print_client_create_task(const std::string& type, const std::string& service,
const std::vector<rpc_descriptor>& rpcs)
const std::vector<rpc_descriptor>& rpcs,
const std::vector<std::string>& package)
{
for (const auto& rpc : rpcs)
{
std::string full_method = rpc.method_name;
if (type == "TRPC")
full_method = make_trpc_method_prefix(service, rpc.method_name);
full_method = make_trpc_method_prefix(package, service, rpc.method_name);

fprintf(this->out_file, this->client_create_task_format.c_str(),
type.c_str(), type.c_str(), rpc.method_name.c_str(),
Expand Down

0 comments on commit 87f9723

Please sign in to comment.