generateConstants method
Writes Dart constants for the service and message descriptors.
The map includes an entry for every message type that might need to be read or written (assuming the type name resolved).
Implementation
void generateConstants(IndentingWriter out) {
out.print('const $coreImportPrefix.Map<$coreImportPrefix.String,'
' $coreImportPrefix.dynamic> $jsonConstant = ');
writeJsonConst(out, _descriptor.writeToJsonMap());
out.println(';');
out.println();
final typeConstants = <String, String>{};
for (final key in _transitiveDeps.keys) {
typeConstants[key] = _transitiveDeps[key]!.getJsonConstant(fileGen);
}
out.println('@$coreImportPrefix.Deprecated'
'(\'Use $binaryDescriptorName instead\')');
out.addBlock(
'const $coreImportPrefix.Map<$coreImportPrefix.String,'
' $coreImportPrefix.Map<$coreImportPrefix.String,'
' $coreImportPrefix.dynamic>> $messageJsonConstant = {',
'};', () {
for (final key in typeConstants.keys) {
final typeConst = typeConstants[key];
out.println("'$key': $typeConst,");
}
});
out.println();
if (_undefinedDeps.isNotEmpty) {
for (final name in _undefinedDeps.keys) {
final location = _undefinedDeps[name];
out.println("// can't resolve ($name) used by $location");
}
out.println();
}
}