generateMethod method

void generateMethod(
  1. IndentingWriter out,
  2. MethodDescriptorProto method,
  3. int methodIndex
)

Implementation

void generateMethod(
  IndentingWriter out,
  MethodDescriptorProto method,
  int methodIndex,
) {
  final methodName = disambiguateName(
    avoidInitialUnderscore(service._methodName(method.name)),
    usedMethodNames,
    defaultSuffixes(),
  );
  final inputType = service._getDartClassName(
    method.inputType,
    forMainFile: true,
  );
  final outputType = service._getDartClassName(
    method.outputType,
    forMainFile: true,
  );
  final commentBlock = service.fileGen.commentBlock(
    _methodDescriptorPath(methodIndex),
  );
  if (commentBlock != null) {
    out.println(commentBlock);
  }
  if (method.options.deprecated) {
    out.println(
      '@$coreImportPrefix.Deprecated(\'This method is deprecated\')',
    );
  }
  out.addBlock(
    '$asyncImportPrefix.Future<$outputType> $methodName('
        '$protobufImportPrefix.ClientContext? ctx, $inputType request) =>',
    ';',
    () {
      out.println(
        '_client.invoke<$outputType>(ctx, \'$className\', '
        '\'${method.name}\', request, $outputType())',
      );
    },
  );
}