generateJsonFile method

String generateJsonFile([
  1. OutputConfiguration config = const DefaultOutputConfiguration()
])

Returns the contents of the .pbjson.dart file for this .proto file.

Implementation

String generateJsonFile(
    [OutputConfiguration config = const DefaultOutputConfiguration()]) {
  if (!_linked) throw StateError('not linked');
  final out = makeWriter();
  _writeHeading(out);

  final importWriter = ImportWriter();
  importWriter.addImport(_convertImportUrl, prefix: _convertImportPrefix);
  importWriter.addImport(_coreImportUrl, prefix: coreImportPrefix);
  importWriter.addImport(_typedDataImportUrl, prefix: _typedDataImportPrefix);

  // Import the .pbjson.dart files we depend on.
  final imports = _findJsonProtosToImport();
  for (final target in imports) {
    _addImport(importWriter, config, target, '.pbjson.dart');
  }

  out.println(importWriter.emit());

  for (final e in enumGenerators) {
    e.generateConstants(out);
    writeBinaryDescriptor(
        out, e.binaryDescriptorName, e._descriptor.name, e._descriptor);
    out.println('');
  }
  for (final m in messageGenerators) {
    m.generateConstants(out);
    writeBinaryDescriptor(
        out, m.binaryDescriptorName, m._descriptor.name, m._descriptor);
    out.println('');
  }
  for (final s in serviceGenerators) {
    s.generateConstants(out);
    writeBinaryDescriptor(
        out, s.binaryDescriptorName, s._descriptor.name, s._descriptor);
    out.println('');
  }

  return out.toString();
}