|
|
@ -113,6 +113,29 @@ void PrintAdvancedSignature(Printer* printer, const MethodDescriptor* method, |
|
|
|
PrintMethodSignature(printer, method, vars); |
|
|
|
PrintMethodSignature(printer, method, vars); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PrintV2Signature(Printer* printer, const MethodDescriptor* method, |
|
|
|
|
|
|
|
map< ::grpc::string, ::grpc::string> vars) { |
|
|
|
|
|
|
|
if (method->client_streaming()) { |
|
|
|
|
|
|
|
vars["return_type"] = "GRPCStreamingProtoCall *"; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
vars["return_type"] = "GRPCUnaryProtoCall *"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
vars["method_name"] = |
|
|
|
|
|
|
|
grpc_generator::LowercaseFirstLetter(vars["method_name"]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PrintAllComments(method, printer); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printer->Print(vars, "- ($return_type$)$method_name$With"); |
|
|
|
|
|
|
|
if (method->client_streaming()) { |
|
|
|
|
|
|
|
printer->Print("ResponseHandler:(id<GRPCResponseHandler>)handler"); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
printer->Print(vars, |
|
|
|
|
|
|
|
"Message:($request_class$ *)message " |
|
|
|
|
|
|
|
"responseHandler:(id<GRPCResponseHandler>)handler"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
printer->Print(" callOptions:(GRPCCallOptions *_Nullable)callOptions"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
inline map< ::grpc::string, ::grpc::string> GetMethodVars( |
|
|
|
inline map< ::grpc::string, ::grpc::string> GetMethodVars( |
|
|
|
const MethodDescriptor* method) { |
|
|
|
const MethodDescriptor* method) { |
|
|
|
map< ::grpc::string, ::grpc::string> res; |
|
|
|
map< ::grpc::string, ::grpc::string> res; |
|
|
@ -135,6 +158,16 @@ void PrintMethodDeclarations(Printer* printer, const MethodDescriptor* method) { |
|
|
|
printer->Print(";\n\n\n"); |
|
|
|
printer->Print(";\n\n\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PrintV2MethodDeclarations(Printer* printer, |
|
|
|
|
|
|
|
const MethodDescriptor* method) { |
|
|
|
|
|
|
|
map< ::grpc::string, ::grpc::string> vars = GetMethodVars(method); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PrintProtoRpcDeclarationAsPragma(printer, method, vars); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PrintV2Signature(printer, method, vars); |
|
|
|
|
|
|
|
printer->Print(";\n\n"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PrintSimpleImplementation(Printer* printer, const MethodDescriptor* method, |
|
|
|
void PrintSimpleImplementation(Printer* printer, const MethodDescriptor* method, |
|
|
|
map< ::grpc::string, ::grpc::string> vars) { |
|
|
|
map< ::grpc::string, ::grpc::string> vars) { |
|
|
|
printer->Print("{\n"); |
|
|
|
printer->Print("{\n"); |
|
|
@ -177,6 +210,25 @@ void PrintAdvancedImplementation(Printer* printer, |
|
|
|
printer->Print("}\n"); |
|
|
|
printer->Print("}\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PrintV2Implementation(Printer* printer, const MethodDescriptor* method, |
|
|
|
|
|
|
|
map< ::grpc::string, ::grpc::string> vars) { |
|
|
|
|
|
|
|
printer->Print(" {\n"); |
|
|
|
|
|
|
|
if (method->client_streaming()) { |
|
|
|
|
|
|
|
printer->Print(vars, " return [self RPCToMethod:@\"$method_name$\"\n"); |
|
|
|
|
|
|
|
printer->Print(" responseHandler:handler\n"); |
|
|
|
|
|
|
|
printer->Print(" callOptions:callOptions\n"); |
|
|
|
|
|
|
|
printer->Print( |
|
|
|
|
|
|
|
vars, " responseClass:[$response_class$ class]];\n}\n\n"); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
printer->Print(vars, " return [self RPCToMethod:@\"$method_name$\"\n"); |
|
|
|
|
|
|
|
printer->Print(" message:message\n"); |
|
|
|
|
|
|
|
printer->Print(" responseHandler:handler\n"); |
|
|
|
|
|
|
|
printer->Print(" callOptions:callOptions\n"); |
|
|
|
|
|
|
|
printer->Print( |
|
|
|
|
|
|
|
vars, " responseClass:[$response_class$ class]];\n}\n\n"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PrintMethodImplementations(Printer* printer, |
|
|
|
void PrintMethodImplementations(Printer* printer, |
|
|
|
const MethodDescriptor* method) { |
|
|
|
const MethodDescriptor* method) { |
|
|
|
map< ::grpc::string, ::grpc::string> vars = GetMethodVars(method); |
|
|
|
map< ::grpc::string, ::grpc::string> vars = GetMethodVars(method); |
|
|
@ -184,12 +236,16 @@ void PrintMethodImplementations(Printer* printer, |
|
|
|
PrintProtoRpcDeclarationAsPragma(printer, method, vars); |
|
|
|
PrintProtoRpcDeclarationAsPragma(printer, method, vars); |
|
|
|
|
|
|
|
|
|
|
|
// TODO(jcanizales): Print documentation from the method.
|
|
|
|
// TODO(jcanizales): Print documentation from the method.
|
|
|
|
|
|
|
|
printer->Print("// Deprecated methods.\n"); |
|
|
|
PrintSimpleSignature(printer, method, vars); |
|
|
|
PrintSimpleSignature(printer, method, vars); |
|
|
|
PrintSimpleImplementation(printer, method, vars); |
|
|
|
PrintSimpleImplementation(printer, method, vars); |
|
|
|
|
|
|
|
|
|
|
|
printer->Print("// Returns a not-yet-started RPC object.\n"); |
|
|
|
printer->Print("// Returns a not-yet-started RPC object.\n"); |
|
|
|
PrintAdvancedSignature(printer, method, vars); |
|
|
|
PrintAdvancedSignature(printer, method, vars); |
|
|
|
PrintAdvancedImplementation(printer, method, vars); |
|
|
|
PrintAdvancedImplementation(printer, method, vars); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PrintV2Signature(printer, method, vars); |
|
|
|
|
|
|
|
PrintV2Implementation(printer, method, vars); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
} // namespace
|
|
|
@ -231,6 +287,25 @@ void PrintMethodImplementations(Printer* printer, |
|
|
|
return output; |
|
|
|
return output; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
::grpc::string GetV2Protocol(const ServiceDescriptor* service) { |
|
|
|
|
|
|
|
::grpc::string output; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Scope the output stream so it closes and finalizes output to the string.
|
|
|
|
|
|
|
|
grpc::protobuf::io::StringOutputStream output_stream(&output); |
|
|
|
|
|
|
|
Printer printer(&output_stream, '$'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
map< ::grpc::string, ::grpc::string> vars = { |
|
|
|
|
|
|
|
{"service_class", ServiceClassName(service) + "2"}}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printer.Print(vars, "@protocol $service_class$ <NSObject>\n\n"); |
|
|
|
|
|
|
|
for (int i = 0; i < service->method_count(); i++) { |
|
|
|
|
|
|
|
PrintV2MethodDeclarations(&printer, service->method(i)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
printer.Print("@end\n\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return output; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
::grpc::string GetInterface(const ServiceDescriptor* service) { |
|
|
|
::grpc::string GetInterface(const ServiceDescriptor* service) { |
|
|
|
::grpc::string output; |
|
|
|
::grpc::string output; |
|
|
|
|
|
|
|
|
|
|
@ -248,10 +323,16 @@ void PrintMethodImplementations(Printer* printer, |
|
|
|
" */\n"); |
|
|
|
" */\n"); |
|
|
|
printer.Print(vars, |
|
|
|
printer.Print(vars, |
|
|
|
"@interface $service_class$ :" |
|
|
|
"@interface $service_class$ :" |
|
|
|
" GRPCProtoService<$service_class$>\n"); |
|
|
|
" GRPCProtoService<$service_class$, $service_class$2>\n"); |
|
|
|
printer.Print( |
|
|
|
printer.Print( |
|
|
|
"- (instancetype)initWithHost:(NSString *)host " |
|
|
|
"- (instancetype)initWithHost:(NSString *)host " |
|
|
|
|
|
|
|
"callOptions:(GRPCCallOptions " |
|
|
|
|
|
|
|
"*_Nullable)callOptions" |
|
|
|
" NS_DESIGNATED_INITIALIZER;\n"); |
|
|
|
" NS_DESIGNATED_INITIALIZER;\n"); |
|
|
|
|
|
|
|
printer.Print("- (instancetype)initWithHost:(NSString *)host;\n"); |
|
|
|
|
|
|
|
printer.Print( |
|
|
|
|
|
|
|
"+ (instancetype)serviceWithHost:(NSString *)host " |
|
|
|
|
|
|
|
"callOptions:(GRPCCallOptions *_Nullable)callOptions;\n"); |
|
|
|
printer.Print("+ (instancetype)serviceWithHost:(NSString *)host;\n"); |
|
|
|
printer.Print("+ (instancetype)serviceWithHost:(NSString *)host;\n"); |
|
|
|
printer.Print("@end\n"); |
|
|
|
printer.Print("@end\n"); |
|
|
|
|
|
|
|
|
|
|
@ -273,11 +354,19 @@ void PrintMethodImplementations(Printer* printer, |
|
|
|
printer.Print(vars, |
|
|
|
printer.Print(vars, |
|
|
|
"@implementation $service_class$\n\n" |
|
|
|
"@implementation $service_class$\n\n" |
|
|
|
"// Designated initializer\n" |
|
|
|
"// Designated initializer\n" |
|
|
|
"- (instancetype)initWithHost:(NSString *)host {\n" |
|
|
|
"- (instancetype)initWithHost:(NSString *)host " |
|
|
|
|
|
|
|
"callOptions:(GRPCCallOptions *_Nullable)callOptions{\n" |
|
|
|
" self = [super initWithHost:host\n" |
|
|
|
" self = [super initWithHost:host\n" |
|
|
|
" packageName:@\"$package$\"\n" |
|
|
|
" packageName:@\"$package$\"\n" |
|
|
|
" serviceName:@\"$service_name$\"];\n" |
|
|
|
" serviceName:@\"$service_name$\"\n" |
|
|
|
|
|
|
|
" callOptions:callOptions];\n" |
|
|
|
" return self;\n" |
|
|
|
" return self;\n" |
|
|
|
|
|
|
|
"}\n\n" |
|
|
|
|
|
|
|
"- (instancetype)initWithHost:(NSString *)host {\n" |
|
|
|
|
|
|
|
" return [self initWithHost:host\n" |
|
|
|
|
|
|
|
" packageName:@\"$package$\"\n" |
|
|
|
|
|
|
|
" serviceName:@\"$service_name$\"\n" |
|
|
|
|
|
|
|
" callOptions:nil];\n" |
|
|
|
"}\n\n"); |
|
|
|
"}\n\n"); |
|
|
|
|
|
|
|
|
|
|
|
printer.Print( |
|
|
|
printer.Print( |
|
|
@ -292,7 +381,11 @@ void PrintMethodImplementations(Printer* printer, |
|
|
|
printer.Print( |
|
|
|
printer.Print( |
|
|
|
"#pragma mark - Class Methods\n\n" |
|
|
|
"#pragma mark - Class Methods\n\n" |
|
|
|
"+ (instancetype)serviceWithHost:(NSString *)host {\n" |
|
|
|
"+ (instancetype)serviceWithHost:(NSString *)host {\n" |
|
|
|
" return [[self alloc] initWithHost:host];\n" |
|
|
|
" return [self serviceWithHost:host callOptions:nil];\n" |
|
|
|
|
|
|
|
"}\n\n" |
|
|
|
|
|
|
|
"+ (instancetype)serviceWithHost:(NSString *)host " |
|
|
|
|
|
|
|
"callOptions:(GRPCCallOptions *_Nullable)callOptions {\n" |
|
|
|
|
|
|
|
" return [[self alloc] initWithHost:host callOptions:callOptions];\n" |
|
|
|
"}\n\n"); |
|
|
|
"}\n\n"); |
|
|
|
|
|
|
|
|
|
|
|
printer.Print("#pragma mark - Method Implementations\n\n"); |
|
|
|
printer.Print("#pragma mark - Method Implementations\n\n"); |
|
|
|