|
|
|
@ -756,6 +756,29 @@ static bool GenerateGrpc(GeneratorContext* context, PrivateGenerator& generator, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static bool ParseParameters(const grpc::string& parameter, |
|
|
|
|
grpc::string* grpc_version, |
|
|
|
|
std::vector<grpc::string>* strip_prefixes, |
|
|
|
|
grpc::string* error) { |
|
|
|
|
std::vector<grpc::string> comma_delimited_parameters; |
|
|
|
|
grpc_python_generator::Split(parameter, ',', &comma_delimited_parameters); |
|
|
|
|
if (comma_delimited_parameters.size() == 1 && |
|
|
|
|
comma_delimited_parameters[0].empty()) { |
|
|
|
|
*grpc_version = "grpc_2_0"; |
|
|
|
|
} else if (comma_delimited_parameters.size() == 1) { |
|
|
|
|
*grpc_version = comma_delimited_parameters[0]; |
|
|
|
|
} else if (comma_delimited_parameters.size() == 2) { |
|
|
|
|
*grpc_version = comma_delimited_parameters[0]; |
|
|
|
|
std::copy(comma_delimited_parameters.begin() + 1, |
|
|
|
|
comma_delimited_parameters.end(), |
|
|
|
|
std::back_inserter(*strip_prefixes)); |
|
|
|
|
} else { |
|
|
|
|
*error = "--grpc_python_out received too many comma-delimited parameters."; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool PythonGrpcGenerator::Generate(const FileDescriptor* file, |
|
|
|
|
const grpc::string& parameter, |
|
|
|
|
GeneratorContext* context, |
|
|
|
@ -778,14 +801,19 @@ bool PythonGrpcGenerator::Generate(const FileDescriptor* file, |
|
|
|
|
generator_file_name = file->name(); |
|
|
|
|
|
|
|
|
|
ProtoBufFile pbfile(file); |
|
|
|
|
PrivateGenerator generator(config_, &pbfile); |
|
|
|
|
if (parameter == "" || parameter == "grpc_2_0") { |
|
|
|
|
grpc::string grpc_version; |
|
|
|
|
GeneratorConfiguration extended_config(config_); |
|
|
|
|
bool success = ParseParameters(parameter, &grpc_version, |
|
|
|
|
&(extended_config.prefixes_to_filter), error); |
|
|
|
|
PrivateGenerator generator(extended_config, &pbfile); |
|
|
|
|
if (!success) return false; |
|
|
|
|
if (grpc_version == "grpc_2_0") { |
|
|
|
|
return GenerateGrpc(context, generator, pb2_grpc_file_name, true); |
|
|
|
|
} else if (parameter == "grpc_1_0") { |
|
|
|
|
} else if (grpc_version == "grpc_1_0") { |
|
|
|
|
return GenerateGrpc(context, generator, pb2_grpc_file_name, true) && |
|
|
|
|
GenerateGrpc(context, generator, pb2_file_name, false); |
|
|
|
|
} else { |
|
|
|
|
*error = "Invalid parameter '" + parameter + "'."; |
|
|
|
|
*error = "Invalid grpc version '" + grpc_version + "'."; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|