Commit f473bb99 authored by Feng Xiao's avatar Feng Xiao

Merge pull request #128 from krishnanm86/master

Source code refactoring. Extracted common functionality in cpp_helpers.c...
parents 001e82a7 2e9f5e3b
...@@ -580,19 +580,24 @@ void Generator::PrintServiceDescriptor( ...@@ -580,19 +580,24 @@ void Generator::PrintServiceDescriptor(
printer_->Print("])\n\n"); printer_->Print("])\n\n");
} }
void Generator::PrintServiceClass(const ServiceDescriptor& descriptor) const {
// Print the service. void Generator::PrintDescriptorKeyAndModuleName(const ServiceDescriptor& descriptor) const {
printer_->Print("$class_name$ = service_reflection.GeneratedServiceType("
"'$class_name$', (_service.Service,), dict(\n",
"class_name", descriptor.name());
printer_->Indent();
printer_->Print( printer_->Print(
"$descriptor_key$ = $descriptor_name$,\n", "$descriptor_key$ = $descriptor_name$,\n",
"descriptor_key", kDescriptorKey, "descriptor_key", kDescriptorKey,
"descriptor_name", ModuleLevelServiceDescriptorName(descriptor)); "descriptor_name", ModuleLevelServiceDescriptorName(descriptor));
printer_->Print( printer_->Print(
"__module__ = '$module_name$'\n", "__module__ = '$module_name$'\n",
"module_name", ModuleName(file_->name())); "module_name", ModuleName(file_->name()));
}
void Generator::PrintServiceClass(const ServiceDescriptor& descriptor) const {
// Print the service.
printer_->Print("$class_name$ = service_reflection.GeneratedServiceType("
"'$class_name$', (_service.Service,), dict(\n",
"class_name", descriptor.name());
printer_->Indent();
Generator::PrintDescriptorKeyAndModuleName(descriptor);
printer_->Print("))\n\n"); printer_->Print("))\n\n");
printer_->Outdent(); printer_->Outdent();
} }
...@@ -604,13 +609,7 @@ void Generator::PrintServiceStub(const ServiceDescriptor& descriptor) const { ...@@ -604,13 +609,7 @@ void Generator::PrintServiceStub(const ServiceDescriptor& descriptor) const {
"'$class_name$_Stub', ($class_name$,), dict(\n", "'$class_name$_Stub', ($class_name$,), dict(\n",
"class_name", descriptor.name()); "class_name", descriptor.name());
printer_->Indent(); printer_->Indent();
printer_->Print( Generator::PrintDescriptorKeyAndModuleName(descriptor);
"$descriptor_key$ = $descriptor_name$,\n",
"descriptor_key", kDescriptorKey,
"descriptor_name", ModuleLevelServiceDescriptorName(descriptor));
printer_->Print(
"__module__ = '$module_name$'\n",
"module_name", ModuleName(file_->name()));
printer_->Print("))\n\n"); printer_->Print("))\n\n");
printer_->Outdent(); printer_->Outdent();
} }
......
...@@ -127,6 +127,7 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator { ...@@ -127,6 +127,7 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator {
void PrintServiceDescriptor(const ServiceDescriptor& descriptor) const; void PrintServiceDescriptor(const ServiceDescriptor& descriptor) const;
void PrintServiceClass(const ServiceDescriptor& descriptor) const; void PrintServiceClass(const ServiceDescriptor& descriptor) const;
void PrintServiceStub(const ServiceDescriptor& descriptor) const; void PrintServiceStub(const ServiceDescriptor& descriptor) const;
void PrintDescriptorKeyAndModuleName(const ServiceDescriptor& descriptor) const ;
void PrintEnumValueDescriptor(const EnumValueDescriptor& descriptor) const; void PrintEnumValueDescriptor(const EnumValueDescriptor& descriptor) const;
string OptionsValue(const string& class_name, string OptionsValue(const string& class_name,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment