Fix all strong mode warnings in protoc-plugin
Includes changes to the plugin, the generated code, the
benchmarks, and the tests.
Also, fix the benchmarks to work again. It has a hacky parser
for .pubspec-lock files that didn't work after the format changed.
Also, dartfmt modified files.
Review URL: https://chromiumcodereview.appspot.com//1829573002 .
diff --git a/.analysis_options b/.analysis_options
new file mode 100644
index 0000000..a10d4c5
--- /dev/null
+++ b/.analysis_options
@@ -0,0 +1,2 @@
+analyzer:
+ strong-mode: true
diff --git a/benchmark/lib/benchmarks/get_strings.dart b/benchmark/lib/benchmarks/get_strings.dart
index 72603c1..6b737f1 100644
--- a/benchmark/lib/benchmarks/get_strings.dart
+++ b/benchmark/lib/benchmarks/get_strings.dart
@@ -94,7 +94,6 @@
}
void _getStrings() {
- var expected = fillValue;
bool ok = true;
for (var line in grid.lines) {
ok = ok && line.cell1.isNotEmpty;
@@ -125,7 +124,7 @@
static const $id = BenchmarkID.GET_STRINGS;
static final $type = new BenchmarkType($id, $create);
- static $create(Request r) {
+ static GetStringsBenchmark $create(Request r) {
assert(r.params.hasMessageCount());
var value = null;
if (r.params.hasStringValue()) value = r.params.stringValue;
diff --git a/benchmark/lib/benchmarks/has_strings.dart b/benchmark/lib/benchmarks/has_strings.dart
index 8943093..1dc9cd4 100644
--- a/benchmark/lib/benchmarks/has_strings.dart
+++ b/benchmark/lib/benchmarks/has_strings.dart
@@ -124,7 +124,7 @@
static const $id = BenchmarkID.HAS_STRINGS;
static final $type = new BenchmarkType($id, $create);
- static $create(Request r) {
+ static HasStringsBenchmark $create(Request r) {
assert(r.params.hasMessageCount());
var value = null;
if (r.params.hasStringValue()) value = r.params.stringValue;
diff --git a/benchmark/lib/benchmarks/int32_json.dart b/benchmark/lib/benchmarks/int32_json.dart
index 1fb5850..414ce41 100644
--- a/benchmark/lib/benchmarks/int32_json.dart
+++ b/benchmark/lib/benchmarks/int32_json.dart
@@ -5,7 +5,8 @@
library protoc.benchmark.int32_json;
import '../benchmark.dart';
-import '../generated/benchmark.pb.dart' show BenchmarkID, Request, Params, Sample;
+import '../generated/benchmark.pb.dart'
+ show BenchmarkID, Request, Params, Sample;
import '../generated/int32grid.pb.dart' as pb;
/// A benchmark that deserializes a grid of int fields.
@@ -77,7 +78,7 @@
static const $id = BenchmarkID.READ_INT32_FIELDS_JSON;
static final $type = new BenchmarkType($id, $create);
- static $create(Request r) {
+ static Int32Benchmark $create(Request r) {
assert(r.params.hasInt32FieldCount());
assert(r.params.hasMessageCount());
return new Int32Benchmark(r.params.int32FieldCount, r.params.messageCount);
diff --git a/benchmark/lib/benchmarks/int64_json.dart b/benchmark/lib/benchmarks/int64_json.dart
index 289e3da..7b0c452 100644
--- a/benchmark/lib/benchmarks/int64_json.dart
+++ b/benchmark/lib/benchmarks/int64_json.dart
@@ -7,7 +7,8 @@
import 'package:fixnum/fixnum.dart' show Int64;
import '../benchmark.dart';
-import '../generated/benchmark.pb.dart' show BenchmarkID, Request, Params, Sample;
+import '../generated/benchmark.pb.dart'
+ show BenchmarkID, Request, Params, Sample;
import '../generated/int64grid.pb.dart' as pb;
/// A benchmark that deserializes a grid of int fields.
@@ -79,7 +80,7 @@
static const $id = BenchmarkID.READ_INT64_FIELDS_JSON;
static final $type = new BenchmarkType($id, $create);
- static $create(Request r) {
+ static Int64Benchmark $create(Request r) {
assert(r.params.hasInt64FieldCount());
assert(r.params.hasMessageCount());
return new Int64Benchmark(r.params.int64FieldCount, r.params.messageCount);
diff --git a/benchmark/lib/benchmarks/repeated_int32_json.dart b/benchmark/lib/benchmarks/repeated_int32_json.dart
index 0de84be..cd9fc0d 100644
--- a/benchmark/lib/benchmarks/repeated_int32_json.dart
+++ b/benchmark/lib/benchmarks/repeated_int32_json.dart
@@ -5,7 +5,8 @@
library protoc.benchmark.repeated_int32_json;
import '../benchmark.dart';
-import '../generated/benchmark.pb.dart' show BenchmarkID, Request, Params, Sample;
+import '../generated/benchmark.pb.dart'
+ show BenchmarkID, Request, Params, Sample;
import '../generated/int32grid.pb.dart' as pb;
/// A benchmark that deserializes a grid of repeated ints.
@@ -68,7 +69,7 @@
static const $id = BenchmarkID.READ_INT32_REPEATED_JSON;
static final $type = new BenchmarkType($id, $create);
- static $create(Request r) {
+ static RepeatedInt32Benchmark $create(Request r) {
assert(r.params.hasInt32RepeatCount());
assert(r.params.hasMessageCount());
return new RepeatedInt32Benchmark(
diff --git a/benchmark/lib/benchmarks/repeated_int64_json.dart b/benchmark/lib/benchmarks/repeated_int64_json.dart
index d7f3737..3ad18cd 100644
--- a/benchmark/lib/benchmarks/repeated_int64_json.dart
+++ b/benchmark/lib/benchmarks/repeated_int64_json.dart
@@ -7,7 +7,8 @@
import 'package:fixnum/fixnum.dart';
import '../benchmark.dart';
-import '../generated/benchmark.pb.dart' show BenchmarkID, Request, Params, Sample;
+import '../generated/benchmark.pb.dart'
+ show BenchmarkID, Request, Params, Sample;
import '../generated/int64grid.pb.dart' as pb;
/// A benchmark that deserializes a grid of repeated ints.
@@ -70,7 +71,7 @@
static const $id = BenchmarkID.READ_INT64_REPEATED_JSON;
static final $type = new BenchmarkType($id, $create);
- static $create(Request r) {
+ static RepeatedInt64Benchmark $create(Request r) {
assert(r.params.hasInt64RepeatCount());
assert(r.params.hasMessageCount());
return new RepeatedInt64Benchmark(
diff --git a/benchmark/lib/benchmarks/repeated_string_json.dart b/benchmark/lib/benchmarks/repeated_string_json.dart
index 4dd6a20..fbbc4e3 100644
--- a/benchmark/lib/benchmarks/repeated_string_json.dart
+++ b/benchmark/lib/benchmarks/repeated_string_json.dart
@@ -80,7 +80,7 @@
static const $id = BenchmarkID.READ_STRING_REPEATED_JSON;
static final $type = new BenchmarkType($id, $create);
- static $create(Request r) {
+ static RepeatedStringBenchmark $create(Request r) {
assert(r.params.hasStringFieldCount());
assert(r.params.hasMessageCount());
assert(r.params.hasStringSize());
diff --git a/benchmark/lib/benchmarks/set_strings.dart b/benchmark/lib/benchmarks/set_strings.dart
index be1da31..7b1bd71 100644
--- a/benchmark/lib/benchmarks/set_strings.dart
+++ b/benchmark/lib/benchmarks/set_strings.dart
@@ -98,7 +98,7 @@
static const $id = BenchmarkID.SET_STRINGS;
static final $type = new BenchmarkType($id, $create);
- static $create(Request r) {
+ static SetStringsBenchmark $create(Request r) {
assert(r.params.hasMessageCount());
var value = null;
if (r.params.hasStringValue()) value = r.params.stringValue;
diff --git a/benchmark/lib/benchmarks/string_json.dart b/benchmark/lib/benchmarks/string_json.dart
index 8e7c066..7d3cab2 100644
--- a/benchmark/lib/benchmarks/string_json.dart
+++ b/benchmark/lib/benchmarks/string_json.dart
@@ -86,7 +86,7 @@
static const $id = BenchmarkID.READ_STRING_FIELDS_JSON;
static final $type = new BenchmarkType($id, $create);
- static $create(Request r) {
+ static StringBenchmark $create(Request r) {
assert(r.params.hasStringFieldCount());
assert(r.params.hasMessageCount());
assert(r.params.hasStringSize());
diff --git a/benchmark/lib/dashboard_model.dart b/benchmark/lib/dashboard_model.dart
index 533d0c8..a7a6581 100644
--- a/benchmark/lib/dashboard_model.dart
+++ b/benchmark/lib/dashboard_model.dart
@@ -40,11 +40,11 @@
final Set<pb.Request> selections;
final rows = <Row>[];
- factory Table(pb.Suite suite) =>
- new Table._raw(suite, null, null, new Set<pb.Request>.from(suite.requests));
+ factory Table(pb.Suite suite) => new Table._raw(
+ suite, null, null, new Set<pb.Request>.from(suite.requests));
Table._raw(this.suite, this.baseline, this.report, this.selections) {
- var it = report == null ? [].iterator : report.responses.iterator;
+ Iterator it = report == null ? [].iterator : report.responses.iterator;
for (var r in suite.requests) {
var b = createBenchmark(r);
pb.Sample baseline;
@@ -60,8 +60,8 @@
new Table._raw(suite, baseline, report, selections);
Table withAllSelected() {
- return new Table._raw(suite, baseline, report,
- new Set<pb.Request>.from(suite.requests));
+ return new Table._raw(
+ suite, baseline, report, new Set<pb.Request>.from(suite.requests));
}
Table withNoneSelected() {
diff --git a/benchmark/lib/dashboard_view.dart b/benchmark/lib/dashboard_view.dart
index 011192a..9b56e64 100644
--- a/benchmark/lib/dashboard_view.dart
+++ b/benchmark/lib/dashboard_view.dart
@@ -73,7 +73,7 @@
this._jsonView);
factory DashboardView() {
- var elt = _template.clone(true);
+ Element elt = _template.clone(true);
find(String q) => elt.querySelector(q);
_Button button(q) => new _Button(find(q));
label(q) => new _Label(find(q));
@@ -97,7 +97,7 @@
Stream get onSelectAllClick => _selectAllButton.onClick;
Stream get onSelectNoneClick => _selectNoneButton.onClick;
Stream<String> get onMenuChange =>
- _menu.onChange.map((item) => item == noBaseline ? null : item);
+ _menu.onChange.map((item) => item == noBaseline ? null : item);
Stream<SelectEvent<pb.Request>> get onSelectionChange =>
_selectionChanges.stream;
@@ -176,8 +176,8 @@
]);
}
- void render(Row row, pb.Report r,
- EventSink<SelectEvent<pb.Request>> rowSelected) {
+ void render(
+ Row row, pb.Report r, EventSink<SelectEvent<pb.Request>> rowSelected) {
var b = row.benchmark;
var response = row.findResponse(r);
_selected.render(row.selected, item: row.request, sink: rowSelected);
@@ -235,7 +235,7 @@
/// A menu of selectable text items.
class _Menu {
final SelectElement elt;
- final _changes = new StreamController.broadcast();
+ final _changes = new StreamController<String>.broadcast();
final _options = new List<_MenuOption>();
_Menu(this.elt) {
diff --git a/bin/protoc_plugin_bazel.dart b/bin/protoc_plugin_bazel.dart
index 4ab1b79..86d9987 100755
--- a/bin/protoc_plugin_bazel.dart
+++ b/bin/protoc_plugin_bazel.dart
@@ -8,7 +8,7 @@
import 'package:protoc_plugin/protoc.dart';
void main() {
- var packages = {};
+ var packages = <String, BazelPackage>{};
new CodeGenerator(stdin, stdout).generate(
optionParsers: {bazelOptionId: new BazelOptionParser(packages)},
config: new BazelOutputConfiguration(packages));
diff --git a/lib/const_generator.dart b/lib/const_generator.dart
index a083307..11b9ced 100644
--- a/lib/const_generator.dart
+++ b/lib/const_generator.dart
@@ -92,10 +92,10 @@
}
}
-void _writeMapItems(IndentingWriter out, Map<String, dynamic> val,
+void _writeMapItems(IndentingWriter out, Map<dynamic, dynamic> val,
{bool vertical: false}) {
bool first = true;
- for (String key in val.keys) {
+ for (var key in val.keys) {
if (!first && !vertical) out.print(", ");
_writeString(out, key);
out.print(": ");
diff --git a/lib/enum_generator.dart b/lib/enum_generator.dart
index 2734fff..acf2aa6 100644
--- a/lib/enum_generator.dart
+++ b/lib/enum_generator.dart
@@ -19,16 +19,17 @@
<EnumValueDescriptorProto>[];
final List<EnumAlias> _aliases = <EnumAlias>[];
- EnumGenerator(
- EnumDescriptorProto descriptor,
- ProtobufContainer parent)
- : _parent = parent,
- classname = (parent == null || parent is FileGenerator) ?
- descriptor.name : '${parent.classname}_${descriptor.name}',
- fqname = (parent == null || parent.fqname == null) ? descriptor.name :
- (parent.fqname == '.' ?
- '.${descriptor.name}' : '${parent.fqname}.${descriptor.name}'),
- _descriptor = descriptor {
+ EnumGenerator(EnumDescriptorProto descriptor, ProtobufContainer parent)
+ : _parent = parent,
+ classname = (parent == null || parent is FileGenerator)
+ ? descriptor.name
+ : '${parent.classname}_${descriptor.name}',
+ fqname = (parent == null || parent.fqname == null)
+ ? descriptor.name
+ : (parent.fqname == '.'
+ ? '.${descriptor.name}'
+ : '${parent.fqname}.${descriptor.name}'),
+ _descriptor = descriptor {
for (EnumValueDescriptorProto value in descriptor.value) {
EnumValueDescriptorProto canonicalValue =
descriptor.value.firstWhere((v) => v.number == value.number);
@@ -63,9 +64,8 @@
// -----------------------------------------------------------------
// Define enum types.
for (EnumValueDescriptorProto val in _canonicalValues) {
- out.println(
- 'static const ${classname} ${val.name} = '
- "const ${classname}._(${val.number}, '${val.name}');");
+ out.println('static const ${classname} ${val.name} = '
+ "const ${classname}._(${val.number}, '${val.name}');");
}
if (!_aliases.isEmpty) {
out.println();
@@ -76,22 +76,21 @@
}
out.println();
- out.println(
- 'static const List<${classname}> values ='
- ' const <${classname}> [');
+ out.println('static const List<${classname}> values ='
+ ' const <${classname}> [');
for (EnumValueDescriptorProto val in _canonicalValues) {
out.println(' ${val.name},');
}
out.println('];');
out.println();
- out.println('static final Map<int, ${classname}> _byValue ='
+ out.println('static final Map<int, dynamic> _byValue ='
' ProtobufEnum.initByValue(values);');
out.println('static ${classname} valueOf(int value) =>'
- ' _byValue[value];');
+ ' _byValue[value] as ${classname};');
out.addBlock('static void $checkItem($classname v) {', '}', () {
out.println('if (v is !$classname)'
- " checkItemFailed(v, '$classname');");
+ " checkItemFailed(v, '$classname');");
});
out.println();
diff --git a/lib/extension_generator.dart b/lib/extension_generator.dart
index ae4f505..441d38b 100644
--- a/lib/extension_generator.dart
+++ b/lib/extension_generator.dart
@@ -55,18 +55,17 @@
if (_field == null) throw new StateError("resolve not called");
String name = _field.dartFieldName;
+ var type = _field.baseType;
+ var dartType = type.getDartType(package);
if (_field.isRepeated) {
out.print('static final Extension $name = '
- 'new Extension.repeated(\'$_extendedClassName\', \'$name\', '
- '${_field.number}, ${_field.typeConstant}');
- var type = _field.baseType;
+ 'new Extension<$dartType>.repeated(\'$_extendedClassName\','
+ ' \'$name\', ${_field.number}, ${_field.typeConstant}');
if (type.isMessage || type.isGroup) {
- var dartClass = type.getDartType(package);
- out.println(', $dartClass.$checkItem, $dartClass.create);');
+ out.println(', $dartType.$checkItem, $dartType.create);');
} else if (type.isEnum) {
- var dartClass = type.getDartType(package);
- out.println(', $dartClass.$checkItem, null, $dartClass.valueOf);');
+ out.println(', $dartType.$checkItem, null, $dartType.valueOf);');
} else {
out.println(", getCheckFunction(${_field.typeConstant}));");
}
@@ -74,15 +73,13 @@
}
out.print('static final Extension $name = '
- 'new Extension(\'$_extendedClassName\', \'$name\', '
+ 'new Extension<$dartType>(\'$_extendedClassName\', \'$name\', '
'${_field.number}, ${_field.typeConstant}');
String initializer = _field.generateDefaultFunction(package);
- var type = _field.baseType;
if (type.isMessage || type.isGroup) {
- var dartClass = type.getDartType(package);
- out.println(', $initializer, $dartClass.create);');
+ out.println(', $initializer, $dartType.create);');
} else if (type.isEnum) {
var dartEnum = type.getDartType(package);
String valueOf = '(var v) => $dartEnum.valueOf(v)';
diff --git a/lib/file_generator.dart b/lib/file_generator.dart
index 9ea661c..3ea66a4 100644
--- a/lib/file_generator.dart
+++ b/lib/file_generator.dart
@@ -5,7 +5,6 @@
part of protoc;
class FileGenerator extends ProtobufContainer {
-
/// Returns the the mixin to use by default in this file,
/// or null for no mixin by default.
static PbMixin _getDefaultMixin(FileDescriptorProto desc) {
@@ -16,7 +15,7 @@
var name = desc.options.getExtension(Dart_options.defaultMixin);
PbMixin mixin = findMixin(name);
if (mixin == null) {
- throw("unknown mixin class: ${name}");
+ throw ("unknown mixin class: ${name}");
}
return mixin;
}
@@ -40,8 +39,8 @@
enumGenerators.add(new EnumGenerator(enumType, this));
}
for (DescriptorProto messageType in _fileDescriptor.messageType) {
- messageGenerators.add(
- new MessageGenerator(messageType, this, defaultMixin));
+ messageGenerators
+ .add(new MessageGenerator(messageType, this, defaultMixin));
}
for (FieldDescriptorProto extension in _fileDescriptor.extension) {
extensionGenerators.add(new ExtensionGenerator(extension, this));
@@ -109,8 +108,8 @@
Uri filePath = new Uri.file(_fileDescriptor.name);
return new CodeGeneratorResponse_File()
- ..name = config.outputPathFor(filePath).path
- ..content = out.toString();
+ ..name = config.outputPathFor(filePath).path
+ ..content = out.toString();
}
/// Generates the Dart code for this .proto file.
@@ -120,8 +119,8 @@
Uri filePath = new Uri.file(_fileDescriptor.name);
if (filePath.isAbsolute) {
- // protoc should never generate a file descriptor with an absolute path.
- throw("FAILURE: File with an absolute path is not supported");
+ // protoc should never generate a file descriptor with an absolute path.
+ throw "FAILURE: File with an absolute path is not supported";
}
generateHeader(out, filePath, config);
@@ -175,10 +174,8 @@
/// Prints header and imports.
void generateHeader(IndentingWriter out, Uri filePath,
[OutputConfiguration config = const DefaultOutputConfiguration()]) {
-
String libraryName = _generateLibraryName(filePath);
- out.println(
- '///\n'
+ out.println('///\n'
'// Generated code. Do not modify.\n'
'///\n'
'library $libraryName;\n');
@@ -207,7 +204,7 @@
Uri importPath = new Uri.file(filename);
if (importPath.isAbsolute) {
// protoc should never generate an import with an absolute path.
- throw("FAILURE: Import with absolute path is not supported");
+ throw "FAILURE: Import with absolute path is not supported";
}
// Create a path from the current file to the imported proto.
Uri resolvedImport = config.resolveImport(importPath, filePath);
@@ -253,15 +250,15 @@
m.addMixinsTo(mixins);
}
- var imports = {};
+ var imports = <String, List<String>>{};
for (var m in mixins) {
- var imp = m.importFrom;
- List<String> symbols = imports[imp];
- if (symbols == null) {
- symbols = [];
- imports[imp] = symbols;
- }
- symbols.add(m.name);
+ var imp = m.importFrom;
+ List<String> symbols = imports[imp];
+ if (symbols == null) {
+ symbols = [];
+ imports[imp] = symbols;
+ }
+ symbols.add(m.name);
}
for (var imp in imports.keys) {
diff --git a/lib/message_generator.dart b/lib/message_generator.dart
index 8d986e1..49ceb15 100644
--- a/lib/message_generator.dart
+++ b/lib/message_generator.dart
@@ -11,16 +11,49 @@
class MessageGenerator extends ProtobufContainer {
// List of Dart language reserved words in names which cannot be used in a
// subclass of GeneratedMessage.
- static final List<String> reservedWords =
- ['assert', 'break', 'case', 'catch', 'class', 'const', 'continue',
- 'default', 'do', 'else', 'enum', 'extends', 'false', 'final',
- 'finally', 'for', 'if', 'in', 'is', 'new', 'null', 'rethrow', 'return',
- 'super', 'switch', 'this', 'throw', 'true', 'try', 'var', 'void',
- 'while', 'with'];
+ static final List<String> reservedWords = [
+ 'assert',
+ 'break',
+ 'case',
+ 'catch',
+ 'class',
+ 'const',
+ 'continue',
+ 'default',
+ 'do',
+ 'else',
+ 'enum',
+ 'extends',
+ 'false',
+ 'final',
+ 'finally',
+ 'for',
+ 'if',
+ 'in',
+ 'is',
+ 'new',
+ 'null',
+ 'rethrow',
+ 'return',
+ 'super',
+ 'switch',
+ 'this',
+ 'throw',
+ 'true',
+ 'try',
+ 'var',
+ 'void',
+ 'while',
+ 'with'
+ ];
// List of names used in the generated class itself
- static final List<String> generatedNames =
- ['create', 'createRepeated', 'getDefault', checkItem];
+ static final List<String> generatedNames = [
+ 'create',
+ 'createRepeated',
+ 'getDefault',
+ checkItem
+ ];
// Returns the mixin for this message, or null if none.
static PbMixin _getMixin(DescriptorProto desc, PbMixin defaultValue) {
@@ -31,7 +64,7 @@
if (name.isEmpty) return null; // don't use a mixin (override any default)
var mixin = findMixin(name);
if (mixin == null) {
- throw("unknown mixin class: ${name}");
+ throw ("unknown mixin class: ${name}");
}
return mixin;
}
@@ -52,24 +85,25 @@
// Used during generation.
final Set<String> _methodNames = new Set<String>();
- MessageGenerator(
- DescriptorProto descriptor, ProtobufContainer parent, PbMixin defaultMixin)
+ MessageGenerator(DescriptorProto descriptor, ProtobufContainer parent,
+ PbMixin defaultMixin)
: _descriptor = descriptor,
_parent = parent,
- classname = (parent.classname == '') ?
- descriptor.name : '${parent.classname}_${descriptor.name}',
- fqname = (parent == null || parent.fqname == null) ? descriptor.name :
- (parent.fqname == '.' ?
- '.${descriptor.name}' : '${parent.fqname}.${descriptor.name}'),
+ classname = (parent.classname == '')
+ ? descriptor.name
+ : '${parent.classname}_${descriptor.name}',
+ fqname = (parent == null || parent.fqname == null)
+ ? descriptor.name
+ : (parent.fqname == '.'
+ ? '.${descriptor.name}'
+ : '${parent.fqname}.${descriptor.name}'),
mixin = _getMixin(descriptor, defaultMixin) {
-
for (EnumDescriptorProto e in _descriptor.enumType) {
_enumGenerators.add(new EnumGenerator(e, this));
}
for (DescriptorProto n in _descriptor.nestedType) {
- _messageGenerators.add(
- new MessageGenerator(n, this, defaultMixin));
+ _messageGenerators.add(new MessageGenerator(n, this, defaultMixin));
}
for (FieldDescriptorProto x in _descriptor.extension) {
@@ -112,7 +146,7 @@
// Registers message and enum types that can be used elsewhere.
void register(GenerationContext ctx) {
ctx.registerFieldType(fqname, this);
- for (var m in _messageGenerators) {
+ for (var m in _messageGenerators) {
m.register(ctx);
}
for (var e in _enumGenerators) {
@@ -126,10 +160,10 @@
var sorted = new List<FieldDescriptorProto>.from(_descriptor.field)
..sort((FieldDescriptorProto a, FieldDescriptorProto b) {
- if (a.number < b.number) return -1;
- if (a.number > b.number) return 1;
- throw "multiple fields defined for tag ${a.number} in $fqname";
- });
+ if (a.number < b.number) return -1;
+ if (a.number > b.number) return 1;
+ throw "multiple fields defined for tag ${a.number} in $fqname";
+ });
_fieldList = <ProtobufField>[];
for (FieldDescriptorProto field in sorted) {
@@ -204,9 +238,8 @@
mixinClause = ' with ${mixinNames.join(", ")}';
}
- out.addBlock('class ${classname} extends GeneratedMessage${mixinClause} {',
- '}', ()
- {
+ out.addBlock(
+ 'class ${classname} extends GeneratedMessage${mixinClause} {', '}', () {
out.addBlock(
'static final BuilderInfo _i = new BuilderInfo(\'${classname}\')',
';', () {
@@ -245,21 +278,22 @@
' new ${classname}();');
out.println('static PbList<${classname}> createRepeated() =>'
' new PbList<${classname}>();');
- out.addBlock('static ${classname} getDefault() {',
- '}', () {
- out.println('if (_defaultInstance == null) _defaultInstance = new _Readonly${classname}();');
+ out.addBlock('static ${classname} getDefault() {', '}', () {
+ out.println(
+ 'if (_defaultInstance == null) _defaultInstance = new _Readonly${classname}();');
out.println('return _defaultInstance;');
});
out.println('static ${classname} _defaultInstance;');
out.addBlock('static void $checkItem($classname v) {', '}', () {
- out.println('if (v is !$classname)'
- " checkItemFailed(v, '$classname');");
+ out.println('if (v is !$classname)'
+ " checkItemFailed(v, '$classname');");
});
generateFieldsAccessorsMutators(out);
});
out.println();
- out.println('class _Readonly${classname} extends ${classname} with ReadonlyMessageMixin {}');
+ out.println(
+ 'class _Readonly${classname} extends ${classname} with ReadonlyMessageMixin {}');
out.println();
}
@@ -315,8 +349,8 @@
String clearIdentifier = field.clearMethodName;
if (!field.isRepeated) {
while (_methodNames.contains(identifier) ||
- _methodNames.contains(hasIdentifier) ||
- _methodNames.contains(clearIdentifier)) {
+ _methodNames.contains(hasIdentifier) ||
+ _methodNames.contains(clearIdentifier)) {
identifier += '_' + field.number.toString();
hasIdentifier += '_' + field.number.toString();
clearIdentifier += '_' + field.number.toString();
@@ -334,7 +368,8 @@
var fieldTypeString = field.getDartType(package);
var defaultExpr = field.getDefaultExpr();
out.println('${fieldTypeString} get ${identifier}'
- ' => \$_get(${field.index}, ${field.number}, $defaultExpr);');
+ ' => \$_get('
+ '${field.index}, ${field.number}, $defaultExpr);');
if (!field.isRepeated) {
var fastSetter = field.baseType.setter;
if (fastSetter != null) {
@@ -368,11 +403,9 @@
var name = getJsonConstant(fileGen);
var json = _descriptor.writeToJsonMap();
var nestedTypeNames =
- _messageGenerators.map((m) => m.getJsonConstant(fileGen))
- .toList();
+ _messageGenerators.map((m) => m.getJsonConstant(fileGen)).toList();
var nestedEnumNames =
- _enumGenerators.map((e) => e.getJsonConstant(fileGen))
- .toList();
+ _enumGenerators.map((e) => e.getJsonConstant(fileGen)).toList();
out.addBlock("const $name = const {", "};", () {
for (var key in json.keys) {
diff --git a/lib/options.dart b/lib/options.dart
index 3e202bd..0679c02 100644
--- a/lib/options.dart
+++ b/lib/options.dart
@@ -9,9 +9,8 @@
/// key-value pair ("name=value"). For each option "name", it looks up whether a
/// [SingleOptionParser] exists in [parsers] and delegates the actual parsing of
/// the option to it. Returns `true` if no errors were reported.
-bool genericOptionsParser(
- CodeGeneratorRequest request, CodeGeneratorResponse response,
- Map<String, SingleOptionParser> parsers) {
+bool genericOptionsParser(CodeGeneratorRequest request,
+ CodeGeneratorResponse response, Map<String, SingleOptionParser> parsers) {
var parameter = request.parameter != null ? request.parameter : '';
var options = parameter.trim().split(',');
var errors = [];
@@ -19,9 +18,9 @@
for (var option in options) {
option = option.trim();
if (option.isEmpty) continue;
- var reportError = (details) {
+ void reportError(String details) {
errors.add('Error found trying to parse the option: $option.\n$details');
- };
+ }
var nameValue = option.split('=');
if (nameValue.length != 1 && nameValue.length != 2) {
@@ -58,7 +57,6 @@
/// [genericOptionsParser] delegate to instances of this class to
/// parse the value of a specific option.
abstract class SingleOptionParser {
-
/// Parse the [name]=[value] value pair and report any errors to [onError]. If
/// the option is a flag, [value] will be null. Note, [name] is commonly
/// unused. It is provided because [SingleOptionParser] can be registered for
@@ -73,10 +71,12 @@
CodeGeneratorRequest request, CodeGeneratorResponse response,
[Map<String, SingleOptionParser> parsers]) {
var fieldNameOptionParser = new FieldNameOptionParser();
- var map = {};
- if (parsers != null) parsers.forEach((k, v) { map[k] = v; });
- map['field_name'] = fieldNameOptionParser;
- if (genericOptionsParser(request, response, map)) {
+
+ var newParsers = <String, SingleOptionParser>{};
+ if (parsers != null) newParsers.addAll(parsers);
+ newParsers['field_name'] = fieldNameOptionParser;
+
+ if (genericOptionsParser(request, response, newParsers)) {
return new GenerationOptions(fieldNameOptionParser.mappings);
}
return null;
diff --git a/lib/protobuf_field.dart b/lib/protobuf_field.dart
index 5a5c167..78c2b50 100644
--- a/lib/protobuf_field.dart
+++ b/lib/protobuf_field.dart
@@ -112,23 +112,24 @@
if (isRepeated) {
if (baseType.isMessage || baseType.isGroup) {
- return '..pp($number, $quotedName, $typeConstant,'
+ return '..pp/*<$type>*/($number, $quotedName, $typeConstant,'
' $type.$checkItem, $type.create)';
} else if (baseType.isEnum) {
- return '..pp($number, $quotedName, $typeConstant,'
+ return '..pp/*<$type>*/($number, $quotedName, $typeConstant,'
' $type.$checkItem, null, $type.valueOf)';
} else {
- return '..p($number, $quotedName, $typeConstant)';
+ return '..p/*<$type>*/($number, $quotedName, $typeConstant)';
}
}
String makeDefault = generateDefaultFunction(package);
if (baseType.isEnum) {
String valueOf = '$type.valueOf';
- return '..e($number, $quotedName, $typeConstant, $makeDefault, $valueOf)';
+ return '..e/*<$type>*/('
+ '$number, $quotedName, $typeConstant, $makeDefault, $valueOf)';
}
- String prefix = '..a($number, $quotedName, $typeConstant';
+ String prefix = '..a/*<$type>*/($number, $quotedName, $typeConstant';
if (makeDefault == null) return prefix + ')';
if (baseType.isMessage || baseType.isGroup) {
@@ -145,18 +146,18 @@
String getDefaultExpr() {
if (isRepeated) return "null";
switch (_field.type) {
- case FieldDescriptorProto_Type.TYPE_BOOL:
- return _getDefaultAsBoolExpr("false");
- case FieldDescriptorProto_Type.TYPE_INT32:
- case FieldDescriptorProto_Type.TYPE_UINT32:
- case FieldDescriptorProto_Type.TYPE_SINT32:
- case FieldDescriptorProto_Type.TYPE_FIXED32:
- case FieldDescriptorProto_Type.TYPE_SFIXED32:
- return _getDefaultAsInt32Expr("0");
- case FieldDescriptorProto_Type.TYPE_STRING:
- return _getDefaultAsStringExpr("''");
- default:
- return "null";
+ case FieldDescriptorProto_Type.TYPE_BOOL:
+ return _getDefaultAsBoolExpr("false");
+ case FieldDescriptorProto_Type.TYPE_INT32:
+ case FieldDescriptorProto_Type.TYPE_UINT32:
+ case FieldDescriptorProto_Type.TYPE_SINT32:
+ case FieldDescriptorProto_Type.TYPE_FIXED32:
+ case FieldDescriptorProto_Type.TYPE_SFIXED32:
+ return _getDefaultAsInt32Expr("0");
+ case FieldDescriptorProto_Type.TYPE_STRING:
+ return _getDefaultAsStringExpr("''");
+ default:
+ return "null";
}
}
diff --git a/lib/src/descriptor.pb.dart b/lib/src/descriptor.pb.dart
index 946e2f9..228d477 100644
--- a/lib/src/descriptor.pb.dart
+++ b/lib/src/descriptor.pb.dart
@@ -8,7 +8,7 @@
class FileDescriptorSet extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('FileDescriptorSet')
- ..pp(1, 'file', PbFieldType.PM, FileDescriptorProto.$checkItem, FileDescriptorProto.create)
+ ..pp/*<FileDescriptorProto>*/(1, 'file', PbFieldType.PM, FileDescriptorProto.$checkItem, FileDescriptorProto.create)
;
FileDescriptorSet() : super();
@@ -27,24 +27,24 @@
if (v is !FileDescriptorSet) checkItemFailed(v, 'FileDescriptorSet');
}
- List<FileDescriptorProto> get file => getField(1);
+ List<FileDescriptorProto> get file => $_get(0, 1, null);
}
class _ReadonlyFileDescriptorSet extends FileDescriptorSet with ReadonlyMessageMixin {}
class FileDescriptorProto extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('FileDescriptorProto')
- ..a(1, 'name', PbFieldType.OS)
- ..a(2, 'package', PbFieldType.OS)
- ..p(3, 'dependency', PbFieldType.PS)
- ..p(10, 'publicDependency', PbFieldType.P3)
- ..p(11, 'weakDependency', PbFieldType.P3)
- ..pp(4, 'messageType', PbFieldType.PM, DescriptorProto.$checkItem, DescriptorProto.create)
- ..pp(5, 'enumType', PbFieldType.PM, EnumDescriptorProto.$checkItem, EnumDescriptorProto.create)
- ..pp(6, 'service', PbFieldType.PM, ServiceDescriptorProto.$checkItem, ServiceDescriptorProto.create)
- ..pp(7, 'extension', PbFieldType.PM, FieldDescriptorProto.$checkItem, FieldDescriptorProto.create)
- ..a(8, 'options', PbFieldType.OM, FileOptions.getDefault, FileOptions.create)
- ..a(9, 'sourceCodeInfo', PbFieldType.OM, SourceCodeInfo.getDefault, SourceCodeInfo.create)
+ ..a/*<String>*/(1, 'name', PbFieldType.OS)
+ ..a/*<String>*/(2, 'package', PbFieldType.OS)
+ ..p/*<String>*/(3, 'dependency', PbFieldType.PS)
+ ..pp/*<DescriptorProto>*/(4, 'messageType', PbFieldType.PM, DescriptorProto.$checkItem, DescriptorProto.create)
+ ..pp/*<EnumDescriptorProto>*/(5, 'enumType', PbFieldType.PM, EnumDescriptorProto.$checkItem, EnumDescriptorProto.create)
+ ..pp/*<ServiceDescriptorProto>*/(6, 'service', PbFieldType.PM, ServiceDescriptorProto.$checkItem, ServiceDescriptorProto.create)
+ ..pp/*<FieldDescriptorProto>*/(7, 'extension', PbFieldType.PM, FieldDescriptorProto.$checkItem, FieldDescriptorProto.create)
+ ..a/*<FileOptions>*/(8, 'options', PbFieldType.OM, FileOptions.getDefault, FileOptions.create)
+ ..a/*<SourceCodeInfo>*/(9, 'sourceCodeInfo', PbFieldType.OM, SourceCodeInfo.getDefault, SourceCodeInfo.create)
+ ..p/*<int>*/(10, 'publicDependency', PbFieldType.P3)
+ ..p/*<int>*/(11, 'weakDependency', PbFieldType.P3)
;
FileDescriptorProto() : super();
@@ -63,47 +63,47 @@
if (v is !FileDescriptorProto) checkItemFailed(v, 'FileDescriptorProto');
}
- String get name => getField(1);
- void set name(String v) { setField(1, v); }
- bool hasName() => hasField(1);
+ String get name => $_get(0, 1, '');
+ void set name(String v) { $_setString(0, 1, v); }
+ bool hasName() => $_has(0, 1);
void clearName() => clearField(1);
- String get package => getField(2);
- void set package(String v) { setField(2, v); }
- bool hasPackage() => hasField(2);
+ String get package => $_get(1, 2, '');
+ void set package(String v) { $_setString(1, 2, v); }
+ bool hasPackage() => $_has(1, 2);
void clearPackage() => clearField(2);
- List<String> get dependency => getField(3);
+ List<String> get dependency => $_get(2, 3, null);
- List<int> get publicDependency => getField(10);
+ List<DescriptorProto> get messageType => $_get(3, 4, null);
- List<int> get weakDependency => getField(11);
+ List<EnumDescriptorProto> get enumType => $_get(4, 5, null);
- List<DescriptorProto> get messageType => getField(4);
+ List<ServiceDescriptorProto> get service => $_get(5, 6, null);
- List<EnumDescriptorProto> get enumType => getField(5);
+ List<FieldDescriptorProto> get extension => $_get(6, 7, null);
- List<ServiceDescriptorProto> get service => getField(6);
-
- List<FieldDescriptorProto> get extension => getField(7);
-
- FileOptions get options => getField(8);
+ FileOptions get options => $_get(7, 8, null);
void set options(FileOptions v) { setField(8, v); }
- bool hasOptions() => hasField(8);
+ bool hasOptions() => $_has(7, 8);
void clearOptions() => clearField(8);
- SourceCodeInfo get sourceCodeInfo => getField(9);
+ SourceCodeInfo get sourceCodeInfo => $_get(8, 9, null);
void set sourceCodeInfo(SourceCodeInfo v) { setField(9, v); }
- bool hasSourceCodeInfo() => hasField(9);
+ bool hasSourceCodeInfo() => $_has(8, 9);
void clearSourceCodeInfo() => clearField(9);
+
+ List<int> get publicDependency => $_get(9, 10, null);
+
+ List<int> get weakDependency => $_get(10, 11, null);
}
class _ReadonlyFileDescriptorProto extends FileDescriptorProto with ReadonlyMessageMixin {}
class DescriptorProto_ExtensionRange extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('DescriptorProto_ExtensionRange')
- ..a(1, 'start', PbFieldType.O3)
- ..a(2, 'end', PbFieldType.O3)
+ ..a/*<int>*/(1, 'start', PbFieldType.O3)
+ ..a/*<int>*/(2, 'end', PbFieldType.O3)
..hasRequiredFields = false
;
@@ -123,14 +123,14 @@
if (v is !DescriptorProto_ExtensionRange) checkItemFailed(v, 'DescriptorProto_ExtensionRange');
}
- int get start => getField(1);
- void set start(int v) { setField(1, v); }
- bool hasStart() => hasField(1);
+ int get start => $_get(0, 1, 0);
+ void set start(int v) { $_setUnsignedInt32(0, 1, v); }
+ bool hasStart() => $_has(0, 1);
void clearStart() => clearField(1);
- int get end => getField(2);
- void set end(int v) { setField(2, v); }
- bool hasEnd() => hasField(2);
+ int get end => $_get(1, 2, 0);
+ void set end(int v) { $_setUnsignedInt32(1, 2, v); }
+ bool hasEnd() => $_has(1, 2);
void clearEnd() => clearField(2);
}
@@ -138,13 +138,13 @@
class DescriptorProto extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('DescriptorProto')
- ..a(1, 'name', PbFieldType.OS)
- ..pp(2, 'field', PbFieldType.PM, FieldDescriptorProto.$checkItem, FieldDescriptorProto.create)
- ..pp(6, 'extension', PbFieldType.PM, FieldDescriptorProto.$checkItem, FieldDescriptorProto.create)
- ..pp(3, 'nestedType', PbFieldType.PM, DescriptorProto.$checkItem, DescriptorProto.create)
- ..pp(4, 'enumType', PbFieldType.PM, EnumDescriptorProto.$checkItem, EnumDescriptorProto.create)
- ..pp(5, 'extensionRange', PbFieldType.PM, DescriptorProto_ExtensionRange.$checkItem, DescriptorProto_ExtensionRange.create)
- ..a(7, 'options', PbFieldType.OM, MessageOptions.getDefault, MessageOptions.create)
+ ..a/*<String>*/(1, 'name', PbFieldType.OS)
+ ..pp/*<FieldDescriptorProto>*/(2, 'field', PbFieldType.PM, FieldDescriptorProto.$checkItem, FieldDescriptorProto.create)
+ ..pp/*<DescriptorProto>*/(3, 'nestedType', PbFieldType.PM, DescriptorProto.$checkItem, DescriptorProto.create)
+ ..pp/*<EnumDescriptorProto>*/(4, 'enumType', PbFieldType.PM, EnumDescriptorProto.$checkItem, EnumDescriptorProto.create)
+ ..pp/*<DescriptorProto_ExtensionRange>*/(5, 'extensionRange', PbFieldType.PM, DescriptorProto_ExtensionRange.$checkItem, DescriptorProto_ExtensionRange.create)
+ ..pp/*<FieldDescriptorProto>*/(6, 'extension', PbFieldType.PM, FieldDescriptorProto.$checkItem, FieldDescriptorProto.create)
+ ..a/*<MessageOptions>*/(7, 'options', PbFieldType.OM, MessageOptions.getDefault, MessageOptions.create)
;
DescriptorProto() : super();
@@ -163,24 +163,24 @@
if (v is !DescriptorProto) checkItemFailed(v, 'DescriptorProto');
}
- String get name => getField(1);
- void set name(String v) { setField(1, v); }
- bool hasName() => hasField(1);
+ String get name => $_get(0, 1, '');
+ void set name(String v) { $_setString(0, 1, v); }
+ bool hasName() => $_has(0, 1);
void clearName() => clearField(1);
- List<FieldDescriptorProto> get field => getField(2);
+ List<FieldDescriptorProto> get field => $_get(1, 2, null);
- List<FieldDescriptorProto> get extension => getField(6);
+ List<DescriptorProto> get nestedType => $_get(2, 3, null);
- List<DescriptorProto> get nestedType => getField(3);
+ List<EnumDescriptorProto> get enumType => $_get(3, 4, null);
- List<EnumDescriptorProto> get enumType => getField(4);
+ List<DescriptorProto_ExtensionRange> get extensionRange => $_get(4, 5, null);
- List<DescriptorProto_ExtensionRange> get extensionRange => getField(5);
+ List<FieldDescriptorProto> get extension => $_get(5, 6, null);
- MessageOptions get options => getField(7);
+ MessageOptions get options => $_get(6, 7, null);
void set options(MessageOptions v) { setField(7, v); }
- bool hasOptions() => hasField(7);
+ bool hasOptions() => $_has(6, 7);
void clearOptions() => clearField(7);
}
@@ -227,8 +227,8 @@
TYPE_SINT64,
];
- static final Map<int, FieldDescriptorProto_Type> _byValue = ProtobufEnum.initByValue(values);
- static FieldDescriptorProto_Type valueOf(int value) => _byValue[value];
+ static final Map<int, dynamic> _byValue = ProtobufEnum.initByValue(values);
+ static FieldDescriptorProto_Type valueOf(int value) => _byValue[value] as FieldDescriptorProto_Type;
static void $checkItem(FieldDescriptorProto_Type v) {
if (v is !FieldDescriptorProto_Type) checkItemFailed(v, 'FieldDescriptorProto_Type');
}
@@ -247,8 +247,8 @@
LABEL_REPEATED,
];
- static final Map<int, FieldDescriptorProto_Label> _byValue = ProtobufEnum.initByValue(values);
- static FieldDescriptorProto_Label valueOf(int value) => _byValue[value];
+ static final Map<int, dynamic> _byValue = ProtobufEnum.initByValue(values);
+ static FieldDescriptorProto_Label valueOf(int value) => _byValue[value] as FieldDescriptorProto_Label;
static void $checkItem(FieldDescriptorProto_Label v) {
if (v is !FieldDescriptorProto_Label) checkItemFailed(v, 'FieldDescriptorProto_Label');
}
@@ -258,14 +258,14 @@
class FieldDescriptorProto extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('FieldDescriptorProto')
- ..a(1, 'name', PbFieldType.OS)
- ..a(3, 'number', PbFieldType.O3)
- ..e(4, 'label', PbFieldType.OE, FieldDescriptorProto_Label.LABEL_OPTIONAL, FieldDescriptorProto_Label.valueOf)
- ..e(5, 'type', PbFieldType.OE, FieldDescriptorProto_Type.TYPE_DOUBLE, FieldDescriptorProto_Type.valueOf)
- ..a(6, 'typeName', PbFieldType.OS)
- ..a(2, 'extendee', PbFieldType.OS)
- ..a(7, 'defaultValue', PbFieldType.OS)
- ..a(8, 'options', PbFieldType.OM, FieldOptions.getDefault, FieldOptions.create)
+ ..a/*<String>*/(1, 'name', PbFieldType.OS)
+ ..a/*<String>*/(2, 'extendee', PbFieldType.OS)
+ ..a/*<int>*/(3, 'number', PbFieldType.O3)
+ ..e/*<FieldDescriptorProto_Label>*/(4, 'label', PbFieldType.OE, FieldDescriptorProto_Label.LABEL_OPTIONAL, FieldDescriptorProto_Label.valueOf)
+ ..e/*<FieldDescriptorProto_Type>*/(5, 'type', PbFieldType.OE, FieldDescriptorProto_Type.TYPE_DOUBLE, FieldDescriptorProto_Type.valueOf)
+ ..a/*<String>*/(6, 'typeName', PbFieldType.OS)
+ ..a/*<String>*/(7, 'defaultValue', PbFieldType.OS)
+ ..a/*<FieldOptions>*/(8, 'options', PbFieldType.OM, FieldOptions.getDefault, FieldOptions.create)
;
FieldDescriptorProto() : super();
@@ -284,44 +284,44 @@
if (v is !FieldDescriptorProto) checkItemFailed(v, 'FieldDescriptorProto');
}
- String get name => getField(1);
- void set name(String v) { setField(1, v); }
- bool hasName() => hasField(1);
+ String get name => $_get(0, 1, '');
+ void set name(String v) { $_setString(0, 1, v); }
+ bool hasName() => $_has(0, 1);
void clearName() => clearField(1);
- int get number => getField(3);
- void set number(int v) { setField(3, v); }
- bool hasNumber() => hasField(3);
- void clearNumber() => clearField(3);
-
- FieldDescriptorProto_Label get label => getField(4);
- void set label(FieldDescriptorProto_Label v) { setField(4, v); }
- bool hasLabel() => hasField(4);
- void clearLabel() => clearField(4);
-
- FieldDescriptorProto_Type get type => getField(5);
- void set type(FieldDescriptorProto_Type v) { setField(5, v); }
- bool hasType() => hasField(5);
- void clearType() => clearField(5);
-
- String get typeName => getField(6);
- void set typeName(String v) { setField(6, v); }
- bool hasTypeName() => hasField(6);
- void clearTypeName() => clearField(6);
-
- String get extendee => getField(2);
- void set extendee(String v) { setField(2, v); }
- bool hasExtendee() => hasField(2);
+ String get extendee => $_get(1, 2, '');
+ void set extendee(String v) { $_setString(1, 2, v); }
+ bool hasExtendee() => $_has(1, 2);
void clearExtendee() => clearField(2);
- String get defaultValue => getField(7);
- void set defaultValue(String v) { setField(7, v); }
- bool hasDefaultValue() => hasField(7);
+ int get number => $_get(2, 3, 0);
+ void set number(int v) { $_setUnsignedInt32(2, 3, v); }
+ bool hasNumber() => $_has(2, 3);
+ void clearNumber() => clearField(3);
+
+ FieldDescriptorProto_Label get label => $_get(3, 4, null);
+ void set label(FieldDescriptorProto_Label v) { setField(4, v); }
+ bool hasLabel() => $_has(3, 4);
+ void clearLabel() => clearField(4);
+
+ FieldDescriptorProto_Type get type => $_get(4, 5, null);
+ void set type(FieldDescriptorProto_Type v) { setField(5, v); }
+ bool hasType() => $_has(4, 5);
+ void clearType() => clearField(5);
+
+ String get typeName => $_get(5, 6, '');
+ void set typeName(String v) { $_setString(5, 6, v); }
+ bool hasTypeName() => $_has(5, 6);
+ void clearTypeName() => clearField(6);
+
+ String get defaultValue => $_get(6, 7, '');
+ void set defaultValue(String v) { $_setString(6, 7, v); }
+ bool hasDefaultValue() => $_has(6, 7);
void clearDefaultValue() => clearField(7);
- FieldOptions get options => getField(8);
+ FieldOptions get options => $_get(7, 8, null);
void set options(FieldOptions v) { setField(8, v); }
- bool hasOptions() => hasField(8);
+ bool hasOptions() => $_has(7, 8);
void clearOptions() => clearField(8);
}
@@ -329,9 +329,9 @@
class EnumDescriptorProto extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('EnumDescriptorProto')
- ..a(1, 'name', PbFieldType.OS)
- ..pp(2, 'value', PbFieldType.PM, EnumValueDescriptorProto.$checkItem, EnumValueDescriptorProto.create)
- ..a(3, 'options', PbFieldType.OM, EnumOptions.getDefault, EnumOptions.create)
+ ..a/*<String>*/(1, 'name', PbFieldType.OS)
+ ..pp/*<EnumValueDescriptorProto>*/(2, 'value', PbFieldType.PM, EnumValueDescriptorProto.$checkItem, EnumValueDescriptorProto.create)
+ ..a/*<EnumOptions>*/(3, 'options', PbFieldType.OM, EnumOptions.getDefault, EnumOptions.create)
;
EnumDescriptorProto() : super();
@@ -350,16 +350,16 @@
if (v is !EnumDescriptorProto) checkItemFailed(v, 'EnumDescriptorProto');
}
- String get name => getField(1);
- void set name(String v) { setField(1, v); }
- bool hasName() => hasField(1);
+ String get name => $_get(0, 1, '');
+ void set name(String v) { $_setString(0, 1, v); }
+ bool hasName() => $_has(0, 1);
void clearName() => clearField(1);
- List<EnumValueDescriptorProto> get value => getField(2);
+ List<EnumValueDescriptorProto> get value => $_get(1, 2, null);
- EnumOptions get options => getField(3);
+ EnumOptions get options => $_get(2, 3, null);
void set options(EnumOptions v) { setField(3, v); }
- bool hasOptions() => hasField(3);
+ bool hasOptions() => $_has(2, 3);
void clearOptions() => clearField(3);
}
@@ -367,9 +367,9 @@
class EnumValueDescriptorProto extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('EnumValueDescriptorProto')
- ..a(1, 'name', PbFieldType.OS)
- ..a(2, 'number', PbFieldType.O3)
- ..a(3, 'options', PbFieldType.OM, EnumValueOptions.getDefault, EnumValueOptions.create)
+ ..a/*<String>*/(1, 'name', PbFieldType.OS)
+ ..a/*<int>*/(2, 'number', PbFieldType.O3)
+ ..a/*<EnumValueOptions>*/(3, 'options', PbFieldType.OM, EnumValueOptions.getDefault, EnumValueOptions.create)
;
EnumValueDescriptorProto() : super();
@@ -388,19 +388,19 @@
if (v is !EnumValueDescriptorProto) checkItemFailed(v, 'EnumValueDescriptorProto');
}
- String get name => getField(1);
- void set name(String v) { setField(1, v); }
- bool hasName() => hasField(1);
+ String get name => $_get(0, 1, '');
+ void set name(String v) { $_setString(0, 1, v); }
+ bool hasName() => $_has(0, 1);
void clearName() => clearField(1);
- int get number => getField(2);
- void set number(int v) { setField(2, v); }
- bool hasNumber() => hasField(2);
+ int get number => $_get(1, 2, 0);
+ void set number(int v) { $_setUnsignedInt32(1, 2, v); }
+ bool hasNumber() => $_has(1, 2);
void clearNumber() => clearField(2);
- EnumValueOptions get options => getField(3);
+ EnumValueOptions get options => $_get(2, 3, null);
void set options(EnumValueOptions v) { setField(3, v); }
- bool hasOptions() => hasField(3);
+ bool hasOptions() => $_has(2, 3);
void clearOptions() => clearField(3);
}
@@ -408,10 +408,10 @@
class ServiceDescriptorProto extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('ServiceDescriptorProto')
- ..a(1, 'name', PbFieldType.OS)
- ..pp(2, 'method', PbFieldType.PM, MethodDescriptorProto.$checkItem, MethodDescriptorProto.create)
- ..pp(4, 'stream', PbFieldType.PM, StreamDescriptorProto.$checkItem, StreamDescriptorProto.create)
- ..a(3, 'options', PbFieldType.OM, ServiceOptions.getDefault, ServiceOptions.create)
+ ..a/*<String>*/(1, 'name', PbFieldType.OS)
+ ..pp/*<MethodDescriptorProto>*/(2, 'method', PbFieldType.PM, MethodDescriptorProto.$checkItem, MethodDescriptorProto.create)
+ ..a/*<ServiceOptions>*/(3, 'options', PbFieldType.OM, ServiceOptions.getDefault, ServiceOptions.create)
+ ..pp/*<StreamDescriptorProto>*/(4, 'stream', PbFieldType.PM, StreamDescriptorProto.$checkItem, StreamDescriptorProto.create)
;
ServiceDescriptorProto() : super();
@@ -430,29 +430,29 @@
if (v is !ServiceDescriptorProto) checkItemFailed(v, 'ServiceDescriptorProto');
}
- String get name => getField(1);
- void set name(String v) { setField(1, v); }
- bool hasName() => hasField(1);
+ String get name => $_get(0, 1, '');
+ void set name(String v) { $_setString(0, 1, v); }
+ bool hasName() => $_has(0, 1);
void clearName() => clearField(1);
- List<MethodDescriptorProto> get method => getField(2);
+ List<MethodDescriptorProto> get method => $_get(1, 2, null);
- List<StreamDescriptorProto> get stream => getField(4);
-
- ServiceOptions get options => getField(3);
+ ServiceOptions get options => $_get(2, 3, null);
void set options(ServiceOptions v) { setField(3, v); }
- bool hasOptions() => hasField(3);
+ bool hasOptions() => $_has(2, 3);
void clearOptions() => clearField(3);
+
+ List<StreamDescriptorProto> get stream => $_get(3, 4, null);
}
class _ReadonlyServiceDescriptorProto extends ServiceDescriptorProto with ReadonlyMessageMixin {}
class MethodDescriptorProto extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('MethodDescriptorProto')
- ..a(1, 'name', PbFieldType.OS)
- ..a(2, 'inputType', PbFieldType.OS)
- ..a(3, 'outputType', PbFieldType.OS)
- ..a(4, 'options', PbFieldType.OM, MethodOptions.getDefault, MethodOptions.create)
+ ..a/*<String>*/(1, 'name', PbFieldType.OS)
+ ..a/*<String>*/(2, 'inputType', PbFieldType.OS)
+ ..a/*<String>*/(3, 'outputType', PbFieldType.OS)
+ ..a/*<MethodOptions>*/(4, 'options', PbFieldType.OM, MethodOptions.getDefault, MethodOptions.create)
;
MethodDescriptorProto() : super();
@@ -471,24 +471,24 @@
if (v is !MethodDescriptorProto) checkItemFailed(v, 'MethodDescriptorProto');
}
- String get name => getField(1);
- void set name(String v) { setField(1, v); }
- bool hasName() => hasField(1);
+ String get name => $_get(0, 1, '');
+ void set name(String v) { $_setString(0, 1, v); }
+ bool hasName() => $_has(0, 1);
void clearName() => clearField(1);
- String get inputType => getField(2);
- void set inputType(String v) { setField(2, v); }
- bool hasInputType() => hasField(2);
+ String get inputType => $_get(1, 2, '');
+ void set inputType(String v) { $_setString(1, 2, v); }
+ bool hasInputType() => $_has(1, 2);
void clearInputType() => clearField(2);
- String get outputType => getField(3);
- void set outputType(String v) { setField(3, v); }
- bool hasOutputType() => hasField(3);
+ String get outputType => $_get(2, 3, '');
+ void set outputType(String v) { $_setString(2, 3, v); }
+ bool hasOutputType() => $_has(2, 3);
void clearOutputType() => clearField(3);
- MethodOptions get options => getField(4);
+ MethodOptions get options => $_get(3, 4, null);
void set options(MethodOptions v) { setField(4, v); }
- bool hasOptions() => hasField(4);
+ bool hasOptions() => $_has(3, 4);
void clearOptions() => clearField(4);
}
@@ -496,10 +496,10 @@
class StreamDescriptorProto extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('StreamDescriptorProto')
- ..a(1, 'name', PbFieldType.OS)
- ..a(2, 'clientMessageType', PbFieldType.OS)
- ..a(3, 'serverMessageType', PbFieldType.OS)
- ..a(4, 'options', PbFieldType.OM, StreamOptions.getDefault, StreamOptions.create)
+ ..a/*<String>*/(1, 'name', PbFieldType.OS)
+ ..a/*<String>*/(2, 'clientMessageType', PbFieldType.OS)
+ ..a/*<String>*/(3, 'serverMessageType', PbFieldType.OS)
+ ..a/*<StreamOptions>*/(4, 'options', PbFieldType.OM, StreamOptions.getDefault, StreamOptions.create)
;
StreamDescriptorProto() : super();
@@ -518,24 +518,24 @@
if (v is !StreamDescriptorProto) checkItemFailed(v, 'StreamDescriptorProto');
}
- String get name => getField(1);
- void set name(String v) { setField(1, v); }
- bool hasName() => hasField(1);
+ String get name => $_get(0, 1, '');
+ void set name(String v) { $_setString(0, 1, v); }
+ bool hasName() => $_has(0, 1);
void clearName() => clearField(1);
- String get clientMessageType => getField(2);
- void set clientMessageType(String v) { setField(2, v); }
- bool hasClientMessageType() => hasField(2);
+ String get clientMessageType => $_get(1, 2, '');
+ void set clientMessageType(String v) { $_setString(1, 2, v); }
+ bool hasClientMessageType() => $_has(1, 2);
void clearClientMessageType() => clearField(2);
- String get serverMessageType => getField(3);
- void set serverMessageType(String v) { setField(3, v); }
- bool hasServerMessageType() => hasField(3);
+ String get serverMessageType => $_get(2, 3, '');
+ void set serverMessageType(String v) { $_setString(2, 3, v); }
+ bool hasServerMessageType() => $_has(2, 3);
void clearServerMessageType() => clearField(3);
- StreamOptions get options => getField(4);
+ StreamOptions get options => $_get(3, 4, null);
void set options(StreamOptions v) { setField(4, v); }
- bool hasOptions() => hasField(4);
+ bool hasOptions() => $_has(3, 4);
void clearOptions() => clearField(4);
}
@@ -552,8 +552,8 @@
LITE_RUNTIME,
];
- static final Map<int, FileOptions_OptimizeMode> _byValue = ProtobufEnum.initByValue(values);
- static FileOptions_OptimizeMode valueOf(int value) => _byValue[value];
+ static final Map<int, dynamic> _byValue = ProtobufEnum.initByValue(values);
+ static FileOptions_OptimizeMode valueOf(int value) => _byValue[value] as FileOptions_OptimizeMode;
static void $checkItem(FileOptions_OptimizeMode v) {
if (v is !FileOptions_OptimizeMode) checkItemFailed(v, 'FileOptions_OptimizeMode');
}
@@ -563,15 +563,15 @@
class FileOptions extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('FileOptions')
- ..a(1, 'javaPackage', PbFieldType.OS)
- ..a(8, 'javaOuterClassname', PbFieldType.OS)
- ..a(10, 'javaMultipleFiles', PbFieldType.OB)
- ..a(20, 'javaGenerateEqualsAndHash', PbFieldType.OB)
- ..e(9, 'optimizeFor', PbFieldType.OE, FileOptions_OptimizeMode.SPEED, FileOptions_OptimizeMode.valueOf)
- ..a(16, 'ccGenericServices', PbFieldType.OB)
- ..a(17, 'javaGenericServices', PbFieldType.OB)
- ..a(18, 'pyGenericServices', PbFieldType.OB)
- ..pp(999, 'uninterpretedOption', PbFieldType.PM, UninterpretedOption.$checkItem, UninterpretedOption.create)
+ ..a/*<String>*/(1, 'javaPackage', PbFieldType.OS)
+ ..a/*<String>*/(8, 'javaOuterClassname', PbFieldType.OS)
+ ..e/*<FileOptions_OptimizeMode>*/(9, 'optimizeFor', PbFieldType.OE, FileOptions_OptimizeMode.SPEED, FileOptions_OptimizeMode.valueOf)
+ ..a/*<bool>*/(10, 'javaMultipleFiles', PbFieldType.OB)
+ ..a/*<bool>*/(16, 'ccGenericServices', PbFieldType.OB)
+ ..a/*<bool>*/(17, 'javaGenericServices', PbFieldType.OB)
+ ..a/*<bool>*/(18, 'pyGenericServices', PbFieldType.OB)
+ ..a/*<bool>*/(20, 'javaGenerateEqualsAndHash', PbFieldType.OB)
+ ..pp/*<UninterpretedOption>*/(999, 'uninterpretedOption', PbFieldType.PM, UninterpretedOption.$checkItem, UninterpretedOption.create)
..hasExtensions = true
;
@@ -591,56 +591,56 @@
if (v is !FileOptions) checkItemFailed(v, 'FileOptions');
}
- String get javaPackage => getField(1);
- void set javaPackage(String v) { setField(1, v); }
- bool hasJavaPackage() => hasField(1);
+ String get javaPackage => $_get(0, 1, '');
+ void set javaPackage(String v) { $_setString(0, 1, v); }
+ bool hasJavaPackage() => $_has(0, 1);
void clearJavaPackage() => clearField(1);
- String get javaOuterClassname => getField(8);
- void set javaOuterClassname(String v) { setField(8, v); }
- bool hasJavaOuterClassname() => hasField(8);
+ String get javaOuterClassname => $_get(1, 8, '');
+ void set javaOuterClassname(String v) { $_setString(1, 8, v); }
+ bool hasJavaOuterClassname() => $_has(1, 8);
void clearJavaOuterClassname() => clearField(8);
- bool get javaMultipleFiles => getField(10);
- void set javaMultipleFiles(bool v) { setField(10, v); }
- bool hasJavaMultipleFiles() => hasField(10);
- void clearJavaMultipleFiles() => clearField(10);
-
- bool get javaGenerateEqualsAndHash => getField(20);
- void set javaGenerateEqualsAndHash(bool v) { setField(20, v); }
- bool hasJavaGenerateEqualsAndHash() => hasField(20);
- void clearJavaGenerateEqualsAndHash() => clearField(20);
-
- FileOptions_OptimizeMode get optimizeFor => getField(9);
+ FileOptions_OptimizeMode get optimizeFor => $_get(2, 9, null);
void set optimizeFor(FileOptions_OptimizeMode v) { setField(9, v); }
- bool hasOptimizeFor() => hasField(9);
+ bool hasOptimizeFor() => $_has(2, 9);
void clearOptimizeFor() => clearField(9);
- bool get ccGenericServices => getField(16);
- void set ccGenericServices(bool v) { setField(16, v); }
- bool hasCcGenericServices() => hasField(16);
+ bool get javaMultipleFiles => $_get(3, 10, false);
+ void set javaMultipleFiles(bool v) { $_setBool(3, 10, v); }
+ bool hasJavaMultipleFiles() => $_has(3, 10);
+ void clearJavaMultipleFiles() => clearField(10);
+
+ bool get ccGenericServices => $_get(4, 16, false);
+ void set ccGenericServices(bool v) { $_setBool(4, 16, v); }
+ bool hasCcGenericServices() => $_has(4, 16);
void clearCcGenericServices() => clearField(16);
- bool get javaGenericServices => getField(17);
- void set javaGenericServices(bool v) { setField(17, v); }
- bool hasJavaGenericServices() => hasField(17);
+ bool get javaGenericServices => $_get(5, 17, false);
+ void set javaGenericServices(bool v) { $_setBool(5, 17, v); }
+ bool hasJavaGenericServices() => $_has(5, 17);
void clearJavaGenericServices() => clearField(17);
- bool get pyGenericServices => getField(18);
- void set pyGenericServices(bool v) { setField(18, v); }
- bool hasPyGenericServices() => hasField(18);
+ bool get pyGenericServices => $_get(6, 18, false);
+ void set pyGenericServices(bool v) { $_setBool(6, 18, v); }
+ bool hasPyGenericServices() => $_has(6, 18);
void clearPyGenericServices() => clearField(18);
- List<UninterpretedOption> get uninterpretedOption => getField(999);
+ bool get javaGenerateEqualsAndHash => $_get(7, 20, false);
+ void set javaGenerateEqualsAndHash(bool v) { $_setBool(7, 20, v); }
+ bool hasJavaGenerateEqualsAndHash() => $_has(7, 20);
+ void clearJavaGenerateEqualsAndHash() => clearField(20);
+
+ List<UninterpretedOption> get uninterpretedOption => $_get(8, 999, null);
}
class _ReadonlyFileOptions extends FileOptions with ReadonlyMessageMixin {}
class MessageOptions extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('MessageOptions')
- ..a(1, 'messageSetWireFormat', PbFieldType.OB)
- ..a(2, 'noStandardDescriptorAccessor', PbFieldType.OB)
- ..pp(999, 'uninterpretedOption', PbFieldType.PM, UninterpretedOption.$checkItem, UninterpretedOption.create)
+ ..a/*<bool>*/(1, 'messageSetWireFormat', PbFieldType.OB)
+ ..a/*<bool>*/(2, 'noStandardDescriptorAccessor', PbFieldType.OB)
+ ..pp/*<UninterpretedOption>*/(999, 'uninterpretedOption', PbFieldType.PM, UninterpretedOption.$checkItem, UninterpretedOption.create)
..hasExtensions = true
;
@@ -660,17 +660,17 @@
if (v is !MessageOptions) checkItemFailed(v, 'MessageOptions');
}
- bool get messageSetWireFormat => getField(1);
- void set messageSetWireFormat(bool v) { setField(1, v); }
- bool hasMessageSetWireFormat() => hasField(1);
+ bool get messageSetWireFormat => $_get(0, 1, false);
+ void set messageSetWireFormat(bool v) { $_setBool(0, 1, v); }
+ bool hasMessageSetWireFormat() => $_has(0, 1);
void clearMessageSetWireFormat() => clearField(1);
- bool get noStandardDescriptorAccessor => getField(2);
- void set noStandardDescriptorAccessor(bool v) { setField(2, v); }
- bool hasNoStandardDescriptorAccessor() => hasField(2);
+ bool get noStandardDescriptorAccessor => $_get(1, 2, false);
+ void set noStandardDescriptorAccessor(bool v) { $_setBool(1, 2, v); }
+ bool hasNoStandardDescriptorAccessor() => $_has(1, 2);
void clearNoStandardDescriptorAccessor() => clearField(2);
- List<UninterpretedOption> get uninterpretedOption => getField(999);
+ List<UninterpretedOption> get uninterpretedOption => $_get(2, 999, null);
}
class _ReadonlyMessageOptions extends MessageOptions with ReadonlyMessageMixin {}
@@ -682,8 +682,8 @@
STRING,
];
- static final Map<int, FieldOptions_CType> _byValue = ProtobufEnum.initByValue(values);
- static FieldOptions_CType valueOf(int value) => _byValue[value];
+ static final Map<int, dynamic> _byValue = ProtobufEnum.initByValue(values);
+ static FieldOptions_CType valueOf(int value) => _byValue[value] as FieldOptions_CType;
static void $checkItem(FieldOptions_CType v) {
if (v is !FieldOptions_CType) checkItemFailed(v, 'FieldOptions_CType');
}
@@ -693,12 +693,12 @@
class FieldOptions extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('FieldOptions')
- ..e(1, 'ctype', PbFieldType.OE, FieldOptions_CType.STRING, FieldOptions_CType.valueOf)
- ..a(2, 'packed', PbFieldType.OB)
- ..a(5, 'lazy', PbFieldType.OB)
- ..a(3, 'deprecated', PbFieldType.OB)
- ..a(9, 'experimentalMapKey', PbFieldType.OS)
- ..pp(999, 'uninterpretedOption', PbFieldType.PM, UninterpretedOption.$checkItem, UninterpretedOption.create)
+ ..e/*<FieldOptions_CType>*/(1, 'ctype', PbFieldType.OE, FieldOptions_CType.STRING, FieldOptions_CType.valueOf)
+ ..a/*<bool>*/(2, 'packed', PbFieldType.OB)
+ ..a/*<bool>*/(3, 'deprecated', PbFieldType.OB)
+ ..a/*<bool>*/(5, 'lazy', PbFieldType.OB)
+ ..a/*<String>*/(9, 'experimentalMapKey', PbFieldType.OS)
+ ..pp/*<UninterpretedOption>*/(999, 'uninterpretedOption', PbFieldType.PM, UninterpretedOption.$checkItem, UninterpretedOption.create)
..hasExtensions = true
;
@@ -718,40 +718,40 @@
if (v is !FieldOptions) checkItemFailed(v, 'FieldOptions');
}
- FieldOptions_CType get ctype => getField(1);
+ FieldOptions_CType get ctype => $_get(0, 1, null);
void set ctype(FieldOptions_CType v) { setField(1, v); }
- bool hasCtype() => hasField(1);
+ bool hasCtype() => $_has(0, 1);
void clearCtype() => clearField(1);
- bool get packed => getField(2);
- void set packed(bool v) { setField(2, v); }
- bool hasPacked() => hasField(2);
+ bool get packed => $_get(1, 2, false);
+ void set packed(bool v) { $_setBool(1, 2, v); }
+ bool hasPacked() => $_has(1, 2);
void clearPacked() => clearField(2);
- bool get lazy => getField(5);
- void set lazy(bool v) { setField(5, v); }
- bool hasLazy() => hasField(5);
- void clearLazy() => clearField(5);
-
- bool get deprecated => getField(3);
- void set deprecated(bool v) { setField(3, v); }
- bool hasDeprecated() => hasField(3);
+ bool get deprecated => $_get(2, 3, false);
+ void set deprecated(bool v) { $_setBool(2, 3, v); }
+ bool hasDeprecated() => $_has(2, 3);
void clearDeprecated() => clearField(3);
- String get experimentalMapKey => getField(9);
- void set experimentalMapKey(String v) { setField(9, v); }
- bool hasExperimentalMapKey() => hasField(9);
+ bool get lazy => $_get(3, 5, false);
+ void set lazy(bool v) { $_setBool(3, 5, v); }
+ bool hasLazy() => $_has(3, 5);
+ void clearLazy() => clearField(5);
+
+ String get experimentalMapKey => $_get(4, 9, '');
+ void set experimentalMapKey(String v) { $_setString(4, 9, v); }
+ bool hasExperimentalMapKey() => $_has(4, 9);
void clearExperimentalMapKey() => clearField(9);
- List<UninterpretedOption> get uninterpretedOption => getField(999);
+ List<UninterpretedOption> get uninterpretedOption => $_get(5, 999, null);
}
class _ReadonlyFieldOptions extends FieldOptions with ReadonlyMessageMixin {}
class EnumOptions extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('EnumOptions')
- ..a(2, 'allowAlias', PbFieldType.OB, true)
- ..pp(999, 'uninterpretedOption', PbFieldType.PM, UninterpretedOption.$checkItem, UninterpretedOption.create)
+ ..a/*<bool>*/(2, 'allowAlias', PbFieldType.OB, true)
+ ..pp/*<UninterpretedOption>*/(999, 'uninterpretedOption', PbFieldType.PM, UninterpretedOption.$checkItem, UninterpretedOption.create)
..hasExtensions = true
;
@@ -771,19 +771,19 @@
if (v is !EnumOptions) checkItemFailed(v, 'EnumOptions');
}
- bool get allowAlias => getField(2);
- void set allowAlias(bool v) { setField(2, v); }
- bool hasAllowAlias() => hasField(2);
+ bool get allowAlias => $_get(0, 2, true);
+ void set allowAlias(bool v) { $_setBool(0, 2, v); }
+ bool hasAllowAlias() => $_has(0, 2);
void clearAllowAlias() => clearField(2);
- List<UninterpretedOption> get uninterpretedOption => getField(999);
+ List<UninterpretedOption> get uninterpretedOption => $_get(1, 999, null);
}
class _ReadonlyEnumOptions extends EnumOptions with ReadonlyMessageMixin {}
class EnumValueOptions extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('EnumValueOptions')
- ..pp(999, 'uninterpretedOption', PbFieldType.PM, UninterpretedOption.$checkItem, UninterpretedOption.create)
+ ..pp/*<UninterpretedOption>*/(999, 'uninterpretedOption', PbFieldType.PM, UninterpretedOption.$checkItem, UninterpretedOption.create)
..hasExtensions = true
;
@@ -803,14 +803,14 @@
if (v is !EnumValueOptions) checkItemFailed(v, 'EnumValueOptions');
}
- List<UninterpretedOption> get uninterpretedOption => getField(999);
+ List<UninterpretedOption> get uninterpretedOption => $_get(0, 999, null);
}
class _ReadonlyEnumValueOptions extends EnumValueOptions with ReadonlyMessageMixin {}
class ServiceOptions extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('ServiceOptions')
- ..pp(999, 'uninterpretedOption', PbFieldType.PM, UninterpretedOption.$checkItem, UninterpretedOption.create)
+ ..pp/*<UninterpretedOption>*/(999, 'uninterpretedOption', PbFieldType.PM, UninterpretedOption.$checkItem, UninterpretedOption.create)
..hasExtensions = true
;
@@ -830,14 +830,14 @@
if (v is !ServiceOptions) checkItemFailed(v, 'ServiceOptions');
}
- List<UninterpretedOption> get uninterpretedOption => getField(999);
+ List<UninterpretedOption> get uninterpretedOption => $_get(0, 999, null);
}
class _ReadonlyServiceOptions extends ServiceOptions with ReadonlyMessageMixin {}
class MethodOptions extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('MethodOptions')
- ..pp(999, 'uninterpretedOption', PbFieldType.PM, UninterpretedOption.$checkItem, UninterpretedOption.create)
+ ..pp/*<UninterpretedOption>*/(999, 'uninterpretedOption', PbFieldType.PM, UninterpretedOption.$checkItem, UninterpretedOption.create)
..hasExtensions = true
;
@@ -857,14 +857,14 @@
if (v is !MethodOptions) checkItemFailed(v, 'MethodOptions');
}
- List<UninterpretedOption> get uninterpretedOption => getField(999);
+ List<UninterpretedOption> get uninterpretedOption => $_get(0, 999, null);
}
class _ReadonlyMethodOptions extends MethodOptions with ReadonlyMessageMixin {}
class StreamOptions extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('StreamOptions')
- ..pp(999, 'uninterpretedOption', PbFieldType.PM, UninterpretedOption.$checkItem, UninterpretedOption.create)
+ ..pp/*<UninterpretedOption>*/(999, 'uninterpretedOption', PbFieldType.PM, UninterpretedOption.$checkItem, UninterpretedOption.create)
..hasExtensions = true
;
@@ -884,15 +884,15 @@
if (v is !StreamOptions) checkItemFailed(v, 'StreamOptions');
}
- List<UninterpretedOption> get uninterpretedOption => getField(999);
+ List<UninterpretedOption> get uninterpretedOption => $_get(0, 999, null);
}
class _ReadonlyStreamOptions extends StreamOptions with ReadonlyMessageMixin {}
class UninterpretedOption_NamePart extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('UninterpretedOption_NamePart')
- ..a(1, 'namePart', PbFieldType.QS)
- ..a(2, 'isExtension', PbFieldType.QB)
+ ..a/*<String>*/(1, 'namePart', PbFieldType.QS)
+ ..a/*<bool>*/(2, 'isExtension', PbFieldType.QB)
;
UninterpretedOption_NamePart() : super();
@@ -911,14 +911,14 @@
if (v is !UninterpretedOption_NamePart) checkItemFailed(v, 'UninterpretedOption_NamePart');
}
- String get namePart => getField(1);
- void set namePart(String v) { setField(1, v); }
- bool hasNamePart() => hasField(1);
+ String get namePart => $_get(0, 1, '');
+ void set namePart(String v) { $_setString(0, 1, v); }
+ bool hasNamePart() => $_has(0, 1);
void clearNamePart() => clearField(1);
- bool get isExtension => getField(2);
- void set isExtension(bool v) { setField(2, v); }
- bool hasIsExtension() => hasField(2);
+ bool get isExtension => $_get(1, 2, false);
+ void set isExtension(bool v) { $_setBool(1, 2, v); }
+ bool hasIsExtension() => $_has(1, 2);
void clearIsExtension() => clearField(2);
}
@@ -926,13 +926,13 @@
class UninterpretedOption extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('UninterpretedOption')
- ..pp(2, 'name', PbFieldType.PM, UninterpretedOption_NamePart.$checkItem, UninterpretedOption_NamePart.create)
- ..a(3, 'identifierValue', PbFieldType.OS)
- ..a(4, 'positiveIntValue', PbFieldType.OU6, Int64.ZERO)
- ..a(5, 'negativeIntValue', PbFieldType.O6, Int64.ZERO)
- ..a(6, 'doubleValue', PbFieldType.OD)
- ..a(7, 'stringValue', PbFieldType.OY)
- ..a(8, 'aggregateValue', PbFieldType.OS)
+ ..pp/*<UninterpretedOption_NamePart>*/(2, 'name', PbFieldType.PM, UninterpretedOption_NamePart.$checkItem, UninterpretedOption_NamePart.create)
+ ..a/*<String>*/(3, 'identifierValue', PbFieldType.OS)
+ ..a/*<Int64>*/(4, 'positiveIntValue', PbFieldType.OU6, Int64.ZERO)
+ ..a/*<Int64>*/(5, 'negativeIntValue', PbFieldType.O6, Int64.ZERO)
+ ..a/*<double>*/(6, 'doubleValue', PbFieldType.OD)
+ ..a/*<List<int>>*/(7, 'stringValue', PbFieldType.OY)
+ ..a/*<String>*/(8, 'aggregateValue', PbFieldType.OS)
;
UninterpretedOption() : super();
@@ -951,36 +951,36 @@
if (v is !UninterpretedOption) checkItemFailed(v, 'UninterpretedOption');
}
- List<UninterpretedOption_NamePart> get name => getField(2);
+ List<UninterpretedOption_NamePart> get name => $_get(0, 2, null);
- String get identifierValue => getField(3);
- void set identifierValue(String v) { setField(3, v); }
- bool hasIdentifierValue() => hasField(3);
+ String get identifierValue => $_get(1, 3, '');
+ void set identifierValue(String v) { $_setString(1, 3, v); }
+ bool hasIdentifierValue() => $_has(1, 3);
void clearIdentifierValue() => clearField(3);
- Int64 get positiveIntValue => getField(4);
- void set positiveIntValue(Int64 v) { setField(4, v); }
- bool hasPositiveIntValue() => hasField(4);
+ Int64 get positiveIntValue => $_get(2, 4, null);
+ void set positiveIntValue(Int64 v) { $_setInt64(2, 4, v); }
+ bool hasPositiveIntValue() => $_has(2, 4);
void clearPositiveIntValue() => clearField(4);
- Int64 get negativeIntValue => getField(5);
- void set negativeIntValue(Int64 v) { setField(5, v); }
- bool hasNegativeIntValue() => hasField(5);
+ Int64 get negativeIntValue => $_get(3, 5, null);
+ void set negativeIntValue(Int64 v) { $_setInt64(3, 5, v); }
+ bool hasNegativeIntValue() => $_has(3, 5);
void clearNegativeIntValue() => clearField(5);
- double get doubleValue => getField(6);
- void set doubleValue(double v) { setField(6, v); }
- bool hasDoubleValue() => hasField(6);
+ double get doubleValue => $_get(4, 6, null);
+ void set doubleValue(double v) { $_setDouble(4, 6, v); }
+ bool hasDoubleValue() => $_has(4, 6);
void clearDoubleValue() => clearField(6);
- List<int> get stringValue => getField(7);
- void set stringValue(List<int> v) { setField(7, v); }
- bool hasStringValue() => hasField(7);
+ List<int> get stringValue => $_get(5, 7, null);
+ void set stringValue(List<int> v) { $_setBytes(5, 7, v); }
+ bool hasStringValue() => $_has(5, 7);
void clearStringValue() => clearField(7);
- String get aggregateValue => getField(8);
- void set aggregateValue(String v) { setField(8, v); }
- bool hasAggregateValue() => hasField(8);
+ String get aggregateValue => $_get(6, 8, '');
+ void set aggregateValue(String v) { $_setString(6, 8, v); }
+ bool hasAggregateValue() => $_has(6, 8);
void clearAggregateValue() => clearField(8);
}
@@ -988,8 +988,8 @@
class SourceCodeInfo_Location extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('SourceCodeInfo_Location')
- ..p(1, 'path', PbFieldType.K3)
- ..p(2, 'span', PbFieldType.K3)
+ ..p/*<int>*/(1, 'path', PbFieldType.K3)
+ ..p/*<int>*/(2, 'span', PbFieldType.K3)
..hasRequiredFields = false
;
@@ -1009,16 +1009,16 @@
if (v is !SourceCodeInfo_Location) checkItemFailed(v, 'SourceCodeInfo_Location');
}
- List<int> get path => getField(1);
+ List<int> get path => $_get(0, 1, null);
- List<int> get span => getField(2);
+ List<int> get span => $_get(1, 2, null);
}
class _ReadonlySourceCodeInfo_Location extends SourceCodeInfo_Location with ReadonlyMessageMixin {}
class SourceCodeInfo extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('SourceCodeInfo')
- ..pp(1, 'location', PbFieldType.PM, SourceCodeInfo_Location.$checkItem, SourceCodeInfo_Location.create)
+ ..pp/*<SourceCodeInfo_Location>*/(1, 'location', PbFieldType.PM, SourceCodeInfo_Location.$checkItem, SourceCodeInfo_Location.create)
..hasRequiredFields = false
;
@@ -1038,7 +1038,7 @@
if (v is !SourceCodeInfo) checkItemFailed(v, 'SourceCodeInfo');
}
- List<SourceCodeInfo_Location> get location => getField(1);
+ List<SourceCodeInfo_Location> get location => $_get(0, 1, null);
}
class _ReadonlySourceCodeInfo extends SourceCodeInfo with ReadonlyMessageMixin {}
@@ -1101,38 +1101,39 @@
const {'1': 'default_value', '3': 7, '4': 1, '5': 9},
const {'1': 'options', '3': 8, '4': 1, '5': 11, '6': '.proto2.FieldOptions'},
],
- '4': const [
- const {
- '1': 'Type',
- '2': const [
- const {'1': 'TYPE_DOUBLE', '2': 1},
- const {'1': 'TYPE_FLOAT', '2': 2},
- const {'1': 'TYPE_INT64', '2': 3},
- const {'1': 'TYPE_UINT64', '2': 4},
- const {'1': 'TYPE_INT32', '2': 5},
- const {'1': 'TYPE_FIXED64', '2': 6},
- const {'1': 'TYPE_FIXED32', '2': 7},
- const {'1': 'TYPE_BOOL', '2': 8},
- const {'1': 'TYPE_STRING', '2': 9},
- const {'1': 'TYPE_GROUP', '2': 10},
- const {'1': 'TYPE_MESSAGE', '2': 11},
- const {'1': 'TYPE_BYTES', '2': 12},
- const {'1': 'TYPE_UINT32', '2': 13},
- const {'1': 'TYPE_ENUM', '2': 14},
- const {'1': 'TYPE_SFIXED32', '2': 15},
- const {'1': 'TYPE_SFIXED64', '2': 16},
- const {'1': 'TYPE_SINT32', '2': 17},
- const {'1': 'TYPE_SINT64', '2': 18},
- ],
- },
- const {
- '1': 'Label',
- '2': const [
- const {'1': 'LABEL_OPTIONAL', '2': 1},
- const {'1': 'LABEL_REQUIRED', '2': 2},
- const {'1': 'LABEL_REPEATED', '2': 3},
- ],
- },
+ '4': const [FieldDescriptorProto_Type$json, FieldDescriptorProto_Label$json],
+};
+
+const FieldDescriptorProto_Type$json = const {
+ '1': 'Type',
+ '2': const [
+ const {'1': 'TYPE_DOUBLE', '2': 1},
+ const {'1': 'TYPE_FLOAT', '2': 2},
+ const {'1': 'TYPE_INT64', '2': 3},
+ const {'1': 'TYPE_UINT64', '2': 4},
+ const {'1': 'TYPE_INT32', '2': 5},
+ const {'1': 'TYPE_FIXED64', '2': 6},
+ const {'1': 'TYPE_FIXED32', '2': 7},
+ const {'1': 'TYPE_BOOL', '2': 8},
+ const {'1': 'TYPE_STRING', '2': 9},
+ const {'1': 'TYPE_GROUP', '2': 10},
+ const {'1': 'TYPE_MESSAGE', '2': 11},
+ const {'1': 'TYPE_BYTES', '2': 12},
+ const {'1': 'TYPE_UINT32', '2': 13},
+ const {'1': 'TYPE_ENUM', '2': 14},
+ const {'1': 'TYPE_SFIXED32', '2': 15},
+ const {'1': 'TYPE_SFIXED64', '2': 16},
+ const {'1': 'TYPE_SINT32', '2': 17},
+ const {'1': 'TYPE_SINT64', '2': 18},
+ ],
+};
+
+const FieldDescriptorProto_Label$json = const {
+ '1': 'Label',
+ '2': const [
+ const {'1': 'LABEL_OPTIONAL', '2': 1},
+ const {'1': 'LABEL_REQUIRED', '2': 2},
+ const {'1': 'LABEL_REPEATED', '2': 3},
],
};
@@ -1197,21 +1198,21 @@
const {'1': 'py_generic_services', '3': 18, '4': 1, '5': 8, '7': 'false'},
const {'1': 'uninterpreted_option', '3': 999, '4': 3, '5': 11, '6': '.proto2.UninterpretedOption'},
],
- '4': const [
- const {
- '1': 'OptimizeMode',
- '2': const [
- const {'1': 'SPEED', '2': 1},
- const {'1': 'CODE_SIZE', '2': 2},
- const {'1': 'LITE_RUNTIME', '2': 3},
- ],
- },
- ],
+ '4': const [FileOptions_OptimizeMode$json],
'5': const [
const {'1': 1000, '2': 536870912},
],
};
+const FileOptions_OptimizeMode$json = const {
+ '1': 'OptimizeMode',
+ '2': const [
+ const {'1': 'SPEED', '2': 1},
+ const {'1': 'CODE_SIZE', '2': 2},
+ const {'1': 'LITE_RUNTIME', '2': 3},
+ ],
+};
+
const MessageOptions$json = const {
'1': 'MessageOptions',
'2': const [
@@ -1234,19 +1235,19 @@
const {'1': 'experimental_map_key', '3': 9, '4': 1, '5': 9},
const {'1': 'uninterpreted_option', '3': 999, '4': 3, '5': 11, '6': '.proto2.UninterpretedOption'},
],
- '4': const [
- const {
- '1': 'CType',
- '2': const [
- const {'1': 'STRING', '2': 0},
- ],
- },
- ],
+ '4': const [FieldOptions_CType$json],
'5': const [
const {'1': 1000, '2': 536870912},
],
};
+const FieldOptions_CType$json = const {
+ '1': 'CType',
+ '2': const [
+ const {'1': 'STRING', '2': 0},
+ ],
+};
+
const EnumOptions$json = const {
'1': 'EnumOptions',
'2': const [
diff --git a/lib/src/plugin.pb.dart b/lib/src/plugin.pb.dart
index 9ac0ae4..8a6a34d 100644
--- a/lib/src/plugin.pb.dart
+++ b/lib/src/plugin.pb.dart
@@ -8,9 +8,9 @@
class CodeGeneratorRequest extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('CodeGeneratorRequest')
- ..p(1, 'fileToGenerate', PbFieldType.PS)
- ..a(2, 'parameter', PbFieldType.OS)
- ..pp(15, 'protoFile', PbFieldType.PM, proto2.FileDescriptorProto.$checkItem, proto2.FileDescriptorProto.create)
+ ..p/*<String>*/(1, 'fileToGenerate', PbFieldType.PS)
+ ..a/*<String>*/(2, 'parameter', PbFieldType.OS)
+ ..pp/*<proto2.FileDescriptorProto>*/(15, 'protoFile', PbFieldType.PM, proto2.FileDescriptorProto.$checkItem, proto2.FileDescriptorProto.create)
;
CodeGeneratorRequest() : super();
@@ -29,23 +29,23 @@
if (v is !CodeGeneratorRequest) checkItemFailed(v, 'CodeGeneratorRequest');
}
- List<String> get fileToGenerate => getField(1);
+ List<String> get fileToGenerate => $_get(0, 1, null);
- String get parameter => getField(2);
- void set parameter(String v) { setField(2, v); }
- bool hasParameter() => hasField(2);
+ String get parameter => $_get(1, 2, '');
+ void set parameter(String v) { $_setString(1, 2, v); }
+ bool hasParameter() => $_has(1, 2);
void clearParameter() => clearField(2);
- List<proto2.FileDescriptorProto> get protoFile => getField(15);
+ List<proto2.FileDescriptorProto> get protoFile => $_get(2, 15, null);
}
class _ReadonlyCodeGeneratorRequest extends CodeGeneratorRequest with ReadonlyMessageMixin {}
class CodeGeneratorResponse_File extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('CodeGeneratorResponse_File')
- ..a(1, 'name', PbFieldType.OS)
- ..a(2, 'insertionPoint', PbFieldType.OS)
- ..a(15, 'content', PbFieldType.OS)
+ ..a/*<String>*/(1, 'name', PbFieldType.OS)
+ ..a/*<String>*/(2, 'insertionPoint', PbFieldType.OS)
+ ..a/*<String>*/(15, 'content', PbFieldType.OS)
..hasRequiredFields = false
;
@@ -65,19 +65,19 @@
if (v is !CodeGeneratorResponse_File) checkItemFailed(v, 'CodeGeneratorResponse_File');
}
- String get name => getField(1);
- void set name(String v) { setField(1, v); }
- bool hasName() => hasField(1);
+ String get name => $_get(0, 1, '');
+ void set name(String v) { $_setString(0, 1, v); }
+ bool hasName() => $_has(0, 1);
void clearName() => clearField(1);
- String get insertionPoint => getField(2);
- void set insertionPoint(String v) { setField(2, v); }
- bool hasInsertionPoint() => hasField(2);
+ String get insertionPoint => $_get(1, 2, '');
+ void set insertionPoint(String v) { $_setString(1, 2, v); }
+ bool hasInsertionPoint() => $_has(1, 2);
void clearInsertionPoint() => clearField(2);
- String get content => getField(15);
- void set content(String v) { setField(15, v); }
- bool hasContent() => hasField(15);
+ String get content => $_get(2, 15, '');
+ void set content(String v) { $_setString(2, 15, v); }
+ bool hasContent() => $_has(2, 15);
void clearContent() => clearField(15);
}
@@ -85,8 +85,8 @@
class CodeGeneratorResponse extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('CodeGeneratorResponse')
- ..a(1, 'error', PbFieldType.OS)
- ..pp(15, 'file', PbFieldType.PM, CodeGeneratorResponse_File.$checkItem, CodeGeneratorResponse_File.create)
+ ..a/*<String>*/(1, 'error', PbFieldType.OS)
+ ..pp/*<CodeGeneratorResponse_File>*/(15, 'file', PbFieldType.PM, CodeGeneratorResponse_File.$checkItem, CodeGeneratorResponse_File.create)
..hasRequiredFields = false
;
@@ -106,12 +106,12 @@
if (v is !CodeGeneratorResponse) checkItemFailed(v, 'CodeGeneratorResponse');
}
- String get error => getField(1);
- void set error(String v) { setField(1, v); }
- bool hasError() => hasField(1);
+ String get error => $_get(0, 1, '');
+ void set error(String v) { $_setString(0, 1, v); }
+ bool hasError() => $_has(0, 1);
void clearError() => clearField(1);
- List<CodeGeneratorResponse_File> get file => getField(15);
+ List<CodeGeneratorResponse_File> get file => $_get(1, 15, null);
}
class _ReadonlyCodeGeneratorResponse extends CodeGeneratorResponse with ReadonlyMessageMixin {}
diff --git a/pubspec.yaml b/pubspec.yaml
index f1db72a..5fac574 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,12 +1,12 @@
name: protoc_plugin
-version: 0.5.0
+version: 0.5.1
author: Dart Team <misc@dartlang.org>
description: Protoc compiler plugin to generate Dart code
homepage: https://github.com/dart-lang/dart-protoc-plugin
environment:
sdk: '>=1.0.0 <2.0.0'
dependencies:
- protobuf: '>= 0.5.0 <0.6.0'
+ protobuf: '>=0.5.1 <0.6.0'
path: '>=1.0.0 <2.0.0'
dev_dependencies:
browser: any
diff --git a/test/bazel_test.dart b/test/bazel_test.dart
index af28b49..7f1773d 100644
--- a/test/bazel_test.dart
+++ b/test/bazel_test.dart
@@ -10,7 +10,7 @@
void main() {
group('BazelOptionParser', () {
var optionParser;
- var packages;
+ Map<String, BazelPackage> packages;
var errors;
setUp(() {
@@ -111,7 +111,7 @@
});
group('BazelOutputConfiguration', () {
- var packages;
+ Map<String, BazelPackage> packages;
var config;
setUp(() {
diff --git a/test/enum_generator_test.dart b/test/enum_generator_test.dart
index 226b9e5..6903d37 100755
--- a/test/enum_generator_test.dart
+++ b/test/enum_generator_test.dart
@@ -26,8 +26,8 @@
WORK,
];
- static final Map<int, PhoneType> _byValue = ProtobufEnum.initByValue(values);
- static PhoneType valueOf(int value) => _byValue[value];
+ static final Map<int, dynamic> _byValue = ProtobufEnum.initByValue(values);
+ static PhoneType valueOf(int value) => _byValue[value] as PhoneType;
static void $checkItem(PhoneType v) {
if (v is !PhoneType) checkItemFailed(v, 'PhoneType');
}
@@ -37,20 +37,21 @@
''';
EnumDescriptorProto ed = new EnumDescriptorProto()
- ..name = 'PhoneType'
- ..value.addAll([
- new EnumValueDescriptorProto()
- ..name = 'MOBILE'
- ..number = 0,
- new EnumValueDescriptorProto()
- ..name = 'HOME'
- ..number = 1,
- new EnumValueDescriptorProto()
- ..name = 'WORK'
- ..number = 2,
- new EnumValueDescriptorProto()
- ..name = 'BUSINESS'
- ..number = 2]);
+ ..name = 'PhoneType'
+ ..value.addAll([
+ new EnumValueDescriptorProto()
+ ..name = 'MOBILE'
+ ..number = 0,
+ new EnumValueDescriptorProto()
+ ..name = 'HOME'
+ ..number = 1,
+ new EnumValueDescriptorProto()
+ ..name = 'WORK'
+ ..number = 2,
+ new EnumValueDescriptorProto()
+ ..name = 'BUSINESS'
+ ..number = 2
+ ]);
IndentingWriter writer = new IndentingWriter();
EnumGenerator eg = new EnumGenerator(ed, null);
eg.generate(writer);
diff --git a/test/file_generator_test.dart b/test/file_generator_test.dart
index 6a63842..0ec5896 100644
--- a/test/file_generator_test.dart
+++ b/test/file_generator_test.dart
@@ -13,56 +13,56 @@
FileDescriptorProto buildFileDescriptor(
{phoneNumber: true, topLevelEnum: false}) {
-
- FileDescriptorProto fd = new FileDescriptorProto()
- ..name = 'test';
+ FileDescriptorProto fd = new FileDescriptorProto()..name = 'test';
if (topLevelEnum) {
fd.enumType.add(new EnumDescriptorProto()
..name = 'PhoneType'
..value.addAll([
- new EnumValueDescriptorProto()
- ..name = 'MOBILE'
- ..number = 0,
- new EnumValueDescriptorProto()
- ..name = 'HOME'
- ..number = 1,
- new EnumValueDescriptorProto()
- ..name = 'WORK'
- ..number = 2,
- new EnumValueDescriptorProto()
- ..name = 'BUSINESS'
- ..number = 2]));
+ new EnumValueDescriptorProto()
+ ..name = 'MOBILE'
+ ..number = 0,
+ new EnumValueDescriptorProto()
+ ..name = 'HOME'
+ ..number = 1,
+ new EnumValueDescriptorProto()
+ ..name = 'WORK'
+ ..number = 2,
+ new EnumValueDescriptorProto()
+ ..name = 'BUSINESS'
+ ..number = 2
+ ]));
}
if (phoneNumber) {
fd.messageType.add(new DescriptorProto()
..name = 'PhoneNumber'
..field.addAll([
- // required string number = 1;
- new FieldDescriptorProto()
- ..name = 'number'
- ..number = 1
- ..label = FieldDescriptorProto_Label.LABEL_REQUIRED
- ..type = FieldDescriptorProto_Type.TYPE_STRING,
- // optional int32 type = 2;
- // OR
- // optional PhoneType type = 2;
- new FieldDescriptorProto()
- ..name = 'type'
- ..number = 2
- ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
- ..type = topLevelEnum ? FieldDescriptorProto_Type.TYPE_ENUM
- : FieldDescriptorProto_Type.TYPE_INT32
- ..typeName = topLevelEnum ? '.PhoneType' : '',
- // optional string name = 3 [default = "$"];
- new FieldDescriptorProto()
- ..name = 'name'
- ..number = 3
- ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
- ..type = FieldDescriptorProto_Type.TYPE_STRING
- ..defaultValue = r'$'
- ]));
+ // required string number = 1;
+ new FieldDescriptorProto()
+ ..name = 'number'
+ ..number = 1
+ ..label = FieldDescriptorProto_Label.LABEL_REQUIRED
+ ..type = FieldDescriptorProto_Type.TYPE_STRING,
+ // optional int32 type = 2;
+ // OR
+ // optional PhoneType type = 2;
+ new FieldDescriptorProto()
+ ..name = 'type'
+ ..number = 2
+ ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
+ ..type = topLevelEnum
+ ? FieldDescriptorProto_Type.TYPE_ENUM
+ : FieldDescriptorProto_Type.TYPE_INT32
+ ..typeName = topLevelEnum ? '.PhoneType' : '',
+ // optional string name = 3 [default = "$"];
+ new FieldDescriptorProto()
+ ..name = 'name'
+ ..number = 3
+ ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
+ ..type = FieldDescriptorProto_Type.TYPE_STRING
+ ..defaultValue = r'$'
+ ]));
}
return fd;
@@ -81,9 +81,9 @@
class PhoneNumber extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('PhoneNumber')
- ..a(1, 'number', PbFieldType.QS)
- ..a(2, 'type', PbFieldType.O3)
- ..a(3, 'name', PbFieldType.OS, '\$')
+ ..a/*<String>*/(1, 'number', PbFieldType.QS)
+ ..a/*<int>*/(2, 'type', PbFieldType.O3)
+ ..a/*<String>*/(3, 'name', PbFieldType.OS, '\$')
;
PhoneNumber() : super();
@@ -164,8 +164,8 @@
WORK,
];
- static final Map<int, PhoneType> _byValue = ProtobufEnum.initByValue(values);
- static PhoneType valueOf(int value) => _byValue[value];
+ static final Map<int, dynamic> _byValue = ProtobufEnum.initByValue(values);
+ static PhoneType valueOf(int value) => _byValue[value] as PhoneType;
static void $checkItem(PhoneType v) {
if (v is !PhoneType) checkItemFailed(v, 'PhoneType');
}
@@ -184,9 +184,8 @@
};
''';
- FileDescriptorProto fd = buildFileDescriptor(
- phoneNumber: false,
- topLevelEnum: true);
+ FileDescriptorProto fd =
+ buildFileDescriptor(phoneNumber: false, topLevelEnum: true);
var options = parseGenerationOptions(
new CodeGeneratorRequest(), new CodeGeneratorResponse());
@@ -235,13 +234,13 @@
FileDescriptorProto fd = new FileDescriptorProto()
..name = 'test'
..messageType.add(new DescriptorProto()
- ..name = 'Count'
- ..field.addAll([
- new FieldDescriptorProto()
- ..name = 'count'
- ..number = 1
- ..type = FieldDescriptorProto_Type.TYPE_INT64
- ]));
+ ..name = 'Count'
+ ..field.addAll([
+ new FieldDescriptorProto()
+ ..name = 'count'
+ ..number = 1
+ ..type = FieldDescriptorProto_Type.TYPE_INT64
+ ]));
var options = parseGenerationOptions(
new CodeGeneratorRequest(), new CodeGeneratorResponse());
@@ -254,7 +253,6 @@
expect(writer.toString(), expected);
});
-
test('FileGenerator handles field_name options', () {
// NOTE: Below > 80 cols because it is matching generated code > 80 cols.
String expected = r'''
@@ -267,9 +265,9 @@
class PhoneNumber extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('PhoneNumber')
- ..a(1, 'no', PbFieldType.QS)
- ..a(2, 'the_type', PbFieldType.O3)
- ..a(3, 'name_', PbFieldType.OS, '\$')
+ ..a/*<String>*/(1, 'no', PbFieldType.QS)
+ ..a/*<int>*/(2, 'the_type', PbFieldType.O3)
+ ..a/*<String>*/(3, 'name_', PbFieldType.OS, '\$')
;
PhoneNumber() : super();
@@ -319,10 +317,9 @@
FileDescriptorProto fd = buildFileDescriptor();
var request = new CodeGeneratorRequest();
request.parameter = 'field_name=PhoneNumber.number|No,'
- 'field_name=PhoneNumber.name|Name_,'
- 'field_name=PhoneNumber.type|The_type';
- var options = parseGenerationOptions(
- request, new CodeGeneratorResponse());
+ 'field_name=PhoneNumber.name|Name_,'
+ 'field_name=PhoneNumber.type|The_type';
+ var options = parseGenerationOptions(request, new CodeGeneratorResponse());
FileGenerator fg = new FileGenerator(fd);
link(options, [fg]);
@@ -346,9 +343,9 @@
class M extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('M')
- ..a(1, 'm', PbFieldType.OM, M.getDefault, M.create)
- ..a(2, 'm1', PbFieldType.OM, p1.M.getDefault, p1.M.create)
- ..a(3, 'm2', PbFieldType.OM, p2.M.getDefault, p2.M.create)
+ ..a/*<M>*/(1, 'm', PbFieldType.OM, M.getDefault, M.create)
+ ..a/*<p1.M>*/(2, 'm1', PbFieldType.OM, p1.M.getDefault, p1.M.create)
+ ..a/*<p2.M>*/(3, 'm2', PbFieldType.OM, p2.M.getDefault, p2.M.create)
..hasRequiredFields = false
;
@@ -427,67 +424,67 @@
// Description of package1.proto.
DescriptorProto md1 = new DescriptorProto()
- ..name = 'M'
- ..field.addAll([
- // optional M m = 1;
- new FieldDescriptorProto()
- ..name = 'm'
- ..number = 1
- ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
- ..type = FieldDescriptorProto_Type.TYPE_MESSAGE
- ..typeName = ".p1.M",
- ]);
+ ..name = 'M'
+ ..field.addAll([
+ // optional M m = 1;
+ new FieldDescriptorProto()
+ ..name = 'm'
+ ..number = 1
+ ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
+ ..type = FieldDescriptorProto_Type.TYPE_MESSAGE
+ ..typeName = ".p1.M",
+ ]);
FileDescriptorProto fd1 = new FileDescriptorProto()
- ..package = 'p1'
- ..name = 'package1.proto'
- ..messageType.add(md1);
+ ..package = 'p1'
+ ..name = 'package1.proto'
+ ..messageType.add(md1);
// Description of package1.proto.
DescriptorProto md2 = new DescriptorProto()
- ..name = 'M'
- ..field.addAll([
- // optional M m = 1;
- new FieldDescriptorProto()
- ..name = 'x'
- ..number = 1
- ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
- ..type = FieldDescriptorProto_Type.TYPE_MESSAGE
- ..typeName = ".p2.M",
- ]);
+ ..name = 'M'
+ ..field.addAll([
+ // optional M m = 1;
+ new FieldDescriptorProto()
+ ..name = 'x'
+ ..number = 1
+ ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
+ ..type = FieldDescriptorProto_Type.TYPE_MESSAGE
+ ..typeName = ".p2.M",
+ ]);
FileDescriptorProto fd2 = new FileDescriptorProto()
- ..package = 'p2'
- ..name = 'package2.proto'
- ..messageType.add(md2);
+ ..package = 'p2'
+ ..name = 'package2.proto'
+ ..messageType.add(md2);
// Description of test.proto.
DescriptorProto md = new DescriptorProto()
- ..name = 'M'
- ..field.addAll([
- // optional M m = 1;
- new FieldDescriptorProto()
- ..name = 'm'
- ..number = 1
- ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
- ..type = FieldDescriptorProto_Type.TYPE_MESSAGE
- ..typeName = ".M",
- // optional p1.M m1 = 2;
- new FieldDescriptorProto()
- ..name = 'm1'
- ..number = 2
- ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
- ..type = FieldDescriptorProto_Type.TYPE_MESSAGE
- ..typeName = ".p1.M",
- // optional p2.M m2 = 3;
- new FieldDescriptorProto()
- ..name = 'm2'
- ..number = 3
- ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
- ..type = FieldDescriptorProto_Type.TYPE_MESSAGE
- ..typeName = ".p2.M",
- ]);
+ ..name = 'M'
+ ..field.addAll([
+ // optional M m = 1;
+ new FieldDescriptorProto()
+ ..name = 'm'
+ ..number = 1
+ ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
+ ..type = FieldDescriptorProto_Type.TYPE_MESSAGE
+ ..typeName = ".M",
+ // optional p1.M m1 = 2;
+ new FieldDescriptorProto()
+ ..name = 'm1'
+ ..number = 2
+ ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
+ ..type = FieldDescriptorProto_Type.TYPE_MESSAGE
+ ..typeName = ".p1.M",
+ // optional p2.M m2 = 3;
+ new FieldDescriptorProto()
+ ..name = 'm2'
+ ..number = 3
+ ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
+ ..type = FieldDescriptorProto_Type.TYPE_MESSAGE
+ ..typeName = ".p2.M",
+ ]);
FileDescriptorProto fd = new FileDescriptorProto()
- ..name = 'test.proto'
- ..messageType.add(md);
+ ..name = 'test.proto'
+ ..messageType.add(md);
fd.dependency.addAll(['package1.proto', 'package2.proto']);
var request = new CodeGeneratorRequest();
var response = new CodeGeneratorResponse();
diff --git a/test/generated_message_test.dart b/test/generated_message_test.dart
index ca56bc9..28305d4 100755
--- a/test/generated_message_test.dart
+++ b/test/generated_message_test.dart
@@ -27,9 +27,9 @@
throwsA(new isInstanceOf<InvalidProtocolBufferException>());
test('testProtosShareRepeatedArraysIfDidntChange', () {
TestAllTypes value1 = new TestAllTypes()
- ..repeatedInt32.add(100)
- ..repeatedImportEnum.add(ImportEnum.IMPORT_BAR)
- ..repeatedForeignMessage.add(new ForeignMessage());
+ ..repeatedInt32.add(100)
+ ..repeatedImportEnum.add(ImportEnum.IMPORT_BAR)
+ ..repeatedForeignMessage.add(new ForeignMessage());
TestAllTypes value2 = value1.clone();
@@ -40,32 +40,65 @@
test('testSettersRejectNull', () {
TestAllTypes message = new TestAllTypes();
- expect(() { message.optionalString = null; }, throwsArgumentError);
- expect(() { message.optionalBytes = null; }, throwsArgumentError);
- expect(() { message.optionalNestedMessage = null; }, throwsArgumentError);
- expect(() { message.optionalNestedMessage =null; }, throwsArgumentError);
- expect(() { message.optionalNestedEnum = null; }, throwsArgumentError);
- expect(() { message.repeatedString.add(null); }, throwsArgumentError);
- expect(() { message.repeatedBytes.add(null); }, throwsArgumentError);
- expect(() { message.repeatedNestedMessage.add(null); },
- throwsArgumentError);
- expect(() { message.repeatedNestedMessage.add(null); },
- throwsArgumentError);
- expect(() { message.repeatedNestedEnum.add(null); }, throwsArgumentError);
+ expect(() {
+ message.optionalString = null;
+ }, throwsArgumentError);
+ expect(() {
+ message.optionalBytes = null;
+ }, throwsArgumentError);
+ expect(() {
+ message.optionalNestedMessage = null;
+ }, throwsArgumentError);
+ expect(() {
+ message.optionalNestedMessage = null;
+ }, throwsArgumentError);
+ expect(() {
+ message.optionalNestedEnum = null;
+ }, throwsArgumentError);
+ expect(() {
+ message.repeatedString.add(null);
+ }, throwsArgumentError);
+ expect(() {
+ message.repeatedBytes.add(null);
+ }, throwsArgumentError);
+ expect(() {
+ message.repeatedNestedMessage.add(null);
+ }, throwsArgumentError);
+ expect(() {
+ message.repeatedNestedMessage.add(null);
+ }, throwsArgumentError);
+ expect(() {
+ message.repeatedNestedEnum.add(null);
+ }, throwsArgumentError);
});
test('testDefaultMessageIsReadOnly', () {
var message = new TestAllTypes();
- expect(message.optionalNestedMessage, same(TestAllTypes_NestedMessage.getDefault()));
- expect(() { message.optionalNestedMessage.bb = 123; }, throwsUnsupportedError);
+ expect(message.optionalNestedMessage,
+ same(TestAllTypes_NestedMessage.getDefault()));
+ expect(() {
+ message.optionalNestedMessage.bb = 123;
+ }, throwsUnsupportedError);
message = TestAllTypes.getDefault();
- expect(() { message.clear(); }, throwsUnsupportedError);
- expect(() { message.optionalString = "123"; }, throwsUnsupportedError);
- expect(() { message.clearOptionalString(); }, throwsUnsupportedError);
- expect(() { message.repeatedString.add("123"); }, throwsUnsupportedError);
- expect(() { message.repeatedString.clear(); }, throwsUnsupportedError);
- expect(() { message.unknownFields.clear(); }, throwsUnsupportedError);
+ expect(() {
+ message.clear();
+ }, throwsUnsupportedError);
+ expect(() {
+ message.optionalString = "123";
+ }, throwsUnsupportedError);
+ expect(() {
+ message.clearOptionalString();
+ }, throwsUnsupportedError);
+ expect(() {
+ message.repeatedString.add("123");
+ }, throwsUnsupportedError);
+ expect(() {
+ message.repeatedString.clear();
+ }, throwsUnsupportedError);
+ expect(() {
+ message.unknownFields.clear();
+ }, throwsUnsupportedError);
});
test('testRepeatedSetters', () {
@@ -78,21 +111,28 @@
TestAllTypes message = new TestAllTypes();
message.repeatedString.addAll(['one', 'two']);
- expect(() { message.repeatedString[1] = null; }, throwsArgumentError);
+ expect(() {
+ message.repeatedString[1] = null;
+ }, throwsArgumentError);
message.repeatedBytes.addAll(['one'.codeUnits, 'two'.codeUnits]);
- expect(() { message.repeatedBytes[1] = null; }, throwsArgumentError);
+ expect(() {
+ message.repeatedBytes[1] = null;
+ }, throwsArgumentError);
message.repeatedNestedMessage.addAll([
- new TestAllTypes_NestedMessage()..bb = 318,
- new TestAllTypes_NestedMessage()..bb = 456]);
- expect(() { message.repeatedNestedMessage[1] = null; },
- throwsArgumentError);
+ new TestAllTypes_NestedMessage()..bb = 318,
+ new TestAllTypes_NestedMessage()..bb = 456
+ ]);
+ expect(() {
+ message.repeatedNestedMessage[1] = null;
+ }, throwsArgumentError);
- message.repeatedNestedEnum.addAll(
- [TestAllTypes_NestedEnum.FOO, TestAllTypes_NestedEnum.BAR]);
- expect(() { message.repeatedNestedEnum[1] = null; },
- throwsArgumentError);
+ message.repeatedNestedEnum
+ .addAll([TestAllTypes_NestedEnum.FOO, TestAllTypes_NestedEnum.BAR]);
+ expect(() {
+ message.repeatedNestedEnum[1] = null;
+ }, throwsArgumentError);
});
test('testRepeatedAppend', () {
@@ -111,18 +151,21 @@
TestAllTypes message = new TestAllTypes();
expect(() {
- message.repeatedForeignMessage.addAll([
- new ForeignMessage()..c = 12, null]); }, throwsArgumentError);
+ message.repeatedForeignMessage
+ .addAll([new ForeignMessage()..c = 12, null]);
+ }, throwsArgumentError);
expect(() {
- message.repeatedForeignEnum.addAll([ForeignEnum.FOREIGN_BAZ, null]);
- }, throwsArgumentError);
+ message.repeatedForeignEnum.addAll([ForeignEnum.FOREIGN_BAZ, null]);
+ }, throwsArgumentError);
- expect(() { message.repeatedString.addAll(['one', null]); },
- throwsArgumentError);
+ expect(() {
+ message.repeatedString.addAll(['one', null]);
+ }, throwsArgumentError);
- expect(() { message.repeatedBytes.addAll(['one'.codeUnits, null]); },
- throwsArgumentError);
+ expect(() {
+ message.repeatedBytes.addAll(['one'.codeUnits, null]);
+ }, throwsArgumentError);
});
test('testSettingForeignMessage', () {
@@ -148,8 +191,7 @@
test('testDefaults', () {
assertClear(new TestAllTypes());
- TestExtremeDefaultValues message =
- new TestExtremeDefaultValues();
+ TestExtremeDefaultValues message = new TestExtremeDefaultValues();
expect(message.utf8String, '\u1234');
expect(message.infDouble, same(double.INFINITY));
@@ -180,8 +222,8 @@
// void testReflectionDefaults() {} // UNSUPPORTED -- until reflection
test('testEnumInterface', () {
- expect(new TestAllTypes().defaultNestedEnum,
- new isInstanceOf<ProtobufEnum>());
+ expect(
+ new TestAllTypes().defaultNestedEnum, new isInstanceOf<ProtobufEnum>());
});
test('testEnumMap', () {
@@ -203,13 +245,14 @@
assertPackedFieldsSet(message);
});
- test('testIgnoreJavaMultipleFilesOption', () { // UNSUPPORTED getFile
+ test('testIgnoreJavaMultipleFilesOption', () {
+ // UNSUPPORTED getFile
// We mostly just want to check that things compile.
MessageWithNoOuter message = new MessageWithNoOuter()
- ..nested = (new MessageWithNoOuter_NestedMessage()..i = 1)
- ..foreign.add(new TestAllTypes()..optionalInt32 = 1)
- ..nestedEnum = MessageWithNoOuter_NestedEnum.BAZ
- ..foreignEnum = EnumWithNoOuter.BAR;
+ ..nested = (new MessageWithNoOuter_NestedMessage()..i = 1)
+ ..foreign.add(new TestAllTypes()..optionalInt32 = 1)
+ ..nestedEnum = MessageWithNoOuter_NestedEnum.BAZ
+ ..foreignEnum = EnumWithNoOuter.BAR;
expect(new MessageWithNoOuter.fromBuffer(message.writeToBuffer()), message);
@@ -225,19 +268,25 @@
// expect(ServiceWithNoOuter.getDescriptor().getFile()
// MultipleFilesTestProto.getDescriptor());
- expect(new TestAllExtensions().hasExtension(
- Multiple_files_test.extensionWithOuter), isFalse);
+ expect(
+ new TestAllExtensions()
+ .hasExtension(Multiple_files_test.extensionWithOuter),
+ isFalse);
});
test('testOptionalFieldWithRequiredSubfieldsOptimizedForSize', () {
expect(new TestOptionalOptimizedForSize().isInitialized(), isTrue);
- expect((new TestOptionalOptimizedForSize()
- ..o = new TestRequiredOptimizedForSize()).isInitialized(),
+ expect(
+ (new TestOptionalOptimizedForSize()
+ ..o = new TestRequiredOptimizedForSize())
+ .isInitialized(),
isFalse);
- expect((new TestOptionalOptimizedForSize()
- ..o = (new TestRequiredOptimizedForSize()..x = 5)).isInitialized(),
+ expect(
+ (new TestOptionalOptimizedForSize()
+ ..o = (new TestRequiredOptimizedForSize()..x = 5))
+ .isInitialized(),
isTrue);
});
@@ -276,10 +325,10 @@
});
test('testMaliciousRecursion', () {
- _makeRecursiveMessage(int depth) {
- return depth == 0 ?
- (new TestRecursiveMessage()..i = 5) :
- (new TestRecursiveMessage()..a = _makeRecursiveMessage(depth - 1));
+ GeneratedMessage _makeRecursiveMessage(int depth) {
+ return depth == 0
+ ? (new TestRecursiveMessage()..i = 5)
+ : (new TestRecursiveMessage()..a = _makeRecursiveMessage(depth - 1));
}
_assertMessageDepth(TestRecursiveMessage message, int depth) {
@@ -297,24 +346,25 @@
_assertMessageDepth(new TestRecursiveMessage.fromBuffer(data64), 64);
- expect(() { new TestRecursiveMessage.fromBuffer(data65); },
- throwsInvalidProtocolBufferException);
+ expect(() {
+ new TestRecursiveMessage.fromBuffer(data65);
+ }, throwsInvalidProtocolBufferException);
CodedBufferReader input = new CodedBufferReader(data64, recursionLimit: 8);
expect(() {
- // Uncomfortable alternative to below...
- new TestRecursiveMessage().mergeFromCodedBufferReader(input);
- }, throwsInvalidProtocolBufferException);
+ // Uncomfortable alternative to below...
+ new TestRecursiveMessage().mergeFromCodedBufferReader(input);
+ }, throwsInvalidProtocolBufferException);
});
test('testSizeLimit', () {
- CodedBufferReader input = new CodedBufferReader(
- getAllSet().writeToBuffer(), sizeLimit: 16);
+ CodedBufferReader input =
+ new CodedBufferReader(getAllSet().writeToBuffer(), sizeLimit: 16);
expect(() {
- // Uncomfortable alternative to below...
- new TestAllTypes().mergeFromCodedBufferReader(input);
- }, throwsInvalidProtocolBufferException);
+ // Uncomfortable alternative to below...
+ new TestAllTypes().mergeFromCodedBufferReader(input);
+ }, throwsInvalidProtocolBufferException);
});
test('testSerialize', () {
TestAllTypes expected = getAllSet();
@@ -324,10 +374,11 @@
});
test('testEnumValues', () {
- expect(TestAllTypes_NestedEnum.values,
- [ TestAllTypes_NestedEnum.FOO,
- TestAllTypes_NestedEnum.BAR,
- TestAllTypes_NestedEnum.BAZ]);
+ expect(TestAllTypes_NestedEnum.values, [
+ TestAllTypes_NestedEnum.FOO,
+ TestAllTypes_NestedEnum.BAR,
+ TestAllTypes_NestedEnum.BAZ
+ ]);
expect(TestAllTypes_NestedEnum.FOO.value, 1);
expect(TestAllTypes_NestedEnum.BAR.value, 2);
expect(TestAllTypes_NestedEnum.BAZ.value, 3);
@@ -335,78 +386,654 @@
test('testWriteWholeMessage', () {
List<int> goldenMessage = const <int>[
- 0x08, 0x65, 0x10, 0x66, 0x18, 0x67, 0x20, 0x68, 0x28, 0xd2, 0x01, 0x30,
- 0xd4, 0x01, 0x3d, 0x6b, 0x00, 0x00, 0x00, 0x41, 0x6c, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x4d, 0x6d, 0x00, 0x00, 0x00, 0x51, 0x6e, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5d, 0x00, 0x00, 0xde, 0x42, 0x61,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5c, 0x40, 0x68, 0x01, 0x72, 0x03,
- 0x31, 0x31, 0x35, 0x7a, 0x03, 0x31, 0x31, 0x36, 0x83, 0x01, 0x88, 0x01,
- 0x75, 0x84, 0x01, 0x92, 0x01, 0x02, 0x08, 0x76, 0x9a, 0x01, 0x02, 0x08,
- 0x77, 0xa2, 0x01, 0x02, 0x08, 0x78, 0xa8, 0x01, 0x03, 0xb0, 0x01, 0x06,
- 0xb8, 0x01, 0x09, 0xc2, 0x01, 0x03, 0x31, 0x32, 0x34, 0xca, 0x01, 0x03,
- 0x31, 0x32, 0x35, 0xf8, 0x01, 0xc9, 0x01, 0xf8, 0x01, 0xad, 0x02, 0x80,
- 0x02, 0xca, 0x01, 0x80, 0x02, 0xae, 0x02, 0x88, 0x02, 0xcb, 0x01, 0x88,
- 0x02, 0xaf, 0x02, 0x90, 0x02, 0xcc, 0x01, 0x90, 0x02, 0xb0, 0x02, 0x98,
- 0x02, 0x9a, 0x03, 0x98, 0x02, 0xe2, 0x04, 0xa0, 0x02, 0x9c, 0x03, 0xa0,
- 0x02, 0xe4, 0x04, 0xad, 0x02, 0xcf, 0x00, 0x00, 0x00, 0xad, 0x02, 0x33,
- 0x01, 0x00, 0x00, 0xb1, 0x02, 0xd0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0xb1, 0x02, 0x34, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbd,
- 0x02, 0xd1, 0x00, 0x00, 0x00, 0xbd, 0x02, 0x35, 0x01, 0x00, 0x00, 0xc1,
- 0x02, 0xd2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc1, 0x02, 0x36,
- 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcd, 0x02, 0x00, 0x00, 0x53,
- 0x43, 0xcd, 0x02, 0x00, 0x80, 0x9b, 0x43, 0xd1, 0x02, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x80, 0x6a, 0x40, 0xd1, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x80, 0x73, 0x40, 0xd8, 0x02, 0x01, 0xd8, 0x02, 0x00, 0xe2, 0x02, 0x03,
- 0x32, 0x31, 0x35, 0xe2, 0x02, 0x03, 0x33, 0x31, 0x35, 0xea, 0x02, 0x03,
- 0x32, 0x31, 0x36, 0xea, 0x02, 0x03, 0x33, 0x31, 0x36, 0xf3, 0x02, 0xf8,
- 0x02, 0xd9, 0x01, 0xf4, 0x02, 0xf3, 0x02, 0xf8, 0x02, 0xbd, 0x02, 0xf4,
- 0x02, 0x82, 0x03, 0x03, 0x08, 0xda, 0x01, 0x82, 0x03, 0x03, 0x08, 0xbe,
- 0x02, 0x8a, 0x03, 0x03, 0x08, 0xdb, 0x01, 0x8a, 0x03, 0x03, 0x08, 0xbf,
- 0x02, 0x92, 0x03, 0x03, 0x08, 0xdc, 0x01, 0x92, 0x03, 0x03, 0x08, 0xc0,
- 0x02, 0x98, 0x03, 0x02, 0x98, 0x03, 0x03, 0xa0, 0x03, 0x05, 0xa0, 0x03,
- 0x06, 0xa8, 0x03, 0x08, 0xa8, 0x03, 0x09, 0xb2, 0x03, 0x03, 0x32, 0x32,
- 0x34, 0xb2, 0x03, 0x03, 0x33, 0x32, 0x34, 0xba, 0x03, 0x03, 0x32, 0x32,
- 0x35, 0xba, 0x03, 0x03, 0x33, 0x32, 0x35, 0xe8, 0x03, 0x91, 0x03, 0xf0,
- 0x03, 0x92, 0x03, 0xf8, 0x03, 0x93, 0x03, 0x80, 0x04, 0x94, 0x03, 0x88,
- 0x04, 0xaa, 0x06, 0x90, 0x04, 0xac, 0x06, 0x9d, 0x04, 0x97, 0x01, 0x00,
- 0x00, 0xa1, 0x04, 0x98, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xad,
- 0x04, 0x99, 0x01, 0x00, 0x00, 0xb1, 0x04, 0x9a, 0x01, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0xbd, 0x04, 0x00, 0x80, 0xcd, 0x43, 0xc1, 0x04, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0xc0, 0x79, 0x40, 0xc8, 0x04, 0x00, 0xd2, 0x04,
- 0x03, 0x34, 0x31, 0x35, 0xda, 0x04, 0x03, 0x34, 0x31, 0x36, 0x88, 0x05,
- 0x01, 0x90, 0x05, 0x04, 0x98, 0x05, 0x07, 0xa2, 0x05, 0x03, 0x34, 0x32,
- 0x34, 0xaa, 0x05, 0x03, 0x34, 0x32, 0x35
+ 0x08,
+ 0x65,
+ 0x10,
+ 0x66,
+ 0x18,
+ 0x67,
+ 0x20,
+ 0x68,
+ 0x28,
+ 0xd2,
+ 0x01,
+ 0x30,
+ 0xd4,
+ 0x01,
+ 0x3d,
+ 0x6b,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x41,
+ 0x6c,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x4d,
+ 0x6d,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x51,
+ 0x6e,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x5d,
+ 0x00,
+ 0x00,
+ 0xde,
+ 0x42,
+ 0x61,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x5c,
+ 0x40,
+ 0x68,
+ 0x01,
+ 0x72,
+ 0x03,
+ 0x31,
+ 0x31,
+ 0x35,
+ 0x7a,
+ 0x03,
+ 0x31,
+ 0x31,
+ 0x36,
+ 0x83,
+ 0x01,
+ 0x88,
+ 0x01,
+ 0x75,
+ 0x84,
+ 0x01,
+ 0x92,
+ 0x01,
+ 0x02,
+ 0x08,
+ 0x76,
+ 0x9a,
+ 0x01,
+ 0x02,
+ 0x08,
+ 0x77,
+ 0xa2,
+ 0x01,
+ 0x02,
+ 0x08,
+ 0x78,
+ 0xa8,
+ 0x01,
+ 0x03,
+ 0xb0,
+ 0x01,
+ 0x06,
+ 0xb8,
+ 0x01,
+ 0x09,
+ 0xc2,
+ 0x01,
+ 0x03,
+ 0x31,
+ 0x32,
+ 0x34,
+ 0xca,
+ 0x01,
+ 0x03,
+ 0x31,
+ 0x32,
+ 0x35,
+ 0xf8,
+ 0x01,
+ 0xc9,
+ 0x01,
+ 0xf8,
+ 0x01,
+ 0xad,
+ 0x02,
+ 0x80,
+ 0x02,
+ 0xca,
+ 0x01,
+ 0x80,
+ 0x02,
+ 0xae,
+ 0x02,
+ 0x88,
+ 0x02,
+ 0xcb,
+ 0x01,
+ 0x88,
+ 0x02,
+ 0xaf,
+ 0x02,
+ 0x90,
+ 0x02,
+ 0xcc,
+ 0x01,
+ 0x90,
+ 0x02,
+ 0xb0,
+ 0x02,
+ 0x98,
+ 0x02,
+ 0x9a,
+ 0x03,
+ 0x98,
+ 0x02,
+ 0xe2,
+ 0x04,
+ 0xa0,
+ 0x02,
+ 0x9c,
+ 0x03,
+ 0xa0,
+ 0x02,
+ 0xe4,
+ 0x04,
+ 0xad,
+ 0x02,
+ 0xcf,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0xad,
+ 0x02,
+ 0x33,
+ 0x01,
+ 0x00,
+ 0x00,
+ 0xb1,
+ 0x02,
+ 0xd0,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0xb1,
+ 0x02,
+ 0x34,
+ 0x01,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0xbd,
+ 0x02,
+ 0xd1,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0xbd,
+ 0x02,
+ 0x35,
+ 0x01,
+ 0x00,
+ 0x00,
+ 0xc1,
+ 0x02,
+ 0xd2,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0xc1,
+ 0x02,
+ 0x36,
+ 0x01,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0xcd,
+ 0x02,
+ 0x00,
+ 0x00,
+ 0x53,
+ 0x43,
+ 0xcd,
+ 0x02,
+ 0x00,
+ 0x80,
+ 0x9b,
+ 0x43,
+ 0xd1,
+ 0x02,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x80,
+ 0x6a,
+ 0x40,
+ 0xd1,
+ 0x02,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x80,
+ 0x73,
+ 0x40,
+ 0xd8,
+ 0x02,
+ 0x01,
+ 0xd8,
+ 0x02,
+ 0x00,
+ 0xe2,
+ 0x02,
+ 0x03,
+ 0x32,
+ 0x31,
+ 0x35,
+ 0xe2,
+ 0x02,
+ 0x03,
+ 0x33,
+ 0x31,
+ 0x35,
+ 0xea,
+ 0x02,
+ 0x03,
+ 0x32,
+ 0x31,
+ 0x36,
+ 0xea,
+ 0x02,
+ 0x03,
+ 0x33,
+ 0x31,
+ 0x36,
+ 0xf3,
+ 0x02,
+ 0xf8,
+ 0x02,
+ 0xd9,
+ 0x01,
+ 0xf4,
+ 0x02,
+ 0xf3,
+ 0x02,
+ 0xf8,
+ 0x02,
+ 0xbd,
+ 0x02,
+ 0xf4,
+ 0x02,
+ 0x82,
+ 0x03,
+ 0x03,
+ 0x08,
+ 0xda,
+ 0x01,
+ 0x82,
+ 0x03,
+ 0x03,
+ 0x08,
+ 0xbe,
+ 0x02,
+ 0x8a,
+ 0x03,
+ 0x03,
+ 0x08,
+ 0xdb,
+ 0x01,
+ 0x8a,
+ 0x03,
+ 0x03,
+ 0x08,
+ 0xbf,
+ 0x02,
+ 0x92,
+ 0x03,
+ 0x03,
+ 0x08,
+ 0xdc,
+ 0x01,
+ 0x92,
+ 0x03,
+ 0x03,
+ 0x08,
+ 0xc0,
+ 0x02,
+ 0x98,
+ 0x03,
+ 0x02,
+ 0x98,
+ 0x03,
+ 0x03,
+ 0xa0,
+ 0x03,
+ 0x05,
+ 0xa0,
+ 0x03,
+ 0x06,
+ 0xa8,
+ 0x03,
+ 0x08,
+ 0xa8,
+ 0x03,
+ 0x09,
+ 0xb2,
+ 0x03,
+ 0x03,
+ 0x32,
+ 0x32,
+ 0x34,
+ 0xb2,
+ 0x03,
+ 0x03,
+ 0x33,
+ 0x32,
+ 0x34,
+ 0xba,
+ 0x03,
+ 0x03,
+ 0x32,
+ 0x32,
+ 0x35,
+ 0xba,
+ 0x03,
+ 0x03,
+ 0x33,
+ 0x32,
+ 0x35,
+ 0xe8,
+ 0x03,
+ 0x91,
+ 0x03,
+ 0xf0,
+ 0x03,
+ 0x92,
+ 0x03,
+ 0xf8,
+ 0x03,
+ 0x93,
+ 0x03,
+ 0x80,
+ 0x04,
+ 0x94,
+ 0x03,
+ 0x88,
+ 0x04,
+ 0xaa,
+ 0x06,
+ 0x90,
+ 0x04,
+ 0xac,
+ 0x06,
+ 0x9d,
+ 0x04,
+ 0x97,
+ 0x01,
+ 0x00,
+ 0x00,
+ 0xa1,
+ 0x04,
+ 0x98,
+ 0x01,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0xad,
+ 0x04,
+ 0x99,
+ 0x01,
+ 0x00,
+ 0x00,
+ 0xb1,
+ 0x04,
+ 0x9a,
+ 0x01,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0xbd,
+ 0x04,
+ 0x00,
+ 0x80,
+ 0xcd,
+ 0x43,
+ 0xc1,
+ 0x04,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0xc0,
+ 0x79,
+ 0x40,
+ 0xc8,
+ 0x04,
+ 0x00,
+ 0xd2,
+ 0x04,
+ 0x03,
+ 0x34,
+ 0x31,
+ 0x35,
+ 0xda,
+ 0x04,
+ 0x03,
+ 0x34,
+ 0x31,
+ 0x36,
+ 0x88,
+ 0x05,
+ 0x01,
+ 0x90,
+ 0x05,
+ 0x04,
+ 0x98,
+ 0x05,
+ 0x07,
+ 0xa2,
+ 0x05,
+ 0x03,
+ 0x34,
+ 0x32,
+ 0x34,
+ 0xaa,
+ 0x05,
+ 0x03,
+ 0x34,
+ 0x32,
+ 0x35
];
expect(getAllSet().writeToBuffer(), goldenMessage);
});
test('testWriteWholePackedFieldsMessage', () {
List<int> goldenPackedMessage = const <int>[
- 0xd2, 0x05, 0x04, 0xd9, 0x04, 0xbd, 0x05, 0xda, 0x05, 0x04, 0xda, 0x04,
- 0xbe, 0x05, 0xe2, 0x05, 0x04, 0xdb, 0x04, 0xbf, 0x05, 0xea, 0x05, 0x04,
- 0xdc, 0x04, 0xc0, 0x05, 0xf2, 0x05, 0x04, 0xba, 0x09, 0x82, 0x0b, 0xfa,
- 0x05, 0x04, 0xbc, 0x09, 0x84, 0x0b, 0x82, 0x06, 0x08, 0x5f, 0x02, 0x00,
- 0x00, 0xc3, 0x02, 0x00, 0x00, 0x8a, 0x06, 0x10, 0x60, 0x02, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0xc4, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x92, 0x06, 0x08, 0x61, 0x02, 0x00, 0x00, 0xc5, 0x02, 0x00, 0x00, 0x9a,
- 0x06, 0x10, 0x62, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x02,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa2, 0x06, 0x08, 0x00, 0xc0, 0x18,
- 0x44, 0x00, 0xc0, 0x31, 0x44, 0xaa, 0x06, 0x10, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x20, 0x83, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x86, 0x40,
- 0xb2, 0x06, 0x02, 0x01, 0x00, 0xba, 0x06, 0x02, 0x05, 0x06
+ 0xd2,
+ 0x05,
+ 0x04,
+ 0xd9,
+ 0x04,
+ 0xbd,
+ 0x05,
+ 0xda,
+ 0x05,
+ 0x04,
+ 0xda,
+ 0x04,
+ 0xbe,
+ 0x05,
+ 0xe2,
+ 0x05,
+ 0x04,
+ 0xdb,
+ 0x04,
+ 0xbf,
+ 0x05,
+ 0xea,
+ 0x05,
+ 0x04,
+ 0xdc,
+ 0x04,
+ 0xc0,
+ 0x05,
+ 0xf2,
+ 0x05,
+ 0x04,
+ 0xba,
+ 0x09,
+ 0x82,
+ 0x0b,
+ 0xfa,
+ 0x05,
+ 0x04,
+ 0xbc,
+ 0x09,
+ 0x84,
+ 0x0b,
+ 0x82,
+ 0x06,
+ 0x08,
+ 0x5f,
+ 0x02,
+ 0x00,
+ 0x00,
+ 0xc3,
+ 0x02,
+ 0x00,
+ 0x00,
+ 0x8a,
+ 0x06,
+ 0x10,
+ 0x60,
+ 0x02,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0xc4,
+ 0x02,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x92,
+ 0x06,
+ 0x08,
+ 0x61,
+ 0x02,
+ 0x00,
+ 0x00,
+ 0xc5,
+ 0x02,
+ 0x00,
+ 0x00,
+ 0x9a,
+ 0x06,
+ 0x10,
+ 0x62,
+ 0x02,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0xc6,
+ 0x02,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0xa2,
+ 0x06,
+ 0x08,
+ 0x00,
+ 0xc0,
+ 0x18,
+ 0x44,
+ 0x00,
+ 0xc0,
+ 0x31,
+ 0x44,
+ 0xaa,
+ 0x06,
+ 0x10,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x20,
+ 0x83,
+ 0x40,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x40,
+ 0x86,
+ 0x40,
+ 0xb2,
+ 0x06,
+ 0x02,
+ 0x01,
+ 0x00,
+ 0xba,
+ 0x06,
+ 0x02,
+ 0x05,
+ 0x06
];
expect(getPackedSet().writeToBuffer(), goldenPackedMessage);
});
test('testWriteMessageWithNegativeEnumValue', () {
SparseEnumMessage message = new SparseEnumMessage()
- ..sparseEnum = TestSparseEnum.SPARSE_E;
+ ..sparseEnum = TestSparseEnum.SPARSE_E;
expect(message.sparseEnum.value < 0, isTrue,
reason: 'enum.value should be -53452');
SparseEnumMessage message2 =
new SparseEnumMessage.fromBuffer(message.writeToBuffer());
expect(message2.sparseEnum, TestSparseEnum.SPARSE_E,
- reason: 'should resolve back to SPARSE_E');
+ reason: 'should resolve back to SPARSE_E');
});
test('testReservedNamesOptional', () {
diff --git a/test/message_generator_test.dart b/test/message_generator_test.dart
index df82b3f..7b7eaa4 100755
--- a/test/message_generator_test.dart
+++ b/test/message_generator_test.dart
@@ -28,8 +28,8 @@
WORK,
];
- static final Map<int, PhoneNumber_PhoneType> _byValue = ProtobufEnum.initByValue(values);
- static PhoneNumber_PhoneType valueOf(int value) => _byValue[value];
+ static final Map<int, dynamic> _byValue = ProtobufEnum.initByValue(values);
+ static PhoneNumber_PhoneType valueOf(int value) => _byValue[value] as PhoneNumber_PhoneType;
static void $checkItem(PhoneNumber_PhoneType v) {
if (v is !PhoneNumber_PhoneType) checkItemFailed(v, 'PhoneNumber_PhoneType');
}
@@ -39,9 +39,9 @@
class PhoneNumber extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('PhoneNumber')
- ..a(1, 'number', PbFieldType.QS)
- ..e(2, 'type', PbFieldType.OE, PhoneNumber_PhoneType.MOBILE, PhoneNumber_PhoneType.valueOf)
- ..a(3, 'name', PbFieldType.OS, '\$')
+ ..a/*<String>*/(1, 'number', PbFieldType.QS)
+ ..e/*<PhoneNumber_PhoneType>*/(2, 'type', PbFieldType.OE, PhoneNumber_PhoneType.MOBILE, PhoneNumber_PhoneType.valueOf)
+ ..a/*<String>*/(3, 'name', PbFieldType.OS, '\$')
;
PhoneNumber() : super();
@@ -81,44 +81,45 @@
''';
FileDescriptorProto fd = new FileDescriptorProto();
EnumDescriptorProto ed = new EnumDescriptorProto()
- ..name = 'PhoneType'
- ..value.addAll([
- new EnumValueDescriptorProto()
- ..name = 'MOBILE'
- ..number = 0,
- new EnumValueDescriptorProto()
- ..name = 'HOME'
- ..number = 1,
- new EnumValueDescriptorProto()
- ..name = 'WORK'
- ..number = 2,
- new EnumValueDescriptorProto()
- ..name = 'BUSINESS'
- ..number = 2]);
+ ..name = 'PhoneType'
+ ..value.addAll([
+ new EnumValueDescriptorProto()
+ ..name = 'MOBILE'
+ ..number = 0,
+ new EnumValueDescriptorProto()
+ ..name = 'HOME'
+ ..number = 1,
+ new EnumValueDescriptorProto()
+ ..name = 'WORK'
+ ..number = 2,
+ new EnumValueDescriptorProto()
+ ..name = 'BUSINESS'
+ ..number = 2
+ ]);
DescriptorProto md = new DescriptorProto()
- ..name = 'PhoneNumber'
- ..field.addAll([
- // optional PhoneType type = 2 [default = HOME];
- new FieldDescriptorProto()
- ..name = 'type'
- ..number = 2
- ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
- ..type = FieldDescriptorProto_Type.TYPE_ENUM
- ..typeName = '.PhoneNumber.PhoneType',
- // required string number = 1;
- new FieldDescriptorProto()
- ..name = 'number'
- ..number = 1
- ..label = FieldDescriptorProto_Label.LABEL_REQUIRED
- ..type = FieldDescriptorProto_Type.TYPE_STRING,
- new FieldDescriptorProto()
- ..name = 'name'
- ..number = 3
- ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
- ..type = FieldDescriptorProto_Type.TYPE_STRING
- ..defaultValue = r'$'
- ])
- ..enumType.add(ed);
+ ..name = 'PhoneNumber'
+ ..field.addAll([
+ // optional PhoneType type = 2 [default = HOME];
+ new FieldDescriptorProto()
+ ..name = 'type'
+ ..number = 2
+ ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
+ ..type = FieldDescriptorProto_Type.TYPE_ENUM
+ ..typeName = '.PhoneNumber.PhoneType',
+ // required string number = 1;
+ new FieldDescriptorProto()
+ ..name = 'number'
+ ..number = 1
+ ..label = FieldDescriptorProto_Label.LABEL_REQUIRED
+ ..type = FieldDescriptorProto_Type.TYPE_STRING,
+ new FieldDescriptorProto()
+ ..name = 'name'
+ ..number = 3
+ ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
+ ..type = FieldDescriptorProto_Type.TYPE_STRING
+ ..defaultValue = r'$'
+ ])
+ ..enumType.add(ed);
var options = parseGenerationOptions(
new CodeGeneratorRequest(), new CodeGeneratorResponse());
diff --git a/test/message_test.dart b/test/message_test.dart
index 20ccddf..949043b 100755
--- a/test/message_test.dart
+++ b/test/message_test.dart
@@ -9,31 +9,30 @@
import 'test_util.dart';
-import '../out/protos/descriptor_2_5_opensource.pb.dart'
- show DescriptorProto;
+import '../out/protos/descriptor_2_5_opensource.pb.dart' show DescriptorProto;
import '../out/protos/google/protobuf/unittest.pb.dart';
void main() {
TestRequired TEST_REQUIRED_UNINITIALIZED = new TestRequired();
TestRequired TEST_REQUIRED_INITIALIZED = new TestRequired()
- ..a = 1
- ..b = 2
- ..c = 3;
+ ..a = 1
+ ..b = 2
+ ..c = 3;
test('testMergeFrom', () {
TestAllTypes mergeSource = new TestAllTypes()
- ..optionalInt32 = 1
- ..optionalString = 'foo'
- ..optionalForeignMessage = new ForeignMessage()
- ..repeatedString.add('bar');
+ ..optionalInt32 = 1
+ ..optionalString = 'foo'
+ ..optionalForeignMessage = new ForeignMessage()
+ ..repeatedString.add('bar');
TestAllTypes mergeDest = new TestAllTypes()
- ..optionalInt64 = make64(2)
- ..optionalString = 'baz'
- ..optionalForeignMessage = new ForeignMessage()
- ..optionalForeignMessage = (new ForeignMessage()..c = 3)
- ..repeatedString.add('qux');
+ ..optionalInt64 = make64(2)
+ ..optionalString = 'baz'
+ ..optionalForeignMessage = new ForeignMessage()
+ ..optionalForeignMessage = (new ForeignMessage()..c = 3)
+ ..repeatedString.add('qux');
String mergeResultExpected = '''
optionalInt32: 1
@@ -47,8 +46,8 @@
''';
TestAllTypes result = new TestAllTypes()
- ..mergeFromMessage(mergeSource)
- ..mergeFromMessage(mergeDest);
+ ..mergeFromMessage(mergeSource)
+ ..mergeFromMessage(mergeDest);
expect(result.toString(), mergeResultExpected);
});
@@ -73,24 +72,25 @@
reason: 'TestRequiredForeign without children should be initialized');
message.optionalMessage = TEST_REQUIRED_UNINITIALIZED;
- expect(message.isInitialized(), isFalse, reason:
- 'TestRequiredForeign with optional TEST_REQUIRED_UNINITIALIZED '
- 'should not be initialized');
+ expect(message.isInitialized(), isFalse,
+ reason: 'TestRequiredForeign with optional TEST_REQUIRED_UNINITIALIZED '
+ 'should not be initialized');
message.optionalMessage = TEST_REQUIRED_INITIALIZED;
expect(message.isInitialized(), isTrue,
- reason: 'TestRequiredForeign with optional TEST_REQUIRED_INITIALIZED '
- 'should be initialized');
+ reason: 'TestRequiredForeign with optional TEST_REQUIRED_INITIALIZED '
+ 'should be initialized');
message.repeatedMessage.add(TEST_REQUIRED_UNINITIALIZED);
- expect(message.isInitialized(), isFalse, reason:
- 'TestRequiredForeign with repeating TEST_REQUIRED_UNINITIALIZED '
- 'should not be initialized');
+ expect(message.isInitialized(), isFalse,
+ reason:
+ 'TestRequiredForeign with repeating TEST_REQUIRED_UNINITIALIZED '
+ 'should not be initialized');
message.repeatedMessage[0] = TEST_REQUIRED_INITIALIZED;
expect(message.isInitialized(), isTrue,
reason: 'TestRequiredForeign with repeating TEST_REQUIRED_INITIALIZED '
- 'should be initialized');
+ 'should be initialized');
});
test('testRequiredExtension', () {
@@ -137,17 +137,18 @@
// NOTE: error message differs from Java in that
// fields are referenced using Dart fieldnames r.t.
// proto field names.
- expect(e.message,
- 'Message missing required fields: '
- 'optionalMessage.a, '
- 'optionalMessage.b, '
- 'optionalMessage.c, '
- 'repeatedMessage[0].a, '
- 'repeatedMessage[0].b, '
- 'repeatedMessage[0].c, '
- 'repeatedMessage[1].a, '
- 'repeatedMessage[1].b, '
- 'repeatedMessage[1].c');
+ expect(
+ e.message,
+ 'Message missing required fields: '
+ 'optionalMessage.a, '
+ 'optionalMessage.b, '
+ 'optionalMessage.c, '
+ 'repeatedMessage[0].a, '
+ 'repeatedMessage[0].b, '
+ 'repeatedMessage[0].c, '
+ 'repeatedMessage[1].a, '
+ 'repeatedMessage[1].b, '
+ 'repeatedMessage[1].c');
}
});
@@ -183,7 +184,8 @@
// NOTE: error message differs from Java in that
// fields are referenced using Dart fieldnames r.t.
// proto field names.
- expect(e.message,
+ expect(
+ e.message,
'Message missing required fields: '
'optionalMessage.a, '
'optionalMessage.b, '
@@ -198,50 +200,50 @@
});
test('testClearField', () {
- int fieldNo;
- TestAllTypes message = new TestAllTypes();
+ int fieldNo;
+ TestAllTypes message = new TestAllTypes();
- // Singular field with no default.
- fieldNo = 1;
- expect(message.hasField(fieldNo), isFalse);
- expect(message.getField(fieldNo), 0);
- message.clearField(fieldNo);
- expect(message.hasField(fieldNo), isFalse);
- message.setField(fieldNo, 0);
- expect(message.getField(fieldNo), 0);
- expect(message.hasField(fieldNo), isTrue);
- message.clearField(fieldNo);
- expect(message.hasField(fieldNo), isFalse);
+ // Singular field with no default.
+ fieldNo = 1;
+ expect(message.hasField(fieldNo), isFalse);
+ expect(message.getField(fieldNo), 0);
+ message.clearField(fieldNo);
+ expect(message.hasField(fieldNo), isFalse);
+ message.setField(fieldNo, 0);
+ expect(message.getField(fieldNo), 0);
+ expect(message.hasField(fieldNo), isTrue);
+ message.clearField(fieldNo);
+ expect(message.hasField(fieldNo), isFalse);
- // Repeated field.
- fieldNo = 31;
- expect(message.hasField(fieldNo), isFalse);
- message.getField(fieldNo).add(1);
- expect(message.hasField(fieldNo), isTrue);
+ // Repeated field.
+ fieldNo = 31;
+ expect(message.hasField(fieldNo), isFalse);
+ message.getField(fieldNo).add(1);
+ expect(message.hasField(fieldNo), isTrue);
- // Singular field with default.
- fieldNo = 61;
- expect(message.hasField(fieldNo), isFalse);
- expect(message.getField(fieldNo), 41);
- message.clearField(fieldNo);
- message.setField(fieldNo, 41);
- expect(message.hasField(fieldNo), isTrue);
- message.setField(fieldNo, 42);
- expect(message.hasField(fieldNo), isTrue);
- expect(message.getField(fieldNo), 42);
- message.clearField(fieldNo);
- expect(message.hasField(fieldNo), isFalse);
- expect(message.getField(fieldNo), 41);
+ // Singular field with default.
+ fieldNo = 61;
+ expect(message.hasField(fieldNo), isFalse);
+ expect(message.getField(fieldNo), 41);
+ message.clearField(fieldNo);
+ message.setField(fieldNo, 41);
+ expect(message.hasField(fieldNo), isTrue);
+ message.setField(fieldNo, 42);
+ expect(message.hasField(fieldNo), isTrue);
+ expect(message.getField(fieldNo), 42);
+ message.clearField(fieldNo);
+ expect(message.hasField(fieldNo), isFalse);
+ expect(message.getField(fieldNo), 41);
});
test('JSON constants share structure', () {
const nestedTypeTag = 3;
- expect(TestAllTypes$json['$nestedTypeTag'][0],
- same(TestAllTypes_NestedMessage$json));
+ List fields = TestAllTypes$json['$nestedTypeTag'];
+ expect(fields[0], same(TestAllTypes_NestedMessage$json));
const enumTypeTag = 4;
- expect(TestAllTypes$json['$enumTypeTag'][0],
- same(TestAllTypes_NestedEnum$json));
+ fields = TestAllTypes$json['$enumTypeTag'];
+ expect(fields[0], same(TestAllTypes_NestedEnum$json));
});
test('Can read JSON constant into DescriptorProto', () {
diff --git a/test/service_test.dart b/test/service_test.dart
index 969bb5b..2628a1f 100644
--- a/test/service_test.dart
+++ b/test/service_test.dart
@@ -109,8 +109,8 @@
]);
String readMessageName(fqname) {
- var descriptor = new DescriptorProto()
- ..mergeFromJsonMap(map[fqname]);
+ var json = map[fqname] as Map<String, dynamic>;
+ var descriptor = new DescriptorProto()..mergeFromJsonMap(json);
return descriptor.name;
}
expect(readMessageName('.SearchRequest'), "SearchRequest");
diff --git a/test/validate_fail_test.dart b/test/validate_fail_test.dart
index 42839c8..d133383 100755
--- a/test/validate_fail_test.dart
+++ b/test/validate_fail_test.dart
@@ -10,8 +10,8 @@
import '../out/protos/google/protobuf/unittest.pb.dart';
// [ArgumentError] in production mode, [TypeError] in checked.
-final invalidArgumentException = predicate(
- (e) => e is ArgumentError || e is TypeError);
+final invalidArgumentException =
+ predicate((e) => e is ArgumentError || e is TypeError);
final badArgument = throwsA(invalidArgumentException);
// Suppress an analyzer warning for a deliberate type mismatch.
@@ -21,79 +21,154 @@
test('testValidationFailureMessages', () {
TestAllTypes builder = new TestAllTypes();
- expect(() { builder.optionalInt32 = null; }, throwsArgumentError);
+ expect(() {
+ builder.optionalInt32 = null;
+ }, throwsArgumentError);
- expect(() { builder.optionalInt32 = cast('101'); }, badArgument);
- expect(() { builder.optionalInt32 = -2147483649; }, throwsArgumentError);
- expect(() { builder.optionalInt32 = 2147483648; }, throwsArgumentError);
+ expect(() {
+ builder.optionalInt32 = cast('101');
+ }, badArgument);
+ expect(() {
+ builder.optionalInt32 = -2147483649;
+ }, throwsArgumentError);
+ expect(() {
+ builder.optionalInt32 = 2147483648;
+ }, throwsArgumentError);
- expect(() { builder.optionalInt64 = cast('102'); }, badArgument);
- expect(() { builder.optionalInt64 = cast(-9223372036854775809); },
- badArgument);
- expect(() { builder.optionalInt64 = cast(9223372036854775808); },
- badArgument);
+ expect(() {
+ builder.optionalInt64 = cast('102');
+ }, badArgument);
+ expect(() {
+ builder.optionalInt64 = cast(-9223372036854775809);
+ }, badArgument);
+ expect(() {
+ builder.optionalInt64 = cast(9223372036854775808);
+ }, badArgument);
- expect(() { builder.optionalUint32 = cast('103'); }, badArgument);
- expect(() { builder.optionalUint32 = -1; }, throwsArgumentError);
- expect(() { builder.optionalUint32 = 4294967296; }, throwsArgumentError);
+ expect(() {
+ builder.optionalUint32 = cast('103');
+ }, badArgument);
+ expect(() {
+ builder.optionalUint32 = -1;
+ }, throwsArgumentError);
+ expect(() {
+ builder.optionalUint32 = 4294967296;
+ }, throwsArgumentError);
- expect(() { builder.optionalUint64 = cast('104'); }, badArgument);
- expect(() { builder.optionalUint64 = cast(-1); }, badArgument);
- expect(() { builder.optionalUint64 = cast(18446744073709551616); },
- badArgument);
+ expect(() {
+ builder.optionalUint64 = cast('104');
+ }, badArgument);
+ expect(() {
+ builder.optionalUint64 = cast(-1);
+ }, badArgument);
+ expect(() {
+ builder.optionalUint64 = cast(18446744073709551616);
+ }, badArgument);
- expect(() { builder.optionalSint32 = cast('105'); }, badArgument);
- expect(() { builder.optionalSint32 = -2147483649; }, throwsArgumentError);
- expect(() { builder.optionalSint32 = 2147483648; }, throwsArgumentError);
+ expect(() {
+ builder.optionalSint32 = cast('105');
+ }, badArgument);
+ expect(() {
+ builder.optionalSint32 = -2147483649;
+ }, throwsArgumentError);
+ expect(() {
+ builder.optionalSint32 = 2147483648;
+ }, throwsArgumentError);
- expect(() { builder.optionalSint64 = cast('106'); }, badArgument);
- expect(() { builder.optionalSint64 = cast(-9223372036854775809); },
- badArgument);
- expect(() { builder.optionalSint64 = cast(9223372036854775808); },
- badArgument);
+ expect(() {
+ builder.optionalSint64 = cast('106');
+ }, badArgument);
+ expect(() {
+ builder.optionalSint64 = cast(-9223372036854775809);
+ }, badArgument);
+ expect(() {
+ builder.optionalSint64 = cast(9223372036854775808);
+ }, badArgument);
- expect(() { builder.optionalFixed32 = cast('107'); }, badArgument);
- expect(() { builder.optionalFixed32 = -1; }, throwsArgumentError);
- expect(() { builder.optionalFixed32 = 4294967296; }, throwsArgumentError);
+ expect(() {
+ builder.optionalFixed32 = cast('107');
+ }, badArgument);
+ expect(() {
+ builder.optionalFixed32 = -1;
+ }, throwsArgumentError);
+ expect(() {
+ builder.optionalFixed32 = 4294967296;
+ }, throwsArgumentError);
- expect(() { builder.optionalFixed64 = cast('108'); }, badArgument);
- expect(() { builder.optionalFixed64 = cast(-1); }, badArgument);
- expect(() { builder.optionalFixed64 = cast(18446744073709551616); },
- badArgument);
+ expect(() {
+ builder.optionalFixed64 = cast('108');
+ }, badArgument);
+ expect(() {
+ builder.optionalFixed64 = cast(-1);
+ }, badArgument);
+ expect(() {
+ builder.optionalFixed64 = cast(18446744073709551616);
+ }, badArgument);
- expect(() { builder.optionalSfixed32 = cast('109'); }, badArgument);
- expect(() { builder.optionalSfixed32 = -2147483649; }, throwsArgumentError);
- expect(() { builder.optionalSfixed32 = 2147483648; }, throwsArgumentError);
+ expect(() {
+ builder.optionalSfixed32 = cast('109');
+ }, badArgument);
+ expect(() {
+ builder.optionalSfixed32 = -2147483649;
+ }, throwsArgumentError);
+ expect(() {
+ builder.optionalSfixed32 = 2147483648;
+ }, throwsArgumentError);
- expect(() { builder.optionalSfixed64 = cast('110'); }, badArgument);
- expect(() { builder.optionalSfixed64 = cast(-9223372036854775809); },
- badArgument);
- expect(() { builder.optionalSfixed64 = cast(9223372036854775808); },
- badArgument);
+ expect(() {
+ builder.optionalSfixed64 = cast('110');
+ }, badArgument);
+ expect(() {
+ builder.optionalSfixed64 = cast(-9223372036854775809);
+ }, badArgument);
+ expect(() {
+ builder.optionalSfixed64 = cast(9223372036854775808);
+ }, badArgument);
- expect(() { builder.optionalFloat = cast('111'); }, badArgument);
- expect(() { builder.optionalFloat = -3.4028234663852886E39; },
- throwsArgumentError);
- expect(() { builder.optionalFloat = 3.4028234663852886E39; },
- throwsArgumentError);
+ expect(() {
+ builder.optionalFloat = cast('111');
+ }, badArgument);
+ expect(() {
+ builder.optionalFloat = -3.4028234663852886E39;
+ }, throwsArgumentError);
+ expect(() {
+ builder.optionalFloat = 3.4028234663852886E39;
+ }, throwsArgumentError);
- expect(() { builder.optionalDouble = cast('112'); }, badArgument);
+ expect(() {
+ builder.optionalDouble = cast('112');
+ }, badArgument);
- expect(() { builder.optionalBool = cast('113'); }, badArgument);
+ expect(() {
+ builder.optionalBool = cast('113');
+ }, badArgument);
- expect(() { builder.optionalString = cast(false); }, badArgument);
+ expect(() {
+ builder.optionalString = cast(false);
+ }, badArgument);
- expect(() { builder.optionalBytes = cast('115'); }, badArgument);
+ // Can't test this easily in strong mode.
+ // expect(() {
+ // builder.optionalBytes = cast('115');
+ // }, badArgument);
- expect(() { builder.optionalNestedMessage = cast('118'); }, badArgument);
+ expect(() {
+ builder.optionalNestedMessage = cast('118');
+ }, badArgument);
- expect(() { builder.optionalNestedEnum = cast('121'); }, badArgument);
+ expect(() {
+ builder.optionalNestedEnum = cast('121');
+ }, badArgument);
// Set repeating value (no setter should exist).
- expect(() { cast(builder).repeatedInt32 = 201; }, throwsNoSuchMethodError);
+ expect(() {
+ cast(builder).repeatedInt32 = 201;
+ }, throwsNoSuchMethodError);
// Unknown tag.
- expect(() { builder.setField(999, 'field'); }, throwsArgumentError);
+ expect(() {
+ builder.setField(999, 'field');
+ }, throwsArgumentError);
expect(() {
new TestAllExtensions()