generateGrpcFile method
Returns the contents of the .pbgrpc.dart file for this .proto file.
Implementation
String generateGrpcFile(
[OutputConfiguration config = const DefaultOutputConfiguration()]) {
if (!_linked) throw StateError('not linked');
final out = makeWriter();
_writeHeading(out);
final importWriter = ImportWriter();
importWriter.addImport(_asyncImportUrl, prefix: asyncImportPrefix);
importWriter.addImport(_coreImportUrl, prefix: coreImportPrefix);
importWriter.addImport(_grpcImportUrl, prefix: grpcImportPrefix);
importWriter.addImport(_protobufImportUrl, prefix: protobufImportPrefix);
// Import .pb.dart files needed for requests and responses.
final imports = <FileGenerator>{};
for (final generator in grpcGenerators) {
generator.addImportsTo(imports);
}
for (final target in imports) {
_addImport(importWriter, config, target, '.pb.dart');
}
final url = config.resolveImport(protoFileUri, protoFileUri, '.pb.dart');
importWriter.addExport(url.toString());
out.println(importWriter.emit());
for (final generator in grpcGenerators) {
generator.generate(out);
}
return out.toString();
}