From cf9d4662c90494bdf85eb82b0dba2926e247e25e Mon Sep 17 00:00:00 2001 From: Tim Blasi Date: Mon, 12 Oct 2015 10:08:33 -0700 Subject: [PATCH] refactor(dart/transform): Update protobuf dependencies Update - libprotoc to 2.6.1 - dart-protoc-plugin to 0.5.0 - pkg/protobuf 0.5.0 Closes #4681 --- modules/angular2/pubspec.yaml | 2 +- .../common/model/annotation_model.pb.dart | 56 +- .../common/model/import_export_model.pb.dart | 85 +- .../common/model/ng_deps_model.pb.dart | 24 +- .../common/model/parameter_model.pb.dart | 56 +- .../model/reflection_info_model.pb.dart | 143 +- modules_dart/transform/pubspec.yaml | 4 +- tools/build/protoc-gen-dart | 1876 ++++++++++------- 8 files changed, 1362 insertions(+), 884 deletions(-) diff --git a/modules/angular2/pubspec.yaml b/modules/angular2/pubspec.yaml index db1f18e131..eca0b94371 100644 --- a/modules/angular2/pubspec.yaml +++ b/modules/angular2/pubspec.yaml @@ -19,7 +19,7 @@ dependencies: intl: '^0.12.4' logging: '>=0.9.0 <0.12.0' observe: '^0.13.1' - protobuf: '^0.4.2' + protobuf: '^0.5.0' quiver: '^0.21.4' source_span: '^1.0.0' stack_trace: '^1.1.1' diff --git a/modules_dart/transform/lib/src/transform/common/model/annotation_model.pb.dart b/modules_dart/transform/lib/src/transform/common/model/annotation_model.pb.dart index be555c8d4f..6a0f1aaeaf 100644 --- a/modules_dart/transform/lib/src/transform/common/model/annotation_model.pb.dart +++ b/modules_dart/transform/lib/src/transform/common/model/annotation_model.pb.dart @@ -33,20 +33,20 @@ class NamedParameter extends GeneratedMessage { if (v is! NamedParameter) checkItemFailed(v, 'NamedParameter'); } - String get name => getField(1); + String get name => $_get(0, 1, ''); void set name(String v) { - setField(1, v); + $_setString(0, 1, v); } - bool hasName() => hasField(1); + bool hasName() => $_has(0, 1); void clearName() => clearField(1); - String get value => getField(2); + String get value => $_get(1, 2, ''); void set value(String v) { - setField(2, v); + $_setString(1, 2, v); } - bool hasValue() => hasField(2); + bool hasValue() => $_has(1, 2); void clearValue() => clearField(2); } @@ -88,56 +88,56 @@ class AnnotationModel extends GeneratedMessage { if (v is! AnnotationModel) checkItemFailed(v, 'AnnotationModel'); } - String get name => getField(1); + String get name => $_get(0, 1, ''); void set name(String v) { - setField(1, v); + $_setString(0, 1, v); } - bool hasName() => hasField(1); + bool hasName() => $_has(0, 1); void clearName() => clearField(1); - List get parameters => getField(2); + List get parameters => $_get(1, 2, null); - List get namedParameters => getField(3); + List get namedParameters => $_get(2, 3, null); - bool get isView => getField(4); + bool get isView => $_get(3, 4, false); void set isView(bool v) { - setField(4, v); + $_setBool(3, 4, v); } - bool hasIsView() => hasField(4); + bool hasIsView() => $_has(3, 4); void clearIsView() => clearField(4); - bool get isDirective => getField(5); + bool get isDirective => $_get(4, 5, false); void set isDirective(bool v) { - setField(5, v); + $_setBool(4, 5, v); } - bool hasIsDirective() => hasField(5); + bool hasIsDirective() => $_has(4, 5); void clearIsDirective() => clearField(5); - bool get isComponent => getField(6); + bool get isComponent => $_get(5, 6, false); void set isComponent(bool v) { - setField(6, v); + $_setBool(5, 6, v); } - bool hasIsComponent() => hasField(6); + bool hasIsComponent() => $_has(5, 6); void clearIsComponent() => clearField(6); - bool get isInjectable => getField(7); + bool get isInjectable => $_get(6, 7, false); void set isInjectable(bool v) { - setField(7, v); + $_setBool(6, 7, v); } - bool hasIsInjectable() => hasField(7); + bool hasIsInjectable() => $_has(6, 7); void clearIsInjectable() => clearField(7); - bool get isConstObject => getField(8); + bool get isConstObject => $_get(7, 8, false); void set isConstObject(bool v) { - setField(8, v); + $_setBool(7, 8, v); } - bool hasIsConstObject() => hasField(8); + bool hasIsConstObject() => $_has(7, 8); void clearIsConstObject() => clearField(8); } @@ -175,6 +175,6 @@ const AnnotationModel$json = const { /** * Generated with: * annotation_model.proto (93cb7c1fba2e56d937fec054b6e119a2a2b9afe7) - * libprotoc 2.5.0 - * dart-protoc-plugin (cc35f743de982a4916588b9c505dd21c7fe87d17) + * libprotoc 2.6.1 + * dart-protoc-plugin (af5fc2bf1de367a434c3b1847ab260510878ffc0) */ diff --git a/modules_dart/transform/lib/src/transform/common/model/import_export_model.pb.dart b/modules_dart/transform/lib/src/transform/common/model/import_export_model.pb.dart index bd59a7bbc5..d8095a8bb2 100644 --- a/modules_dart/transform/lib/src/transform/common/model/import_export_model.pb.dart +++ b/modules_dart/transform/lib/src/transform/common/model/import_export_model.pb.dart @@ -12,12 +12,15 @@ class ImportModel extends GeneratedMessage { ..p(3, 'hideCombinators', PbFieldType.PS) ..a(4, 'prefix', PbFieldType.OS) ..a(5, 'isDeferred', PbFieldType.OB) - ..a(6, 'isNgDeps', PbFieldType.OB) - ; + ..a(6, 'isNgDeps', PbFieldType.OB); ImportModel() : super(); - ImportModel.fromBuffer(List i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromBuffer(i, r); - ImportModel.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); + ImportModel.fromBuffer(List i, + [ExtensionRegistry r = ExtensionRegistry.EMPTY]) + : super.fromBuffer(i, r); + ImportModel.fromJson(String i, + [ExtensionRegistry r = ExtensionRegistry.EMPTY]) + : super.fromJson(i, r); ImportModel clone() => new ImportModel()..mergeFromMessage(this); BuilderInfo get info_ => _i; static ImportModel create() => new ImportModel(); @@ -26,33 +29,46 @@ class ImportModel extends GeneratedMessage { if (_defaultInstance == null) _defaultInstance = new _ReadonlyImportModel(); return _defaultInstance; } + static ImportModel _defaultInstance; static void $checkItem(ImportModel v) { - if (v is !ImportModel) checkItemFailed(v, 'ImportModel'); + if (v is! ImportModel) checkItemFailed(v, 'ImportModel'); } - String get uri => getField(1); - void set uri(String v) { setField(1, v); } - bool hasUri() => hasField(1); + String get uri => $_get(0, 1, ''); + void set uri(String v) { + $_setString(0, 1, v); + } + + bool hasUri() => $_has(0, 1); void clearUri() => clearField(1); - List get showCombinators => getField(2); + List get showCombinators => $_get(1, 2, null); - List get hideCombinators => getField(3); + List get hideCombinators => $_get(2, 3, null); - String get prefix => getField(4); - void set prefix(String v) { setField(4, v); } - bool hasPrefix() => hasField(4); + String get prefix => $_get(3, 4, ''); + void set prefix(String v) { + $_setString(3, 4, v); + } + + bool hasPrefix() => $_has(3, 4); void clearPrefix() => clearField(4); - bool get isDeferred => getField(5); - void set isDeferred(bool v) { setField(5, v); } - bool hasIsDeferred() => hasField(5); + bool get isDeferred => $_get(4, 5, false); + void set isDeferred(bool v) { + $_setBool(4, 5, v); + } + + bool hasIsDeferred() => $_has(4, 5); void clearIsDeferred() => clearField(5); - bool get isNgDeps => getField(6); - void set isNgDeps(bool v) { setField(6, v); } - bool hasIsNgDeps() => hasField(6); + bool get isNgDeps => $_get(5, 6, false); + void set isNgDeps(bool v) { + $_setBool(5, 6, v); + } + + bool hasIsNgDeps() => $_has(5, 6); void clearIsNgDeps() => clearField(6); } @@ -62,12 +78,15 @@ class ExportModel extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('ExportModel') ..a(1, 'uri', PbFieldType.QS) ..p(2, 'showCombinators', PbFieldType.PS) - ..p(3, 'hideCombinators', PbFieldType.PS) - ; + ..p(3, 'hideCombinators', PbFieldType.PS); ExportModel() : super(); - ExportModel.fromBuffer(List i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromBuffer(i, r); - ExportModel.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); + ExportModel.fromBuffer(List i, + [ExtensionRegistry r = ExtensionRegistry.EMPTY]) + : super.fromBuffer(i, r); + ExportModel.fromJson(String i, + [ExtensionRegistry r = ExtensionRegistry.EMPTY]) + : super.fromJson(i, r); ExportModel clone() => new ExportModel()..mergeFromMessage(this); BuilderInfo get info_ => _i; static ExportModel create() => new ExportModel(); @@ -76,19 +95,23 @@ class ExportModel extends GeneratedMessage { if (_defaultInstance == null) _defaultInstance = new _ReadonlyExportModel(); return _defaultInstance; } + static ExportModel _defaultInstance; static void $checkItem(ExportModel v) { - if (v is !ExportModel) checkItemFailed(v, 'ExportModel'); + if (v is! ExportModel) checkItemFailed(v, 'ExportModel'); } - String get uri => getField(1); - void set uri(String v) { setField(1, v); } - bool hasUri() => hasField(1); + String get uri => $_get(0, 1, ''); + void set uri(String v) { + $_setString(0, 1, v); + } + + bool hasUri() => $_has(0, 1); void clearUri() => clearField(1); - List get showCombinators => getField(2); + List get showCombinators => $_get(1, 2, null); - List get hideCombinators => getField(3); + List get hideCombinators => $_get(2, 3, null); } class _ReadonlyExportModel extends ExportModel with ReadonlyMessageMixin {} @@ -117,6 +140,6 @@ const ExportModel$json = const { /** * Generated with: * import_export_model.proto (c018d2ad92db2d341631d813ace70925d1ccbb9b) - * libprotoc 2.5.0 - * dart-protoc-plugin (cc35f743de982a4916588b9c505dd21c7fe87d17) + * libprotoc 2.6.1 + * dart-protoc-plugin (af5fc2bf1de367a434c3b1847ab260510878ffc0) */ diff --git a/modules_dart/transform/lib/src/transform/common/model/ng_deps_model.pb.dart b/modules_dart/transform/lib/src/transform/common/model/ng_deps_model.pb.dart index 556bb8b132..528761a4e0 100644 --- a/modules_dart/transform/lib/src/transform/common/model/ng_deps_model.pb.dart +++ b/modules_dart/transform/lib/src/transform/common/model/ng_deps_model.pb.dart @@ -40,28 +40,28 @@ class NgDepsModel extends GeneratedMessage { if (v is! NgDepsModel) checkItemFailed(v, 'NgDepsModel'); } - String get libraryUri => getField(1); + String get libraryUri => $_get(0, 1, ''); void set libraryUri(String v) { - setField(1, v); + $_setString(0, 1, v); } - bool hasLibraryUri() => hasField(1); + bool hasLibraryUri() => $_has(0, 1); void clearLibraryUri() => clearField(1); - List get partUris => getField(2); + List get partUris => $_get(1, 2, null); - List get imports => getField(3); + List get imports => $_get(2, 3, null); - List get exports => getField(4); + List get exports => $_get(3, 4, null); - List get reflectables => getField(5); + List get reflectables => $_get(4, 5, null); - String get sourceFile => getField(6); + String get sourceFile => $_get(5, 6, ''); void set sourceFile(String v) { - setField(6, v); + $_setString(5, 6, v); } - bool hasSourceFile() => hasField(6); + bool hasSourceFile() => $_has(5, 6); void clearSourceFile() => clearField(6); } @@ -100,6 +100,6 @@ const NgDepsModel$json = const { /** * Generated with: * ng_deps_model.proto (83fe43a087fdd0a7ebee360cd6b669570df4d216) - * libprotoc 2.5.0 - * dart-protoc-plugin (cc35f743de982a4916588b9c505dd21c7fe87d17) + * libprotoc 2.6.1 + * dart-protoc-plugin (af5fc2bf1de367a434c3b1847ab260510878ffc0) */ diff --git a/modules_dart/transform/lib/src/transform/common/model/parameter_model.pb.dart b/modules_dart/transform/lib/src/transform/common/model/parameter_model.pb.dart index 0b8627d42c..949ccd4613 100644 --- a/modules_dart/transform/lib/src/transform/common/model/parameter_model.pb.dart +++ b/modules_dart/transform/lib/src/transform/common/model/parameter_model.pb.dart @@ -11,44 +11,60 @@ class ParameterModel extends GeneratedMessage { ..a(2, 'typeArgs', PbFieldType.OS) ..p(3, 'metadata', PbFieldType.PS) ..a(4, 'paramName', PbFieldType.OS) - ..hasRequiredFields = false - ; + ..hasRequiredFields = false; ParameterModel() : super(); - ParameterModel.fromBuffer(List i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromBuffer(i, r); - ParameterModel.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); + ParameterModel.fromBuffer(List i, + [ExtensionRegistry r = ExtensionRegistry.EMPTY]) + : super.fromBuffer(i, r); + ParameterModel.fromJson(String i, + [ExtensionRegistry r = ExtensionRegistry.EMPTY]) + : super.fromJson(i, r); ParameterModel clone() => new ParameterModel()..mergeFromMessage(this); BuilderInfo get info_ => _i; static ParameterModel create() => new ParameterModel(); - static PbList createRepeated() => new PbList(); + static PbList createRepeated() => + new PbList(); static ParameterModel getDefault() { - if (_defaultInstance == null) _defaultInstance = new _ReadonlyParameterModel(); + if (_defaultInstance == null) _defaultInstance = + new _ReadonlyParameterModel(); return _defaultInstance; } + static ParameterModel _defaultInstance; static void $checkItem(ParameterModel v) { - if (v is !ParameterModel) checkItemFailed(v, 'ParameterModel'); + if (v is! ParameterModel) checkItemFailed(v, 'ParameterModel'); } - String get typeName => getField(1); - void set typeName(String v) { setField(1, v); } - bool hasTypeName() => hasField(1); + String get typeName => $_get(0, 1, ''); + void set typeName(String v) { + $_setString(0, 1, v); + } + + bool hasTypeName() => $_has(0, 1); void clearTypeName() => clearField(1); - String get typeArgs => getField(2); - void set typeArgs(String v) { setField(2, v); } - bool hasTypeArgs() => hasField(2); + String get typeArgs => $_get(1, 2, ''); + void set typeArgs(String v) { + $_setString(1, 2, v); + } + + bool hasTypeArgs() => $_has(1, 2); void clearTypeArgs() => clearField(2); - List get metadata => getField(3); + List get metadata => $_get(2, 3, null); - String get paramName => getField(4); - void set paramName(String v) { setField(4, v); } - bool hasParamName() => hasField(4); + String get paramName => $_get(3, 4, ''); + void set paramName(String v) { + $_setString(3, 4, v); + } + + bool hasParamName() => $_has(3, 4); void clearParamName() => clearField(4); } -class _ReadonlyParameterModel extends ParameterModel with ReadonlyMessageMixin {} +class _ReadonlyParameterModel extends ParameterModel with ReadonlyMessageMixin { +} const ParameterModel$json = const { '1': 'ParameterModel', @@ -63,6 +79,6 @@ const ParameterModel$json = const { /** * Generated with: * parameter_model.proto (2a97dcb9a65b199f50fba67120a85590bceb083a) - * libprotoc 2.5.0 - * dart-protoc-plugin (cc35f743de982a4916588b9c505dd21c7fe87d17) + * libprotoc 2.6.1 + * dart-protoc-plugin (af5fc2bf1de367a434c3b1847ab260510878ffc0) */ diff --git a/modules_dart/transform/lib/src/transform/common/model/reflection_info_model.pb.dart b/modules_dart/transform/lib/src/transform/common/model/reflection_info_model.pb.dart index d40efcb067..c50799773f 100644 --- a/modules_dart/transform/lib/src/transform/common/model/reflection_info_model.pb.dart +++ b/modules_dart/transform/lib/src/transform/common/model/reflection_info_model.pb.dart @@ -10,93 +10,132 @@ import 'parameter_model.pb.dart'; class PropertyMetadataModel extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('PropertyMetadataModel') ..a(1, 'name', PbFieldType.QS) - ..pp(2, 'annotations', PbFieldType.PM, AnnotationModel.$checkItem, AnnotationModel.create) - ; + ..pp(2, 'annotations', PbFieldType.PM, AnnotationModel.$checkItem, + AnnotationModel.create); PropertyMetadataModel() : super(); - PropertyMetadataModel.fromBuffer(List i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromBuffer(i, r); - PropertyMetadataModel.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); - PropertyMetadataModel clone() => new PropertyMetadataModel()..mergeFromMessage(this); + PropertyMetadataModel.fromBuffer(List i, + [ExtensionRegistry r = ExtensionRegistry.EMPTY]) + : super.fromBuffer(i, r); + PropertyMetadataModel.fromJson(String i, + [ExtensionRegistry r = ExtensionRegistry.EMPTY]) + : super.fromJson(i, r); + PropertyMetadataModel clone() => + new PropertyMetadataModel()..mergeFromMessage(this); BuilderInfo get info_ => _i; static PropertyMetadataModel create() => new PropertyMetadataModel(); - static PbList createRepeated() => new PbList(); + static PbList createRepeated() => + new PbList(); static PropertyMetadataModel getDefault() { - if (_defaultInstance == null) _defaultInstance = new _ReadonlyPropertyMetadataModel(); + if (_defaultInstance == null) _defaultInstance = + new _ReadonlyPropertyMetadataModel(); return _defaultInstance; } + static PropertyMetadataModel _defaultInstance; static void $checkItem(PropertyMetadataModel v) { - if (v is !PropertyMetadataModel) checkItemFailed(v, 'PropertyMetadataModel'); + if (v + is! PropertyMetadataModel) checkItemFailed(v, 'PropertyMetadataModel'); } - 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 get annotations => getField(2); + List get annotations => $_get(1, 2, null); } -class _ReadonlyPropertyMetadataModel extends PropertyMetadataModel with ReadonlyMessageMixin {} +class _ReadonlyPropertyMetadataModel extends PropertyMetadataModel + with ReadonlyMessageMixin {} class ReflectionInfoModel extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('ReflectionInfoModel') ..a(1, 'name', PbFieldType.QS) ..a(2, 'ctorName', PbFieldType.OS) ..a(3, 'isFunction', PbFieldType.OB) - ..pp(4, 'annotations', PbFieldType.PM, AnnotationModel.$checkItem, AnnotationModel.create) - ..pp(5, 'parameters', PbFieldType.PM, ParameterModel.$checkItem, ParameterModel.create) + ..pp(4, 'annotations', PbFieldType.PM, AnnotationModel.$checkItem, + AnnotationModel.create) + ..pp(5, 'parameters', PbFieldType.PM, ParameterModel.$checkItem, + ParameterModel.create) ..p(6, 'interfaces', PbFieldType.PS) - ..pp(7, 'propertyMetadata', PbFieldType.PM, PropertyMetadataModel.$checkItem, PropertyMetadataModel.create) - ; + ..pp(7, 'propertyMetadata', PbFieldType.PM, + PropertyMetadataModel.$checkItem, PropertyMetadataModel.create); ReflectionInfoModel() : super(); - ReflectionInfoModel.fromBuffer(List i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromBuffer(i, r); - ReflectionInfoModel.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); - ReflectionInfoModel clone() => new ReflectionInfoModel()..mergeFromMessage(this); + ReflectionInfoModel.fromBuffer(List i, + [ExtensionRegistry r = ExtensionRegistry.EMPTY]) + : super.fromBuffer(i, r); + ReflectionInfoModel.fromJson(String i, + [ExtensionRegistry r = ExtensionRegistry.EMPTY]) + : super.fromJson(i, r); + ReflectionInfoModel clone() => + new ReflectionInfoModel()..mergeFromMessage(this); BuilderInfo get info_ => _i; static ReflectionInfoModel create() => new ReflectionInfoModel(); - static PbList createRepeated() => new PbList(); + static PbList createRepeated() => + new PbList(); static ReflectionInfoModel getDefault() { - if (_defaultInstance == null) _defaultInstance = new _ReadonlyReflectionInfoModel(); + if (_defaultInstance == null) _defaultInstance = + new _ReadonlyReflectionInfoModel(); return _defaultInstance; } + static ReflectionInfoModel _defaultInstance; static void $checkItem(ReflectionInfoModel v) { - if (v is !ReflectionInfoModel) checkItemFailed(v, 'ReflectionInfoModel'); + if (v is! ReflectionInfoModel) checkItemFailed(v, 'ReflectionInfoModel'); } - 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 ctorName => getField(2); - void set ctorName(String v) { setField(2, v); } - bool hasCtorName() => hasField(2); + String get ctorName => $_get(1, 2, ''); + void set ctorName(String v) { + $_setString(1, 2, v); + } + + bool hasCtorName() => $_has(1, 2); void clearCtorName() => clearField(2); - bool get isFunction => getField(3); - void set isFunction(bool v) { setField(3, v); } - bool hasIsFunction() => hasField(3); + bool get isFunction => $_get(2, 3, false); + void set isFunction(bool v) { + $_setBool(2, 3, v); + } + + bool hasIsFunction() => $_has(2, 3); void clearIsFunction() => clearField(3); - List get annotations => getField(4); + List get annotations => $_get(3, 4, null); - List get parameters => getField(5); + List get parameters => $_get(4, 5, null); - List get interfaces => getField(6); + List get interfaces => $_get(5, 6, null); - List get propertyMetadata => getField(7); + List get propertyMetadata => $_get(6, 7, null); } -class _ReadonlyReflectionInfoModel extends ReflectionInfoModel with ReadonlyMessageMixin {} +class _ReadonlyReflectionInfoModel extends ReflectionInfoModel + with ReadonlyMessageMixin {} const PropertyMetadataModel$json = const { '1': 'PropertyMetadataModel', '2': const [ const {'1': 'name', '3': 1, '4': 2, '5': 9}, - const {'1': 'annotations', '3': 2, '4': 3, '5': 11, '6': '.angular2.src.transform.common.model.proto.AnnotationModel'}, + const { + '1': 'annotations', + '3': 2, + '4': 3, + '5': 11, + '6': '.angular2.src.transform.common.model.proto.AnnotationModel' + }, ], }; @@ -106,16 +145,34 @@ const ReflectionInfoModel$json = const { const {'1': 'name', '3': 1, '4': 2, '5': 9}, const {'1': 'ctor_name', '3': 2, '4': 1, '5': 9}, const {'1': 'is_function', '3': 3, '4': 1, '5': 8}, - const {'1': 'annotations', '3': 4, '4': 3, '5': 11, '6': '.angular2.src.transform.common.model.proto.AnnotationModel'}, - const {'1': 'parameters', '3': 5, '4': 3, '5': 11, '6': '.angular2.src.transform.common.model.proto.ParameterModel'}, + const { + '1': 'annotations', + '3': 4, + '4': 3, + '5': 11, + '6': '.angular2.src.transform.common.model.proto.AnnotationModel' + }, + const { + '1': 'parameters', + '3': 5, + '4': 3, + '5': 11, + '6': '.angular2.src.transform.common.model.proto.ParameterModel' + }, const {'1': 'interfaces', '3': 6, '4': 3, '5': 9}, - const {'1': 'propertyMetadata', '3': 7, '4': 3, '5': 11, '6': '.angular2.src.transform.common.model.proto.PropertyMetadataModel'}, + const { + '1': 'propertyMetadata', + '3': 7, + '4': 3, + '5': 11, + '6': '.angular2.src.transform.common.model.proto.PropertyMetadataModel' + }, ], }; /** * Generated with: * reflection_info_model.proto (71d723738054f1276f792a2672a956ef9be94a4c) - * libprotoc 2.5.0 - * dart-protoc-plugin (cc35f743de982a4916588b9c505dd21c7fe87d17) + * libprotoc 2.6.1 + * dart-protoc-plugin (af5fc2bf1de367a434c3b1847ab260510878ffc0) */ diff --git a/modules_dart/transform/pubspec.yaml b/modules_dart/transform/pubspec.yaml index 66d9fe82e6..64316e0c5e 100644 --- a/modules_dart/transform/pubspec.yaml +++ b/modules_dart/transform/pubspec.yaml @@ -10,14 +10,14 @@ dependencies: code_transformers: '^0.2.8' dart_style: '>=0.1.8 <0.3.0' glob: '^1.0.0' - guinness: any html: '^0.12.0' intl: '^0.12.4' logging: '>=0.9.0 <0.12.0' observe: '^0.13.1' - protobuf: '^0.4.2' + protobuf: '^0.5.0' quiver: '^0.21.4' source_span: '^1.0.0' stack_trace: '^1.1.1' dev_dependencies: + guinness: any test: '>=0.12.0 <0.13.0' diff --git a/tools/build/protoc-gen-dart b/tools/build/protoc-gen-dart index 17be1cd5f0..564e66fc4f 100755 --- a/tools/build/protoc-gen-dart +++ b/tools/build/protoc-gen-dart @@ -1,5 +1,5 @@ #!/usr/bin/env dart -// Compiled https://github.com/dart-lang/dart-protoc-plugin/releases, v0.4.1 +// Compiled https://github.com/dart-lang/dart-protoc-plugin/releases, v0.5.0 import "dart:convert"; import "dart:typed_data"; import "dart:math"; @@ -13,36 +13,73 @@ class CryptoUtils { return _CryptoUtils_A.bytesToBase64_B(bytes, urlSafe, addLineSeparator); } } -abstract class _CryptoUtils_A { - static const int PAD_A = 61; - static const int CR_A = 13; - static const int LF_A = 10; - static const int LINE_LENGTH_A = 76; - static const String _encodeTable_A = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - static const String _encodeTableUrlSafe_A = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; - static String bytesToBase64_B(List bytes, [bool urlSafe = false, bool addLineSeparator = false]) { - int len = bytes.length; - if (len == 0) { +const Base64Codec BASE64 = const Base64Codec(); +const List _decodeTable_A = const[-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -2, -2, -1, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 62, -2, 62, -2, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -2, -2, -2, 0, -2, -2, -2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -2, -2, -2, -2, 63, -2, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2]; +const String _encodeTableUrlSafe_A = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; +const String _encodeTable_A = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +const int _LINE_LENGTH = 76; +const int _CR_A = 13; +const int _LF_A = 10; +const List _PAD_BYTES = const[61]; +const List _ENCODED_PAD_BYTES = const[37, 51, 68]; +const String _PAD = "="; +const String _ENCODED_PAD = "%3D"; +class Base64Codec extends Codec, String> { + final bool _urlSafe; + final bool _addLineSeparator; + final bool _encodePaddingCharacter; + const Base64Codec({bool urlSafe: false, bool addLineSeparator: false, bool encodePaddingCharacter: false}) : _urlSafe = urlSafe, _addLineSeparator = addLineSeparator, _encodePaddingCharacter = encodePaddingCharacter; + String get name => "base64"; + String encode(List bytes, {bool urlSafe, bool addLineSeparator, bool encodePaddingCharacter}) { + if (urlSafe == null) urlSafe = _urlSafe; + if (addLineSeparator == null) addLineSeparator = _addLineSeparator; + if (encodePaddingCharacter == null) { + encodePaddingCharacter = _encodePaddingCharacter; + } + return new Base64Encoder(urlSafe: urlSafe, addLineSeparator: addLineSeparator, encodePaddingCharacter: encodePaddingCharacter).convert(bytes); + } + Base64Encoder get encoder => new Base64Encoder(urlSafe: _urlSafe, addLineSeparator: _addLineSeparator, encodePaddingCharacter: _encodePaddingCharacter); + Base64Decoder get decoder => new Base64Decoder(); +} +class Base64Encoder extends Converter, String> { + final bool _urlSafe; + final bool _addLineSeparator; + final bool _encodePaddingCharacter; + final List _pad; + const Base64Encoder({bool urlSafe: false, bool addLineSeparator: false, bool encodePaddingCharacter: false}) : _urlSafe = urlSafe, _addLineSeparator = addLineSeparator, _encodePaddingCharacter = encodePaddingCharacter, _pad = encodePaddingCharacter == true ? _ENCODED_PAD_BYTES : _PAD_BYTES; + String convert(List bytes, [int start_A = 0, int end_A]) { + int bytes_length = bytes.length; + RangeError.checkValidRange(start_A, end_A, bytes_length); + if (end_A == null) end_A = bytes_length; + int length_A = end_A - start_A; + if (length_A == 0) { return ""; } - final String lookup_A = urlSafe ? _encodeTableUrlSafe_A : _encodeTable_A; - final int remainderLength = len.remainder(3); - final int chunkLength = len - remainderLength; - int outputLen = ((len ~/ 3) * 4) + ((remainderLength > 0) ? 4 : 0); - if (addLineSeparator) { - outputLen += ((outputLen - 1) ~/ LINE_LENGTH_A) << 1; + final String lookup_A = _urlSafe ? _encodeTableUrlSafe_A : _encodeTable_A; + final int remainderLength = length_A.remainder(3); + final int chunkLength = length_A - remainderLength; + int baseOutputLength = ((length_A ~/ 3) * 4); + int remainderOutputLength; + if (_encodePaddingCharacter) { + remainderOutputLength = ((remainderLength > 0) ? 6 : 0); + } else { + remainderOutputLength = ((remainderLength > 0) ? 4 : 0); } - List out = new List(outputLen); - int j = 0, i = 0, c = 0; + int outputLength = baseOutputLength + remainderOutputLength; + if (_addLineSeparator) { + outputLength += ((outputLength - 1) ~/ _LINE_LENGTH) << 1; + } + List out = new List(outputLength); + int j = 0, i = start_A, c = 0; while (i < chunkLength) { - int x_A = ((bytes[i++] << 16) & 0xFFFFFF) | ((bytes[i++] << 8) & 0xFFFFFF) | bytes[i++]; + int x_A = ((bytes[i++] << 16) & 0x00FFFFFF) | ((bytes[i++] << 8) & 0x00FFFFFF) | bytes[i++]; out[j++] = lookup_A.codeUnitAt(x_A >> 18); out[j++] = lookup_A.codeUnitAt((x_A >> 12) & 0x3F); out[j++] = lookup_A.codeUnitAt((x_A >> 6) & 0x3F); - out[j++] = lookup_A.codeUnitAt(x_A & 0x3f); - if (addLineSeparator && ++c == 19 && j < outputLen - 2) { - out[j++] = CR_A; - out[j++] = LF_A; + out[j++] = lookup_A.codeUnitAt(x_A & 0x3F); + if (_addLineSeparator && ++c == 19 && j < outputLength - 2) { + out[j++] = _CR_A; + out[j++] = _LF_A; c = 0; } } @@ -50,28 +87,168 @@ abstract class _CryptoUtils_A { int x_A = bytes[i]; out[j++] = lookup_A.codeUnitAt(x_A >> 2); out[j++] = lookup_A.codeUnitAt((x_A << 4) & 0x3F); - out[j++] = PAD_A; - out[j++] = PAD_A; + out.setRange(j, j + _pad.length, _pad); + out.setRange(j + _pad.length, j + 2 * _pad.length, _pad); } else if (remainderLength == 2) { int x_A = bytes[i]; int y_A = bytes[i + 1]; out[j++] = lookup_A.codeUnitAt(x_A >> 2); out[j++] = lookup_A.codeUnitAt(((x_A << 4) | (y_A >> 4)) & 0x3F); out[j++] = lookup_A.codeUnitAt((y_A << 2) & 0x3F); - out[j++] = PAD_A; + out.setRange(j, j + _pad.length, _pad); } return new String.fromCharCodes(out); } + _Base64EncoderSink startChunkedConversion(Sink sink_A) { + StringConversionSink stringSink; + if (sink_A is StringConversionSink) { + stringSink = sink_A; + } else { + stringSink = new StringConversionSink.from(sink_A); + } + return new _Base64EncoderSink(stringSink, _urlSafe, _addLineSeparator); + } +} +class _Base64EncoderSink extends ChunkedConversionSink> { + final Base64Encoder _encoder; + final ChunkedConversionSink _outSink; + final List _buffer_A = new List(); + int _bufferCount = 0; + _Base64EncoderSink(this._outSink, urlSafe, addLineSeparator) : _encoder = new Base64Encoder(urlSafe: urlSafe, addLineSeparator: addLineSeparator); + void add(List chunk) { + var nextBufferCount = (chunk.length + _bufferCount) % 3; + int decodableLength = _bufferCount + chunk.length - nextBufferCount; + if (_bufferCount + chunk.length > _buffer_A.length) { + _buffer_A.replaceRange(_bufferCount, _buffer_A.length, chunk.sublist(0, _buffer_A.length - _bufferCount)); + _buffer_A.addAll(chunk.sublist(_buffer_A.length - _bufferCount)); + } else { + _buffer_A.replaceRange(_bufferCount, _bufferCount + chunk.length, chunk); + } + _outSink.add(_encoder.convert(_buffer_A, 0, decodableLength)); + _buffer_A.removeRange(0, decodableLength); + _bufferCount = nextBufferCount; + } + void close() { + if (_bufferCount > 0) { + _outSink.add(_encoder.convert(_buffer_A.sublist(0, _bufferCount))); + } + _outSink.close(); + } +} +class Base64Decoder extends Converter> { + const Base64Decoder(); + List convert(String input_A) { + int length_A = input_A.length; + if (length_A == 0) { + return new Uint8List(0); + } + int normalLength = 0; + int i = 0; + while (i < length_A) { + int codeUnit = input_A.codeUnitAt(i); + int c = _decodeTable_A[codeUnit]; + if (c == -2) { + if (codeUnit == _ENCODED_PAD_BYTES[0] && i < length_A - 2 && input_A.codeUnitAt(i + 1) == _ENCODED_PAD_BYTES[1] && input_A.codeUnitAt(i + 2) == _ENCODED_PAD_BYTES[2]) { + normalLength++; + i += 2; + } else { + throw new FormatException('Invalid character', input_A, i); + } + } + if (c >= 0) normalLength++; + i++; + } + if (normalLength % 4 != 0) { + throw new FormatException('''Size of Base 64 characters in Input + must be a multiple of 4''', input_A, normalLength); + } + int padLength = 0; + i = length_A - 1; + while (i >= 0) { + int currentCodeUnit = input_A.codeUnitAt(i); + if (currentCodeUnit == _ENCODED_PAD_BYTES[2] && i >= 2 && input_A.codeUnitAt(i - 1) == _ENCODED_PAD_BYTES[1] && input_A.codeUnitAt(i - 2) == _ENCODED_PAD_BYTES[0]) { + padLength++; + i -= 2; + } else if (_decodeTable_A[currentCodeUnit] > 0) { + break; + } else if (currentCodeUnit == _PAD_BYTES[0]) { + padLength++; + } + i--; + } + int outputLength = ((normalLength * 6) >> 3) - padLength; + List out = new Uint8List(outputLength); + for (int i = 0, o = 0; o < outputLength;) { + int x_A = 0; + for (int j = 4; j > 0;) { + int c = _decodeTable_A[input_A.codeUnitAt(i++)]; + if (c >= 0) { + x_A = ((x_A << 6) & 0x00FFFFFF) | c; + j--; + } + } + out[o++] = x_A >> 16; + if (o < outputLength) { + out[o++] = (x_A >> 8) & 0xFF; + if (o < outputLength) out[o++] = x_A & 0xFF; + } + } + return out; + } + _Base64DecoderSink startChunkedConversion(Sink> sink_A) { + if (sink_A is! ByteConversionSink) { + sink_A = new ByteConversionSink.from(sink_A); + } + return new _Base64DecoderSink(sink_A); + } +} +class _Base64DecoderSink extends ChunkedConversionSink { + final Base64Decoder _decoder_A = new Base64Decoder(); + final ChunkedConversionSink> _outSink; + String _unconverted = ""; + _Base64DecoderSink(this._outSink); + void add(String chunk) { + if (chunk.isEmpty) return; + if (_unconverted.isNotEmpty) { + chunk = _unconverted + chunk; + } + chunk = chunk.replaceAll(_ENCODED_PAD, _PAD); + int decodableLength = chunk.length; + if (chunk.length > 3 && chunk.contains(_ENCODED_PAD[0], chunk.length - 2)) { + decodableLength = chunk.lastIndexOf(_ENCODED_PAD[0]); + } + decodableLength -= decodableLength % 4; + _unconverted = chunk.substring(decodableLength); + if (decodableLength > 0) { + _outSink.add(_decoder_A.convert(chunk.substring(0, decodableLength))); + } + } + void close() { + if (_unconverted.isNotEmpty) { + _outSink.add(_decoder_A.convert(_unconverted)); + } + _outSink.close(); + } +} +abstract class _CryptoUtils_A { + static String bytesToBase64_B(List bytes, [bool urlSafe = false, bool addLineSeparator = false]) { + return BASE64.encode(bytes, urlSafe: urlSafe, addLineSeparator: addLineSeparator); + } } class Dart_options { - static final Extension defaultMixin = new Extension('FileOptions', 'defaultMixin', 96128839, GeneratedMessage.OS); - static final Extension mixin = new Extension('MessageOptions', 'mixin', 96128839, GeneratedMessage.OS); + static final Extension defaultMixin = new Extension('FileOptions', 'defaultMixin', 96128839, PbFieldType.OS); + static final Extension mixin = new Extension('MessageOptions', 'mixin', 96128839, PbFieldType.OS); static void registerAllExtensions(ExtensionRegistry registry) { registry.add(defaultMixin); registry.add(mixin); } } -class Int32 implements IntX {} +class Int32 implements IntX { + static int _validateRadix(int radix) { + if (2 <= radix && radix <= 36) return radix; + throw new RangeError.range(radix, 2, 36, 'radix'); + } +} class Int64 implements IntX { final int _l; final int _m; @@ -129,20 +306,20 @@ class Int64 implements IntX { factory Int64.fromInts(int top_A, int bottom_A) { top_A &= 0xffffffff; bottom_A &= 0xffffffff; - int d0 = bottom_A & _MASK; - int d1 = ((top_A & 0xfff) << 10) | ((bottom_A >> _BITS) & 0x3ff); - int d2 = (top_A >> 12) & _MASK2; + int d0 = _MASK & bottom_A; + int d1 = ((0xfff & top_A) << 10) | (0x3ff & (bottom_A >> _BITS)); + int d2 = _MASK2 & (top_A >> 12); return new Int64._bits(d0, d1, d2); } - static Int64 _promote(val) { - if (val is Int64) { - return val; - } else if (val is int) { - return new Int64(val); - } else if (val is Int32) { - return val.toInt64(); + static Int64 _promote(value_A) { + if (value_A is Int64) { + return value_A; + } else if (value_A is int) { + return new Int64(value_A); + } else if (value_A is Int32) { + return value_A.toInt64(); } - throw new ArgumentError(val); + throw new ArgumentError.value(value_A); } Int64 operator+(other) { Int64 o = _promote(other); @@ -204,12 +381,10 @@ class Int64 implements IntX { int c24 = (p4 & 0xfff) << 8; int c2 = c22 + c23 + c24; c1 += c0 >> _BITS; - c0 &= _MASK; c2 += c1 >> _BITS; - c1 &= _MASK; - c2 &= _MASK2; - return new Int64._bits(c0, c1, c2); + return Int64._masked_A(c0, c1, c2); } + Int64 operator%(other) => _divide(this, other, _RETURN_MOD); Int64 operator~/(other) => _divide(this, other, _RETURN_DIV); Int64 remainder(other) => _divide(this, other, _RETURN_REM); Int64 operator&(other) { @@ -231,14 +406,14 @@ class Int64 implements IntX { int a0 = _l ^ o._l; int a1 = _m ^ o._m; int a2 = _h_A ^ o._h_A; - return new Int64._bits(a0, a1, a2); + return Int64._masked_A(a0, a1, a2); } Int64 operator~() { return Int64._masked_A(~_l, ~_m, ~_h_A); } Int64 operator<<(int n) { if (n < 0) { - throw new ArgumentError(n); + throw new ArgumentError.value(n); } n &= 63; int res0, res1, res2; @@ -259,7 +434,7 @@ class Int64 implements IntX { } Int64 operator>>(int n) { if (n < 0) { - throw new ArgumentError(n); + throw new ArgumentError.value(n); } n &= 63; int res0, res1, res2; @@ -308,7 +483,8 @@ class Int64 implements IntX { } return false; } - int compareTo(Comparable other) { + int compareTo(IntX other) => _compareTo(other); + int _compareTo(other) { Int64 o = _promote(other); int signa = _h_A >> (_BITS2 - 1); int signb = o._h_A >> (_BITS2 - 1); @@ -332,18 +508,10 @@ class Int64 implements IntX { } return 0; } - bool operator<(other) { - return this.compareTo(other) < 0; - } - bool operator<=(other) { - return this.compareTo(other) <= 0; - } - bool operator>(other) { - return this.compareTo(other) > 0; - } - bool operator>=(other) { - return this.compareTo(other) >= 0; - } + bool operator<(other) => _compareTo(other) < 0; + bool operator<=(other) => _compareTo(other) <= 0; + bool operator>(other) => this._compareTo(other) > 0; + bool operator>=(other) => _compareTo(other) >= 0; bool get isNegative => (_h_A & _SIGN_BIT_MASK) != 0; bool get isZero => _h_A == 0 && _m == 0 && _l == 0; int get hashCode { @@ -391,10 +559,7 @@ class Int64 implements IntX { Int64 toInt64() => this; String toString() => _toRadixString(10); String toRadixString(int radix) { - if ((radix <= 1) || (radix > 36)) { - throw new ArgumentError("Bad radix: ${radix}"); - } - return _toRadixString(radix); + return _toRadixString(Int32._validateRadix(radix)); } String _toRadixString(int radix) { int d0 = _l; @@ -570,7 +735,7 @@ class Int64 implements IntX { return Int64._masked_A(q0, q1, q2); } if (!aNeg) { - return new Int64._bits(_MASK & r0, r1, r2); + return Int64._masked_A(r0, r1, r2); } if (what == _RETURN_MOD) { if (r0 == 0 && r1 == 0 && r2 == 0) { @@ -583,11 +748,12 @@ class Int64 implements IntX { } } } -abstract class IntX implements Comparable { +abstract class IntX implements Comparable { IntX operator+(other); IntX operator-(other); IntX operator-(); IntX operator*(other); + IntX operator%(other); IntX operator~/(other); IntX remainder(other); IntX operator&(other); @@ -596,7 +762,6 @@ abstract class IntX implements Comparable { IntX operator~(); IntX operator<<(int shiftAmount); IntX operator>>(int shiftAmount); - int compareTo(Comparable other); bool operator==(other); bool operator<(other); bool operator<=(other); @@ -613,7 +778,7 @@ abstract class IntX implements Comparable { String toRadixString(int radix); } final Context url = new Context(style: Style.url_A); -final Context context = createInternal(); +final Context context_A = createInternal(); String get current_A { var uri_A = Uri.base; if (Style.platform == Style.url_A) { @@ -625,7 +790,7 @@ String get current_A { return path_A.substring(0, lastIndex); } } -String withoutExtension(String path_A) => context.withoutExtension_A(path_A); +String withoutExtension(String path_A) => context_A.withoutExtension_A(path_A); const SLASH_A = 0x2f; const COLON_A = 0x3a; const UPPER_A = 0x41; @@ -820,7 +985,7 @@ abstract class InternalStyle extends Style { bool isRootRelative(String path_A); String pathFromUri(Uri uri_A); Uri relativePathToUri(String path_A) { - var segments = context_A.split(path_A); + var segments = context.split(path_A); if (isSeparator(path_A.codeUnitAt(path_A.length - 1))) segments.add(''); return new Uri(pathSegments: segments); } @@ -936,7 +1101,7 @@ abstract class Style { return Style.posix; } String get name; - Context get context_A => new Context(style: this); + Context get context => new Context(style: this); String get separator; String getRoot(String path_A); String pathFromUri(Uri uri_A); @@ -1077,7 +1242,7 @@ bool isAlphabetic(int char) => (char >= UPPER_A && char <= UPPER_Z) || (char >= class CodeGeneratorRequest extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('CodeGeneratorRequest') ..p(1, 'fileToGenerate', PbFieldType.PS) - ..a(2, 'parameter', PbFieldType.OS_A) + ..a(2, 'parameter', PbFieldType.OS) ..pp(15, 'protoFile', PbFieldType.PM, FileDescriptorProto.$checkItem, FileDescriptorProto.create_A); CodeGeneratorRequest() : super(); CodeGeneratorRequest.fromBuffer(List i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromBuffer_A(i, r); @@ -1090,9 +1255,9 @@ class CodeGeneratorRequest extends GeneratedMessage { } class CodeGeneratorResponse_File extends GeneratedMessage { static final BuilderInfo _i_A = new BuilderInfo('CodeGeneratorResponse_File') - ..a(1, 'name', PbFieldType.OS_A) - ..a(2, 'insertionPoint', PbFieldType.OS_A) - ..a(15, 'content', PbFieldType.OS_A) + ..a(1, 'name', PbFieldType.OS) + ..a(2, 'insertionPoint', PbFieldType.OS) + ..a(15, 'content', PbFieldType.OS) ..hasRequiredFields = false; CodeGeneratorResponse_File() : super(); CodeGeneratorResponse_File clone() => new CodeGeneratorResponse_File() @@ -1112,22 +1277,23 @@ class CodeGeneratorResponse_File extends GeneratedMessage { } class CodeGeneratorResponse extends GeneratedMessage { static final BuilderInfo _i_B = new BuilderInfo('CodeGeneratorResponse') - ..a(1, 'error', PbFieldType.OS_A) + ..a(1, 'error', PbFieldType.OS) ..pp(15, 'file', PbFieldType.PM, CodeGeneratorResponse_File.$checkItem_A, CodeGeneratorResponse_File.create_B) ..hasRequiredFields = false; CodeGeneratorResponse() : super(); CodeGeneratorResponse clone() => new CodeGeneratorResponse() ..mergeFromMessage(this); BuilderInfo get info_ => _i_B; + String get error => getField(1); void set error(String v) { setField(1, v); } - List get file_A => getField(15); + List get file => getField(15); } class FileDescriptorProto extends GeneratedMessage { static final BuilderInfo _i_C = new BuilderInfo('FileDescriptorProto') - ..a(1, 'name', PbFieldType.OS_A) - ..a(2, 'package', PbFieldType.OS_A) + ..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) @@ -1175,7 +1341,7 @@ class DescriptorProto_ExtensionRange extends GeneratedMessage { } class DescriptorProto extends GeneratedMessage { static final BuilderInfo _i_E = new BuilderInfo('DescriptorProto') - ..a(1, 'name', PbFieldType.OS_A) + ..a(1, 'name', PbFieldType.OS) ..pp(2, 'field', PbFieldType.PM, FieldDescriptorProto.$checkItem_E, FieldDescriptorProto.create_F) ..pp(6, 'extension', PbFieldType.PM, FieldDescriptorProto.$checkItem_E, FieldDescriptorProto.create_F) ..pp(3, 'nestedType', PbFieldType.PM, DescriptorProto.$checkItem_B, DescriptorProto.create_C) @@ -1237,13 +1403,13 @@ class FieldDescriptorProto_Label extends ProtobufEnum { } class FieldDescriptorProto extends GeneratedMessage { static final BuilderInfo _i_F = new BuilderInfo('FieldDescriptorProto') - ..a(1, 'name', PbFieldType.OS_A) + ..a(1, 'name', PbFieldType.OS) ..a(3, 'number', PbFieldType.O3) ..e(4, 'label', PbFieldType.OE, FieldDescriptorProto_Label.LABEL_OPTIONAL, FieldDescriptorProto_Label.valueOf_A) ..e(5, 'type', PbFieldType.OE, FieldDescriptorProto_Type.TYPE_DOUBLE, FieldDescriptorProto_Type.valueOf) - ..a(6, 'typeName', PbFieldType.OS_A) - ..a(2, 'extendee', PbFieldType.OS_A) - ..a(7, 'defaultValue', PbFieldType.OS_A) + ..a(6, 'typeName', PbFieldType.OS) + ..a(2, 'extendee', PbFieldType.OS) + ..a(7, 'defaultValue', PbFieldType.OS) ..a(8, 'options', PbFieldType.OM, FieldOptions.getDefault_C, FieldOptions.create_K); FieldDescriptorProto() : super(); FieldDescriptorProto clone() => new FieldDescriptorProto() @@ -1269,7 +1435,7 @@ class FieldDescriptorProto extends GeneratedMessage { } class EnumDescriptorProto extends GeneratedMessage { static final BuilderInfo _i_G = new BuilderInfo('EnumDescriptorProto') - ..a(1, 'name', PbFieldType.OS_A) + ..a(1, 'name', PbFieldType.OS) ..pp(2, 'value', PbFieldType.PM, EnumValueDescriptorProto.$checkItem_G, EnumValueDescriptorProto.create_L) ..a(3, 'options', PbFieldType.OM, EnumOptions.getDefault_D, EnumOptions.create_M); EnumDescriptorProto() : super(); @@ -1290,7 +1456,7 @@ class EnumDescriptorProto extends GeneratedMessage { } class EnumValueDescriptorProto extends GeneratedMessage { static final BuilderInfo _i_H = new BuilderInfo('EnumValueDescriptorProto') - ..a(1, 'name', PbFieldType.OS_A) + ..a(1, 'name', PbFieldType.OS) ..a(2, 'number', PbFieldType.O3) ..a(3, 'options', PbFieldType.OM, EnumValueOptions.getDefault_E, EnumValueOptions.create_N); EnumValueDescriptorProto() : super(); @@ -1311,7 +1477,7 @@ class EnumValueDescriptorProto extends GeneratedMessage { } class ServiceDescriptorProto extends GeneratedMessage { static final BuilderInfo _i_I = new BuilderInfo('ServiceDescriptorProto') - ..a(1, 'name', PbFieldType.OS_A) + ..a(1, 'name', PbFieldType.OS) ..pp(2, 'method', PbFieldType.PM, MethodDescriptorProto.$checkItem_H, MethodDescriptorProto.create_O) ..pp(4, 'stream', PbFieldType.PM, StreamDescriptorProto.$checkItem_I, StreamDescriptorProto.create_P) ..a(3, 'options', PbFieldType.OM, ServiceOptions.getDefault_F, ServiceOptions.create_Q); @@ -1333,9 +1499,9 @@ class ServiceDescriptorProto extends GeneratedMessage { } class MethodDescriptorProto extends GeneratedMessage { static final BuilderInfo _i_J = new BuilderInfo('MethodDescriptorProto') - ..a(1, 'name', PbFieldType.OS_A) - ..a(2, 'inputType', PbFieldType.OS_A) - ..a(3, 'outputType', PbFieldType.OS_A) + ..a(1, 'name', PbFieldType.OS) + ..a(2, 'inputType', PbFieldType.OS) + ..a(3, 'outputType', PbFieldType.OS) ..a(4, 'options', PbFieldType.OM, MethodOptions.getDefault_G, MethodOptions.create_R); MethodDescriptorProto() : super(); MethodDescriptorProto clone() => new MethodDescriptorProto() @@ -1356,9 +1522,9 @@ class MethodDescriptorProto extends GeneratedMessage { } class StreamDescriptorProto extends GeneratedMessage { static final BuilderInfo _i_K = new BuilderInfo('StreamDescriptorProto') - ..a(1, 'name', PbFieldType.OS_A) - ..a(2, 'clientMessageType', PbFieldType.OS_A) - ..a(3, 'serverMessageType', PbFieldType.OS_A) + ..a(1, 'name', PbFieldType.OS) + ..a(2, 'clientMessageType', PbFieldType.OS) + ..a(3, 'serverMessageType', PbFieldType.OS) ..a(4, 'options', PbFieldType.OM, StreamOptions.getDefault_H, StreamOptions.create_S); StreamDescriptorProto() : super(); StreamDescriptorProto clone() => new StreamDescriptorProto() @@ -1386,8 +1552,8 @@ class FileOptions_OptimizeMode extends ProtobufEnum { } class FileOptions extends GeneratedMessage { static final BuilderInfo _i_L = new BuilderInfo('FileOptions') - ..a(1, 'javaPackage', PbFieldType.OS_A) - ..a(8, 'javaOuterClassname', PbFieldType.OS_A) + ..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_B) @@ -1439,7 +1605,7 @@ class FieldOptions extends GeneratedMessage { ..a(2, 'packed', PbFieldType.OB) ..a(5, 'lazy', PbFieldType.OB) ..a(3, 'deprecated', PbFieldType.OB) - ..a(9, 'experimentalMapKey', PbFieldType.OS_A) + ..a(9, 'experimentalMapKey', PbFieldType.OS) ..pp(999, 'uninterpretedOption', PbFieldType.PM, UninterpretedOption.$checkItem_J, UninterpretedOption.create_T) ..hasExtensions = true; FieldOptions() : super(); @@ -1552,12 +1718,12 @@ class UninterpretedOption_NamePart extends GeneratedMessage { class UninterpretedOption extends GeneratedMessage { static final BuilderInfo _i_U = new BuilderInfo('UninterpretedOption') ..pp(2, 'name', PbFieldType.PM, UninterpretedOption_NamePart.$checkItem_K, UninterpretedOption_NamePart.create_U) - ..a(3, 'identifierValue', PbFieldType.OS_A) + ..a(3, 'identifierValue', PbFieldType.OS) ..a(4, 'positiveIntValue', PbFieldType.OU6, Int64.ZERO_A) ..a(5, 'negativeIntValue', PbFieldType.O6, Int64.ZERO_A) ..a(6, 'doubleValue', PbFieldType.OD) ..a(7, 'stringValue', PbFieldType.OY) - ..a(8, 'aggregateValue', PbFieldType.OS_A); + ..a(8, 'aggregateValue', PbFieldType.OS); UninterpretedOption() : super(); UninterpretedOption clone() => new UninterpretedOption() ..mergeFromMessage(this); @@ -1603,15 +1769,24 @@ const _UTF8 = const Utf8Codec(allowMalformed: true); class BuilderInfo { final String messageName; final Map fieldInfo = new Map(); + final Map byTagAsString = {}; final Map byName = {}; bool hasExtensions = false; bool hasRequiredFields = true; + List _sortedByTag; BuilderInfo(this.messageName); void add(int tagNumber_A, String name_A, int fieldType_A, dynamic defaultOrMaker, CreateBuilderFunc subBuilder_A, ValueOfFunc valueOf_D) { - fieldInfo[tagNumber_A] = byName[name_A] = new FieldInfo(name_A, tagNumber_A, fieldType_A, defaultOrMaker, subBuilder_A, valueOf_D); + var index_A = fieldInfo.length; + addField(new FieldInfo(name_A, tagNumber_A, index_A, fieldType_A, defaultOrMaker, subBuilder_A, valueOf_D)); } void addRepeated(int tagNumber_A, String name_A, int fieldType_A, CheckFunc check_A, CreateBuilderFunc subBuilder_A, ValueOfFunc valueOf_D) { - fieldInfo[tagNumber_A] = byName[name_A] = new FieldInfo.repeated(name_A, tagNumber_A, fieldType_A, check_A, subBuilder_A, valueOf_D); + var index_A = fieldInfo.length; + addField(new FieldInfo.repeated(name_A, tagNumber_A, index_A, fieldType_A, check_A, subBuilder_A, valueOf_D)); + } + void addField(FieldInfo fi) { + fieldInfo[fi.tagNumber] = fi; + byTagAsString["${fi.tagNumber}"] = fi; + byName[fi.name] = fi; } void a(int tagNumber_A, String name_A, int fieldType_A, [dynamic defaultOrMaker, CreateBuilderFunc subBuilder_A, ValueOfFunc valueOf_D]) { add(tagNumber_A, name_A, fieldType_A, defaultOrMaker, subBuilder_A, valueOf_D); @@ -1631,17 +1806,10 @@ class BuilderInfo { MakeDefaultFunc func = makeDefault(tagNumber_A); return func == null ? null : func(); } - String fieldName(int tagNumber_A) { - FieldInfo i = fieldInfo[tagNumber_A]; - return i != null ? i.name : null; - } MakeDefaultFunc makeDefault(int tagNumber_A) { FieldInfo i = fieldInfo[tagNumber_A]; return i != null ? i.makeDefault : null; } - bool isInitialized(Map fieldValues) { - return fieldInfo.keys.every((tagNumber_A) => _isFieldInitialized(fieldValues, tagNumber_A)); - } CreateBuilderFunc subBuilder(int tagNumber_A) { FieldInfo i = fieldInfo[tagNumber_A]; return i != null ? i.subBuilder : null; @@ -1654,88 +1822,271 @@ class BuilderInfo { FieldInfo i = fieldInfo[tagNumber_A]; return i != null ? i.valueOf_D : null; } - bool _isFieldInitialized(Map fieldValues, int tagNumber_A, [int fieldType_A = null]) { - if (fieldType_A == null) { - fieldType_A = fieldInfo[tagNumber_A].type; - } - if (_isGroupOrMessage(fieldType_A)) { - if (_isRequired(fieldType_A)) { - GeneratedMessage message_A = fieldValues[tagNumber_A]; - if (message_A == null || !message_A.isInitialized()) { - return false; - } - } else if (_isRepeated(fieldType_A)) { - if (fieldValues.containsKey(tagNumber_A)) { - List list_A = fieldValues[tagNumber_A]; - if (!list_A.isEmpty && list_A[0].hasRequiredFields()) { - if (!list_A.every((message_A) => message_A.isInitialized())) { - return false; - } - } - } - } else { - GeneratedMessage message_A = fieldValues[tagNumber_A]; - if (message_A != null && !message_A.isInitialized()) { - return false; - } - } - } else if (_isRequired(fieldType_A)) { - if (fieldValues[tagNumber_A] == null) { - return false; - } - } - return true; + List get sortedByTag { + if (_sortedByTag != null) return _sortedByTag; + _sortedByTag = new List.from(fieldInfo.values) + ..sort((a_A, b) => a_A.tagNumber.compareTo(b.tagNumber)); + return _sortedByTag; } - List _findInvalidFields(Map fieldValues, List invalidFields, [String prefix = '']) { - fieldInfo.forEach((int tagNumber_A, FieldInfo field) { - int fieldType_A = field.type; - if (_isGroupOrMessage(fieldType_A)) { - if (_isRequired(fieldType_A)) { - GeneratedMessage message_A = fieldValues[tagNumber_A]; - if (message_A == null) { - invalidFields.add('${prefix}${field.name}'); - } else { - message_A._findInvalidFields(invalidFields, '${prefix}${field.name}.'); - } - } else if (_isRepeated(fieldType_A)) { - if (fieldValues.containsKey(tagNumber_A)) { - List list_A = fieldValues[tagNumber_A]; - if (!list_A.isEmpty && list_A[0].hasRequiredFields()) { - int position_A = 0; - for (GeneratedMessage message_A in list_A) { - if (message_A.hasRequiredFields()) { - message_A._findInvalidFields(invalidFields, '${prefix}${field.name}[${position_A}].'); - } - position_A++; - } - } - } - } else { - GeneratedMessage message_A = fieldValues[tagNumber_A]; - if (message_A != null) { - message_A._findInvalidFields(invalidFields, '${prefix}${field.name}.'); - } - } - } else if (_isRequired(fieldType_A)) { - if (fieldValues[tagNumber_A] == null) { - invalidFields.add('${prefix}${field.name}'); + GeneratedMessage _makeEmptyMessage(int tagNumber_A, ExtensionRegistry extensionRegistry) { + CreateBuilderFunc subBuilderFunc = subBuilder(tagNumber_A); + if (subBuilderFunc == null && extensionRegistry != null) { + subBuilderFunc = extensionRegistry.getExtension(messageName, tagNumber_A).subBuilder; + } + return subBuilderFunc(); + } + _decodeEnum(int tagNumber_A, ExtensionRegistry registry, int rawValue) { + ValueOfFunc f = valueOfFunc(tagNumber_A); + if (f == null && registry != null) { + f = registry.getExtension(messageName, tagNumber_A).valueOf_D; + } + return f(rawValue); + } +} +void _writeToCodedBufferWriter(_FieldSet fs, CodedBufferWriter out) { + for (var fi in fs._infosSortedByTag) { + var value_A = fs._values_A[fi.index]; + if (value_A == null) continue; + out.writeField(fi.tagNumber, fi.type, value_A); + } + if (fs._hasExtensions) { + for (var tagNumber in sorted(fs._extensions._tagNumbers)) { + var fi = fs._extensions._getInfoOrNull(tagNumber); + out.writeField(tagNumber, fi.type, fs._extensions._getFieldOrNull(fi)); + } + } + if (fs.hasUnknownFields) { + fs._unknownFields.writeToCodedBufferWriter(out); + } +} +void _mergeFromCodedBufferReader(_FieldSet fs, CodedBufferReader input_A, ExtensionRegistry registry) { + assert(registry != null); + void readPackableToList(int wireType, FieldInfo fi, Function readToList) { + List list_A = fs._ensureRepeatedField(fi); + if (wireType == WIRETYPE_LENGTH_DELIMITED) { + input_A._withLimit(input_A.readInt32(), () { + while (!input_A.isAtEnd()) { + readToList(list_A); } + }); + } else { + readToList(list_A); + } + } + void readPackable(int wireType, FieldInfo fi, Function readFunc) { + void readToList(List list_A) => list_A.add(readFunc()); + readPackableToList(wireType, fi, readToList); + } + while (true) { + int tag = input_A.readTag(); + if (tag == 0) return; + int wireType = tag & 0x7; + int tagNumber = tag >> 3; + FieldInfo fi = fs._nonExtensionInfo(tagNumber); + if (fi == null) { + fi = registry.getExtension(fs._messageName, tagNumber); + } + if (fi == null || !_wireTypeMatches(fi.type, wireType)) { + if (!fs._ensureUnknownFields().mergeFieldFromBuffer(tag, input_A)) { + return; } - }); - return invalidFields; + continue; + } + int fieldType = fi.type; + fieldType &= ~(PbFieldType._PACKED_BIT | PbFieldType._REQUIRED_BIT); + switch (fieldType) { + case PbFieldType._OPTIONAL_BOOL: + fs._setFieldUnchecked(fi, input_A.readBool()); + break; + + case PbFieldType._OPTIONAL_BYTES: + fs._setFieldUnchecked(fi, input_A.readBytes()); + break; + + case PbFieldType._OPTIONAL_STRING: + fs._setFieldUnchecked(fi, input_A.readString()); + break; + + case PbFieldType._OPTIONAL_FLOAT: + fs._setFieldUnchecked(fi, input_A.readFloat()); + break; + + case PbFieldType._OPTIONAL_DOUBLE: + fs._setFieldUnchecked(fi, input_A.readDouble()); + break; + + case PbFieldType._OPTIONAL_ENUM: + int rawValue = input_A.readEnum(); + var value_A = fs._meta._decodeEnum(tagNumber, registry, rawValue); + if (value_A == null) { + var unknown = fs._ensureUnknownFields(); + unknown.mergeVarintField(tagNumber, new Int64(rawValue)); + } else { + fs._setFieldUnchecked(fi, value_A); + } + break; + + case PbFieldType._OPTIONAL_GROUP: + GeneratedMessage subMessage = fs._meta._makeEmptyMessage(tagNumber, registry); + var oldValue = fs._getFieldOrNull(fi); + if (oldValue != null) { + subMessage.mergeFromMessage(oldValue); + } + input_A.readGroup(tagNumber, subMessage, registry); + fs._setFieldUnchecked(fi, subMessage); + break; + + case PbFieldType._OPTIONAL_INT32: + fs._setFieldUnchecked(fi, input_A.readInt32()); + break; + + case PbFieldType._OPTIONAL_INT64: + fs._setFieldUnchecked(fi, input_A.readInt64()); + break; + + case PbFieldType._OPTIONAL_SINT32: + fs._setFieldUnchecked(fi, input_A.readSint32()); + break; + + case PbFieldType._OPTIONAL_SINT64: + fs._setFieldUnchecked(fi, input_A.readSint64()); + break; + + case PbFieldType._OPTIONAL_UINT32: + fs._setFieldUnchecked(fi, input_A.readUint32()); + break; + + case PbFieldType._OPTIONAL_UINT64: + fs._setFieldUnchecked(fi, input_A.readUint64()); + break; + + case PbFieldType._OPTIONAL_FIXED32: + fs._setFieldUnchecked(fi, input_A.readFixed32()); + break; + + case PbFieldType._OPTIONAL_FIXED64: + fs._setFieldUnchecked(fi, input_A.readFixed64()); + break; + + case PbFieldType._OPTIONAL_SFIXED32: + fs._setFieldUnchecked(fi, input_A.readSfixed32()); + break; + + case PbFieldType._OPTIONAL_SFIXED64: + fs._setFieldUnchecked(fi, input_A.readSfixed64()); + break; + + case PbFieldType._OPTIONAL_MESSAGE: + GeneratedMessage subMessage = fs._meta._makeEmptyMessage(tagNumber, registry); + var oldValue = fs._getFieldOrNull(fi); + if (oldValue != null) { + subMessage.mergeFromMessage(oldValue); + } + input_A.readMessage(subMessage, registry); + fs._setFieldUnchecked(fi, subMessage); + break; + + case PbFieldType._REPEATED_BOOL: + readPackable(wireType, fi, input_A.readBool); + break; + + case PbFieldType._REPEATED_BYTES: + fs._ensureRepeatedField(fi).add(input_A.readBytes()); + break; + + case PbFieldType._REPEATED_STRING: + fs._ensureRepeatedField(fi).add(input_A.readString()); + break; + + case PbFieldType._REPEATED_FLOAT: + readPackable(wireType, fi, input_A.readFloat); + break; + + case PbFieldType._REPEATED_DOUBLE: + readPackable(wireType, fi, input_A.readDouble); + break; + + case PbFieldType._REPEATED_ENUM: + readPackableToList(wireType, fi, (List list_A) { + int rawValue = input_A.readEnum(); + var value_A = fs._meta._decodeEnum(tagNumber, registry, rawValue); + if (value_A == null) { + var unknown = fs._ensureUnknownFields(); + unknown.mergeVarintField(tagNumber, new Int64(rawValue)); + } else { + list_A.add(value_A); + } + }); + break; + + case PbFieldType._REPEATED_GROUP: + GeneratedMessage subMessage = fs._meta._makeEmptyMessage(tagNumber, registry); + input_A.readGroup(tagNumber, subMessage, registry); + fs._ensureRepeatedField(fi).add(subMessage); + break; + + case PbFieldType._REPEATED_INT32: + readPackable(wireType, fi, input_A.readInt32); + break; + + case PbFieldType._REPEATED_INT64: + readPackable(wireType, fi, input_A.readInt64); + break; + + case PbFieldType._REPEATED_SINT32: + readPackable(wireType, fi, input_A.readSint32); + break; + + case PbFieldType._REPEATED_SINT64: + readPackable(wireType, fi, input_A.readSint64); + break; + + case PbFieldType._REPEATED_UINT32: + readPackable(wireType, fi, input_A.readUint32); + break; + + case PbFieldType._REPEATED_UINT64: + readPackable(wireType, fi, input_A.readUint64); + break; + + case PbFieldType._REPEATED_FIXED32: + readPackable(wireType, fi, input_A.readFixed32); + break; + + case PbFieldType._REPEATED_FIXED64: + readPackable(wireType, fi, input_A.readFixed64); + break; + + case PbFieldType._REPEATED_SFIXED32: + readPackable(wireType, fi, input_A.readSfixed32); + break; + + case PbFieldType._REPEATED_SFIXED64: + readPackable(wireType, fi, input_A.readSfixed64); + break; + + case PbFieldType._REPEATED_MESSAGE: + GeneratedMessage subMessage = fs._meta._makeEmptyMessage(tagNumber, registry); + input_A.readMessage(subMessage, registry); + fs._ensureRepeatedField(fi).add(subMessage); + break; + + default: + throw 'Unknown field type ${fieldType}'; + } } } class CodedBufferReader { static const int DEFAULT_RECURSION_LIMIT = 64; static const int DEFAULT_SIZE_LIMIT = 64 << 20; - final Uint8List _buffer_A; + final Uint8List _buffer_B; int _bufferPos = 0; int _currentLimit = -1; int _lastTag = 0; int _recursionDepth = 0; final int _recursionLimit; final int _sizeLimit; - CodedBufferReader(List buffer_A, {int recursionLimit: DEFAULT_RECURSION_LIMIT, int sizeLimit: DEFAULT_SIZE_LIMIT}) : _buffer_A = buffer_A is Uint8List ? buffer_A : new Uint8List(buffer_A.length) + CodedBufferReader(List buffer_A, {int recursionLimit: DEFAULT_RECURSION_LIMIT, int sizeLimit: DEFAULT_SIZE_LIMIT}) : _buffer_B = buffer_A is Uint8List ? buffer_A : new Uint8List(buffer_A.length) ..setRange(0, buffer_A.length, buffer_A), _recursionLimit = recursionLimit, _sizeLimit = _A.min(sizeLimit, buffer_A.length) { _currentLimit = _sizeLimit; } @@ -1823,7 +2174,7 @@ class CodedBufferReader { List readBytes() { int length_A = readInt32(); _checkLimit(length_A); - return new Uint8List.view(_buffer_A.buffer, _buffer_A.offsetInBytes + _bufferPos - length_A, length_A); + return new Uint8List.view(_buffer_B.buffer, _buffer_B.offsetInBytes + _bufferPos - length_A, length_A); } String readString() => _UTF8.decode(readBytes()); double readFloat() => _readByteData(4).getFloat32(0, Endianness.LITTLE_ENDIAN); @@ -1849,14 +2200,14 @@ class CodedBufferReader { } int _readRawVarintByte() { _checkLimit(1); - return _buffer_A[_bufferPos - 1]; + return _buffer_B[_bufferPos - 1]; } int _readRawVarint32([bool signed = true]) { int bytes = _currentLimit - _bufferPos; if (bytes > 10) bytes = 10; int result_A = 0; for (int i = 0; i < bytes; i++) { - int byte = _buffer_A[_bufferPos++]; + int byte = _buffer_B[_bufferPos++]; result_A |= (byte & 0x7f) << (i * 7); if ((byte & 0x80) == 0) { result_A &= 0xffffffff; @@ -1888,7 +2239,7 @@ class CodedBufferReader { } ByteData _readByteData(int sizeInBytes) { _checkLimit(sizeInBytes); - return new ByteData.view(_buffer_A.buffer, _buffer_A.offsetInBytes + _bufferPos - sizeInBytes, sizeInBytes); + return new ByteData.view(_buffer_B.buffer, _buffer_B.offsetInBytes + _bufferPos - sizeInBytes, sizeInBytes); } } class CodedBufferWriter { @@ -2085,7 +2436,7 @@ misreported its own length. } class Extension extends FieldInfo { final String extendee; - Extension(this.extendee, String name_A, int tagNumber, int fieldType, [dynamic defaultOrMaker, CreateBuilderFunc subBuilder, ValueOfFunc valueOf_D]) : super(name_A, tagNumber, fieldType, defaultOrMaker, subBuilder, valueOf_D); + Extension(this.extendee, String name_A, int tagNumber, int fieldType, [dynamic defaultOrMaker, CreateBuilderFunc subBuilder, ValueOfFunc valueOf_D]) : super(name_A, tagNumber, null, fieldType, defaultOrMaker, subBuilder, valueOf_D); int get hashCode => extendee.hashCode * 31 + tagNumber; bool operator==(other) { if (other is! Extension) return false; @@ -2093,6 +2444,81 @@ class Extension extends FieldInfo { return extendee == o.extendee && tagNumber == o.tagNumber; } } +class _ExtensionFieldSet { + final _FieldSet _parent; + final Map _info = {}; + final Map _values_A = {}; + _ExtensionFieldSet(this._parent) { + assert(!_parent._isReadOnly); + } + Extension _getInfoOrNull(int tagNumber) => _info[tagNumber]; + _getFieldOrDefault(Extension fi) { + if (fi.isRepeated) return _ensureRepeatedField(fi); + _validateInfo(fi); + _addInfoUnchecked(fi); + var value_A = _getFieldOrNull(fi); + if (value_A == null) return fi.makeDefault(); + return value_A; + } + bool _hasField(int tagNumber) { + var value_A = _values_A[tagNumber]; + if (value_A == null) return false; + if (value_A is List) return value_A.isNotEmpty; + return true; + } + List _ensureRepeatedField(Extension fi) { + assert(fi.isRepeated); + assert(fi.extendee == _parent._messageName); + var list_A = _values_A[fi.tagNumber]; + if (list_A != null) return list_A; + _validateInfo(fi); + list_A = _parent._message.createRepeatedField(fi.tagNumber, fi); + _addInfoUnchecked(fi); + _setFieldUnchecked(fi, list_A); + return list_A; + } + _getFieldOrNull(Extension extension) => _values_A[extension.tagNumber]; + void _setField(int tagNumber, value_A) { + var fi = _getInfoOrNull(tagNumber); + if (fi == null) { + throw new ArgumentError("tag ${tagNumber} not defined in ${_parent}._messageName"); + } + if (fi.isRepeated) { + throw new ArgumentError(_parent._setFieldFailedMessage(fi, value_A, 'repeating field (use get + .add())')); + } + _parent._validateField_A(fi, value_A); + _setFieldUnchecked(fi, value_A); + } + void _setFieldAndInfo(Extension fi, value_A) { + if (fi.isRepeated) { + throw new ArgumentError(_parent._setFieldFailedMessage(fi, value_A, 'repeating field (use get + .add())')); + } + _validateInfo(fi); + _parent._validateField_A(fi, value_A); + _addInfoUnchecked(fi); + _setFieldUnchecked(fi, value_A); + } + void _validateInfo(Extension fi) { + if (fi.extendee != _parent._messageName) { + throw new ArgumentError('Extension ${fi} not legal for message ${_parent._messageName}'); + } + } + void _addInfoUnchecked(Extension fi) { + assert(fi.extendee == _parent._messageName); + _info[fi.tagNumber] = fi; + } + void _setFieldUnchecked(Extension fi, value_A) { + if (_parent._hasObservers) { + _parent._eventPlugin.beforeSetField(fi, value_A); + } + _values_A[fi.tagNumber] = value_A; + } + Iterable get _tagNumbers => _values_A.keys; + Iterable get _infos => _info.values; + get _hasValues => _values_A.isNotEmpty; + bool _equalValues(_ExtensionFieldSet other) => _areMapsEqual(_values_A, other._values_A); + void _clearValues() => _values_A.clear(); +} class ExtensionRegistry { final Map> _extensions = >{}; static const ExtensionRegistry EMPTY = const _EmptyExtensionRegistry(); @@ -2256,16 +2682,18 @@ bool _isFloat32(double value_A) => value_A.isNaN || value_A.isInfinite || _inRan class FieldInfo { final String name; final int tagNumber; + final int index; final int type; final MakeDefaultFunc makeDefault; final CreateBuilderFunc subBuilder; final ValueOfFunc valueOf_D; final CheckFunc check; - FieldInfo(this.name, this.tagNumber, int type_A, [dynamic defaultOrMaker, this.subBuilder, this.valueOf_D]) : this.type = type_A, this.makeDefault = findMakeDefault(type_A, defaultOrMaker), this.check = null { + FieldInfo(this.name, this.tagNumber, this.index, int type_A, [dynamic defaultOrMaker, this.subBuilder, this.valueOf_D]) : this.type = type_A, this.makeDefault = findMakeDefault(type_A, defaultOrMaker), this.check = null { + assert(type_A != 0); assert(!_isGroupOrMessage(type_A) || subBuilder != null); assert(!_isEnum(type_A) || valueOf_D != null); } - FieldInfo.repeated(this.name, this.tagNumber, int type_A, CheckFunc check_A, this.subBuilder, [this.valueOf_D]) : this.type = type_A, this.check = check_A, this.makeDefault = (() => new PbList(check: check_A)) { + FieldInfo.repeated(this.name, this.tagNumber, this.index, int type_A, CheckFunc check_A, this.subBuilder, [this.valueOf_D]) : this.type = type_A, this.check = check_A, this.makeDefault = (() => new PbList(check: check_A)) { assert(name != null); assert(tagNumber != null); assert(_isRepeated(type_A)); @@ -2277,9 +2705,339 @@ class FieldInfo { if (defaultOrMaker is MakeDefaultFunc) return defaultOrMaker; return () => defaultOrMaker; } + bool get isRequired => _isRequired(type); bool get isRepeated => _isRepeated(type); + get readonlyDefault { + if (isRepeated) return _emptyList; + return makeDefault(); + } + bool _hasRequiredValues(value_A) { + if (value_A == null) return !isRequired; + if (!_isGroupOrMessage(type)) return true; + if (!isRepeated) { + GeneratedMessage message_A = value_A; + return message_A._fieldSet._hasRequiredValues(); + } + List list_A = value_A; + if (list_A.isEmpty) return true; + if (!list_A[0]._fieldSet._hasRequiredFields) return true; + return list_A.every((GeneratedMessage m) => m._fieldSet._hasRequiredValues()); + } + void _appendInvalidFields(List problems, value_A, String prefix) { + if (value_A == null) { + if (isRequired) problems.add('${prefix}${name}'); + } else if (!_isGroupOrMessage(type)) {} else if (!isRepeated) { + GeneratedMessage message_A = value_A; + message_A._fieldSet._appendInvalidFields(problems, '${prefix}${name}.'); + } else { + List list_A = value_A; + if (list_A.isEmpty) return; + if (!list_A[0]._fieldSet._hasRequiredFields) return; + int position_A = 0; + for (GeneratedMessage message_A in list_A) { + message_A._fieldSet._appendInvalidFields(problems, '${prefix}${name}[${position_A}].'); + position_A++; + } + } + } String toString() => name; } +final _emptyList = new List.unmodifiable([]); +class _FieldSet { + final GeneratedMessage _message; + final BuilderInfo _meta; + final EventPlugin _eventPlugin; + final List _values_A; + _ExtensionFieldSet _extensions; + UnknownFieldSet _unknownFields; + _FieldSet(this._message, BuilderInfo meta, this._eventPlugin) : this._meta = meta, _values_A = _makeValueList(meta.fieldInfo); + static _makeValueList(Map infos) { + if (infos.isEmpty) return _emptyList; + return new List(infos.length); + } + String get _messageName => _meta.messageName; + bool get _isReadOnly => _message._isReadOnly; + bool get _hasRequiredFields => _meta.hasRequiredFields; + Iterable get _infos => _meta.fieldInfo.values; + Iterable get _infosSortedByTag => _meta.sortedByTag; + bool get _hasObservers => _eventPlugin != null && _eventPlugin.hasObservers; + bool get _hasExtensions => _extensions != null; + bool get hasUnknownFields => _unknownFields != null; + _ExtensionFieldSet _ensureExtensions() { + assert(!_isReadOnly); + if (!_hasExtensions) _extensions = new _ExtensionFieldSet(this); + return _extensions; + } + UnknownFieldSet _ensureUnknownFields() { + if (_isReadOnly) return _ReadonlyUnknownFieldSet._empty_A; + if (_unknownFields == null) _unknownFields = new UnknownFieldSet(); + return _unknownFields; + } + FieldInfo _nonExtensionInfo(int tagNumber) => _meta.fieldInfo[tagNumber]; + _getField(int tagNumber) { + var fi = _nonExtensionInfo(tagNumber); + if (fi != null) { + var value_A = _values_A[fi.index]; + if (value_A != null) return value_A; + return _getDefault(fi); + } + if (_hasExtensions) { + var fi = _extensions._getInfoOrNull(tagNumber); + if (fi != null) { + return _extensions._getFieldOrDefault(fi); + } + } + throw new ArgumentError("tag ${tagNumber} not defined in ${_messageName}"); + } + _getDefault(FieldInfo fi) { + if (!fi.isRepeated) return fi.makeDefault(); + if (_isReadOnly) return _emptyList; + var value_A = _message.createRepeatedField(fi.tagNumber, fi); + _setNonExtensionFieldUnchecked(fi, value_A); + return value_A; + } + _getFieldOrNull(FieldInfo fi) { + if (fi.index != null) return _values_A[fi.index]; + if (!_hasExtensions) return null; + return _extensions._getFieldOrNull(fi); + } + bool _hasField(int tagNumber) { + var fi = _nonExtensionInfo(tagNumber); + if (fi != null) return _$has(fi.index, tagNumber); + if (!_hasExtensions) return false; + return _extensions._hasField(tagNumber); + } + void _setField(int tagNumber, value_A) { + if (value_A == null) throw new ArgumentError('value is null'); + var fi = _nonExtensionInfo(tagNumber); + if (fi == null) { + if (!_hasExtensions) { + throw new ArgumentError("tag ${tagNumber} not defined in ${_messageName}"); + } + _extensions._setField(tagNumber, value_A); + return; + } + if (fi.isRepeated) { + throw new ArgumentError(_setFieldFailedMessage(fi, value_A, 'repeating field (use get + .add())')); + } + _validateField_A(fi, value_A); + _setNonExtensionFieldUnchecked(fi, value_A); + } + void _setFieldUnchecked(FieldInfo fi, value_A) { + assert(fi != null); + assert(!fi.isRepeated); + if (fi.index == null) { + _ensureExtensions() + .._addInfoUnchecked(fi) + .._setFieldUnchecked(fi, value_A); + } else { + _setNonExtensionFieldUnchecked(fi, value_A); + } + } + List _ensureRepeatedField(FieldInfo fi) { + assert(!_isReadOnly); + assert(fi.isRepeated); + if (fi.index == null) { + return _ensureExtensions()._ensureRepeatedField(fi); + } + var value_A = _getFieldOrNull(fi); + if (value_A != null) return value_A; + value_A = _message.createRepeatedField(fi.tagNumber, fi); + _setNonExtensionFieldUnchecked(fi, value_A); + return value_A; + } + void _setNonExtensionFieldUnchecked(FieldInfo fi, value_A) { + if (_hasObservers) { + _eventPlugin.beforeSetField(fi, value_A); + } + _values_A[fi.index] = value_A; + } + bool _$has(int index_A, int tagNumber) { + assert(_nonExtensionInfo(tagNumber).index == index_A); + var value_A = _values_A[index_A]; + if (value_A == null) return false; + if (value_A is List) return value_A.isNotEmpty; + return true; + } + void _clear_A() { + if (_unknownFields != null) { + _unknownFields.clear(); + } + if (_hasObservers) { + for (var fi in _infos) { + if (_values_A[fi.index] != null) { + _eventPlugin.beforeClearField(fi); + } + } + if (_hasExtensions) { + for (int key_A in _extensions._tagNumbers) { + var fi = _extensions._getInfoOrNull(key_A); + _eventPlugin.beforeClearField(fi); + } + } + } + if (_values_A.isNotEmpty) _values_A.fillRange(0, _values_A.length, null); + if (_hasExtensions) _extensions._clearValues(); + } + bool _equals_A(_FieldSet o) { + if (_meta != o._meta) return false; + if (!_areListsEqual(_values_A, o._values_A)) return false; + if (!_hasExtensions || !_extensions._hasValues) { + if (o._hasExtensions && o._extensions._hasValues) { + return false; + } + } else { + if (!_extensions._equalValues(o._extensions)) return false; + } + if (_unknownFields == null || _unknownFields.isEmpty) { + if (o._unknownFields != null && o._unknownFields.isNotEmpty) return false; + } else { + if (_unknownFields != o._unknownFields) return false; + } + return true; + } + int get _hashCode { + int hash; + void hashEnumList(PbList enums) { + enums.forEach((ProtobufEnum enm) { + hash = (31 * hash + enm.value) & 0x3fffffff; + }); + } + void hashField(FieldInfo fi, value_A) { + if (value_A is List && value_A.isEmpty) { + return; + } + hash = ((37 * hash) + fi.tagNumber) & 0x3fffffff; + if (!_isEnum(fi.type)) { + hash = ((53 * hash) + (value_A as Object).hashCode) & 0x3fffffff; + } else if (fi.isRepeated) { + hashEnumList(value_A); + } else { + ProtobufEnum enm = value_A; + hash = ((53 * hash) + enm.value) & 0x3fffffff; + } + } + void hashEachField() { + for (var fi in _infosSortedByTag) { + var v = _values_A[fi.index]; + if (v != null) hashField(fi, v); + } + if (!_hasExtensions) return; + for (int tagNumber in sorted(_extensions._tagNumbers)) { + var fi = _extensions._getInfoOrNull(tagNumber); + hashField(fi, _extensions._getFieldOrNull(fi)); + } + } + hash = 41; + hash = ((19 * hash) + _meta.hashCode) & 0x3fffffff; + hashEachField(); + if (hasUnknownFields) { + hash = ((29 * hash) + _unknownFields.hashCode) & 0x3fffffff; + } + return hash; + } + void writeString(StringBuffer out, String indent_A) { + void renderValue(key_A, value_A) { + if (value_A is GeneratedMessage) { + out.write('${indent_A}${key_A}: {\n'); + value_A._fieldSet.writeString(out, '${indent_A} '); + out.write('${indent_A}}\n'); + } else { + out.write('${indent_A}${key_A}: ${value_A}\n'); + } + } + for (FieldInfo fi in _infosSortedByTag) { + var fieldValue = _values_A[fi.index]; + if (fieldValue == null) continue; + if (fieldValue is ByteData) { + final value_A = fieldValue.getUint64(0, Endianness.LITTLE_ENDIAN); + renderValue(fi.name, value_A); + } else if (fieldValue is List) { + for (var value_A in fieldValue) { + renderValue(fi.name, value_A); + } + } else { + renderValue(fi.name, fieldValue); + } + } + if (hasUnknownFields) { + out.write(_unknownFields.toString()); + } else { + out.write(new UnknownFieldSet().toString()); + } + } + void _mergeFromMessage(_FieldSet other) { + void mergeField(FieldInfo otherFi, fieldValue) { + int tagNumber = otherFi.tagNumber; + var fi = _nonExtensionInfo(tagNumber); + if (fi == null && otherFi is Extension) { + fi = otherFi; + } + var cloner = (x_A) => x_A; + if (_isGroupOrMessage(otherFi.type)) { + cloner = (message_A) => message_A.clone(); + } + if (fi.isRepeated) { + _ensureRepeatedField(fi).addAll(new List.from(fieldValue).map(cloner)); + return; + } + fieldValue = cloner(fieldValue); + if (fi.index == null) { + _ensureExtensions()._setFieldAndInfo(fi, fieldValue); + } else { + _validateField_A(fi, fieldValue); + _setNonExtensionFieldUnchecked(fi, fieldValue); + } + } + for (var fi in other._infos) { + var value_A = other._values_A[fi.index]; + if (value_A != null) mergeField(fi, value_A); + } + if (other._hasExtensions) { + var others = other._extensions; + for (int tagNumber in others._tagNumbers) { + var extension = others._getInfoOrNull(tagNumber); + var value_A = others._getFieldOrNull(extension); + mergeField(extension, value_A); + } + } + if (other.hasUnknownFields) { + _ensureUnknownFields().mergeFromUnknownFieldSet(other._unknownFields); + } + } + void _validateField_A(FieldInfo fi, var newValue) { + var message_A = _getFieldError(fi.type, newValue); + if (message_A != null) { + throw new ArgumentError(_setFieldFailedMessage(fi, newValue, message_A)); + } + } + String _setFieldFailedMessage(FieldInfo fi, var value_A, String detail) { + return 'Illegal to set field ${fi.name} (${fi.tagNumber}) of ${_messageName}' ' to value (${value_A}): ${detail}'; + } + bool _hasRequiredValues() { + if (!_hasRequiredFields) return true; + for (var fi in _infos) { + var value_A = _values_A[fi.index]; + if (!fi._hasRequiredValues(value_A)) return false; + } + return _hasRequiredExtensionValues(); + } + bool _hasRequiredExtensionValues() { + if (!_hasExtensions) return true; + for (var fi in _extensions._infos) { + var value_A = _extensions._getFieldOrNull(fi); + if (!fi._hasRequiredValues(value_A)) return false; + } + return true; + } + void _appendInvalidFields(List problems, String prefix) { + if (!_hasRequiredFields) return; + for (var fi in _infos) { + var value_A = _values_A[fi.index]; + fi._appendInvalidFields(problems, value_A, prefix); + } + } +} bool _isRepeated(int fieldType) => (fieldType & PbFieldType._REPEATED_BIT) != 0; bool _isRequired(int fieldType) => (fieldType & PbFieldType._REQUIRED_BIT) != 0; bool _isEnum(int fieldType) => PbFieldType._baseType(fieldType) == PbFieldType._ENUM_BIT; @@ -2387,7 +3145,7 @@ class PbFieldType { static const int _PACKED_INT32 = _REPEATED_BIT | _PACKED_BIT | _INT32_BIT; static const int OB = _OPTIONAL_BOOL; static const int OY = _OPTIONAL_BYTES; - static const int OS_A = _OPTIONAL_STRING; + static const int OS = _OPTIONAL_STRING; static const int OD = _OPTIONAL_DOUBLE; static const int OE = _OPTIONAL_ENUM; static const int O3 = _OPTIONAL_INT32; @@ -2405,433 +3163,59 @@ typedef GeneratedMessage CreateBuilderFunc(); typedef Object MakeDefaultFunc(); typedef ProtobufEnum ValueOfFunc(int _0); abstract class GeneratedMessage { - static const int OS = PbFieldType._OPTIONAL_STRING; - static Int64 MAX_JSON_INT = new Int64.fromInts(0x200000, 0); - static Int64 MIN_JSON_INT = -MAX_JSON_INT; - final Map _fieldValues = new Map(); - final Map _extensions = new Map(); - final UnknownFieldSet unknownFields = new UnknownFieldSet(); + _FieldSet _fieldSet; GeneratedMessage() { + _fieldSet = new _FieldSet(this, info_, eventPlugin); if (eventPlugin != null) eventPlugin.attach(this); } GeneratedMessage.fromBuffer_A(List input_A, ExtensionRegistry extensionRegistry) { + _fieldSet = new _FieldSet(this, info_, eventPlugin); if (eventPlugin != null) eventPlugin.attach(this); mergeFromBuffer(input_A, extensionRegistry); } + BuilderInfo get info_; EventPlugin get eventPlugin => null; - bool get _hasObservers => eventPlugin != null && eventPlugin.hasObservers; + bool get _isReadOnly => false; bool hasRequiredFields() => info_.hasRequiredFields; - bool isInitialized() { - if (!info_.hasRequiredFields) { - return true; - } - return info_.isInitialized(_fieldValues) && extensionsAreInitialized(); - } - void _findInvalidFields(List invalidFields, String prefix) { - info_._findInvalidFields(_fieldValues, invalidFields, prefix); - } - void clear() { - unknownFields.clear(); - if (_hasObservers) { - for (int key_A in _fieldValues.keys) { - var fi = _ensureFieldInfo(key_A); - eventPlugin.beforeClearField(fi); - } - } - _fieldValues.clear(); - } + bool isInitialized() => _fieldSet._hasRequiredValues(); + void clear() => _fieldSet._clear_A(); bool operator==(other) { if (other is! GeneratedMessage) return false; - GeneratedMessage o = other; - if (o.info_ != info_) return false; - if (!_areMapsEqual(o._fieldValues, _fieldValues)) return false; - if (o.unknownFields != unknownFields) return false; - return true; + return _fieldSet._equals_A(other._fieldSet); } - int get hashCode { - int hash; - void hashEnumList(PbList enums) { - enums.forEach((ProtobufEnum enm) { - hash = (31 * hash + enm.value) & 0x3fffffff; - }); - } - void hashFields() { - for (int tagNumber in sorted(_fieldValues.keys)) { - var value_A = _fieldValues[tagNumber]; - if (value_A is List && value_A.isEmpty) { - continue; - } - hash = ((37 * hash) + tagNumber) & 0x3fffffff; - var fi = _ensureFieldInfo(tagNumber); - if (!_isEnum(fi.type)) { - hash = ((53 * hash) + (value_A as Object).hashCode) & 0x3fffffff; - } else if (fi.isRepeated) { - hashEnumList(value_A); - } else { - ProtobufEnum enm = value_A; - hash = ((53 * hash) + enm.value) & 0x3fffffff; - } - } - } - hash = 41; - hash = ((19 * hash) + info_.hashCode) & 0x3fffffff; - hashFields(); - hash = ((29 * hash) + unknownFields.hashCode) & 0x3fffffff; - return hash; - } - String toString() => _toString(''); - String _toString(String indent_A) { - StringBuffer s = new StringBuffer(); - void renderValue(key_A, value_A) { - if (value_A is GeneratedMessage) { - s.write('${indent_A}${key_A}: {\n'); - s.write(value_A._toString('${indent_A} ')); - s.write('${indent_A}}\n'); - } else { - s.write('${indent_A}${key_A}: ${value_A}\n'); - } - } - List fields = new List.from(info_.fieldInfo.values) - ..sort((a, b) => a.tagNumber.compareTo(b.tagNumber)); - for (FieldInfo field in fields) { - if (hasField(field.tagNumber)) { - var fieldValue = _fieldValues[field.tagNumber]; - if (fieldValue is ByteData) { - final value_A = fieldValue.getUint64(0, Endianness.LITTLE_ENDIAN); - renderValue(field.name, value_A); - } else if (fieldValue is List) { - for (var value_A in fieldValue) { - renderValue(field.name, value_A); - } - } else { - renderValue(field.name, fieldValue); - } - } - } - s.write(unknownFields.toString()); - return s.toString(); + int get hashCode => _fieldSet._hashCode; + String toString() { + var out = new StringBuffer(); + _fieldSet.writeString(out, ''); + return out.toString(); } void check() { if (!isInitialized()) { List invalidFields = []; - info_._findInvalidFields(_fieldValues, invalidFields); + _fieldSet._appendInvalidFields(invalidFields, ""); String missingFields = (invalidFields ..sort()).join(', '); throw new StateError('Message missing required fields: ${missingFields}'); } } - BuilderInfo get info_; Uint8List writeToBuffer() { CodedBufferWriter out = new CodedBufferWriter(); writeToCodedBufferWriter(out); return out.toBuffer(); } - void writeToCodedBufferWriter(CodedBufferWriter output) { - for (int tagNumber in sorted(_fieldValues.keys)) { - var value_A = _fieldValues[tagNumber]; - var fi = _ensureFieldInfo(tagNumber); - output.writeField(tagNumber, fi.type, value_A); - } - unknownFields.writeToCodedBufferWriter(output); - } - void mergeFromCodedBufferReader(CodedBufferReader input_A, [ExtensionRegistry extensionRegistry = ExtensionRegistry.EMPTY]) { - void appendToRepeated(tagNumber, value_A) { - List list_A = getField(tagNumber); - list_A.add(value_A); - } - void readPackableToList(int wireType, int tagNumber, Function readToList) { - List list_A = getField(tagNumber); - if (wireType == WIRETYPE_LENGTH_DELIMITED) { - input_A._withLimit(input_A.readInt32(), () { - while (!input_A.isAtEnd()) { - readToList(list_A); - } - }); - } else { - readToList(list_A); - } - } - void readPackable(int wireType, int tagNumber, Function readFunc) { - void readToList(List list_A) => list_A.add(readFunc()); - readPackableToList(wireType, tagNumber, readToList); - } - while (true) { - int tag = input_A.readTag(); - if (tag == 0) { - return; - } - int wireType = tag & 0x7; - int tagNumber = tag >> 3; - FieldInfo fi = info_.fieldInfo[tagNumber]; - if (fi == null) { - fi = extensionRegistry.getExtension(info_.messageName, tagNumber); - if (fi != null) { - _addExtensionToMap(fi); - } - } - if (fi == null || !_wireTypeMatches(fi.type, wireType)) { - if (!unknownFields.mergeFieldFromBuffer(tag, input_A)) { - return; - } - continue; - } - int fieldType = fi.type; - fieldType &= ~(PbFieldType._PACKED_BIT | PbFieldType._REQUIRED_BIT); - switch (fieldType) { - case PbFieldType._OPTIONAL_BOOL: - _setField(fi, input_A.readBool()); - break; - - case PbFieldType._OPTIONAL_BYTES: - _setField(fi, input_A.readBytes()); - break; - - case PbFieldType._OPTIONAL_STRING: - _setField(fi, input_A.readString()); - break; - - case PbFieldType._OPTIONAL_FLOAT: - _setField(fi, input_A.readFloat()); - break; - - case PbFieldType._OPTIONAL_DOUBLE: - _setField(fi, input_A.readDouble()); - break; - - case PbFieldType._OPTIONAL_ENUM: - int rawValue = input_A.readEnum(); - var value_A = _getValueOfFunc(tagNumber, extensionRegistry)(rawValue); - if (value_A == null) { - unknownFields.mergeVarintField(tagNumber, new Int64(rawValue)); - } else { - _setField(fi, value_A); - } - break; - - case PbFieldType._OPTIONAL_GROUP: - GeneratedMessage subMessage = _getEmptyMessage(tagNumber, extensionRegistry); - if (_fieldValues.containsKey(tagNumber)) { - subMessage.mergeFromMessage(getField(tagNumber)); - } - input_A.readGroup(tagNumber, subMessage, extensionRegistry); - _setField(fi, subMessage); - break; - - case PbFieldType._OPTIONAL_INT32: - _setField(fi, input_A.readInt32()); - break; - - case PbFieldType._OPTIONAL_INT64: - _setField(fi, input_A.readInt64()); - break; - - case PbFieldType._OPTIONAL_SINT32: - _setField(fi, input_A.readSint32()); - break; - - case PbFieldType._OPTIONAL_SINT64: - _setField(fi, input_A.readSint64()); - break; - - case PbFieldType._OPTIONAL_UINT32: - _setField(fi, input_A.readUint32()); - break; - - case PbFieldType._OPTIONAL_UINT64: - _setField(fi, input_A.readUint64()); - break; - - case PbFieldType._OPTIONAL_FIXED32: - _setField(fi, input_A.readFixed32()); - break; - - case PbFieldType._OPTIONAL_FIXED64: - _setField(fi, input_A.readFixed64()); - break; - - case PbFieldType._OPTIONAL_SFIXED32: - _setField(fi, input_A.readSfixed32()); - break; - - case PbFieldType._OPTIONAL_SFIXED64: - _setField(fi, input_A.readSfixed64()); - break; - - case PbFieldType._OPTIONAL_MESSAGE: - GeneratedMessage subMessage = _getEmptyMessage(tagNumber, extensionRegistry); - if (_fieldValues.containsKey(tagNumber)) { - subMessage.mergeFromMessage(getField(tagNumber)); - } - input_A.readMessage(subMessage, extensionRegistry); - _setField(fi, subMessage); - break; - - case PbFieldType._REPEATED_BOOL: - readPackable(wireType, tagNumber, input_A.readBool); - break; - - case PbFieldType._REPEATED_BYTES: - appendToRepeated(tagNumber, input_A.readBytes()); - break; - - case PbFieldType._REPEATED_STRING: - appendToRepeated(tagNumber, input_A.readString()); - break; - - case PbFieldType._REPEATED_FLOAT: - readPackable(wireType, tagNumber, input_A.readFloat); - break; - - case PbFieldType._REPEATED_DOUBLE: - readPackable(wireType, tagNumber, input_A.readDouble); - break; - - case PbFieldType._REPEATED_ENUM: - readPackableToList(wireType, tagNumber, (List list_A) { - int rawValue = input_A.readEnum(); - var value_A = _getValueOfFunc(tagNumber, extensionRegistry)(rawValue); - if (value_A == null) { - unknownFields.mergeVarintField(tagNumber, new Int64(rawValue)); - } else { - list_A.add(value_A); - } - }); - break; - - case PbFieldType._REPEATED_GROUP: - GeneratedMessage subMessage = _getEmptyMessage(tagNumber, extensionRegistry); - input_A.readGroup(tagNumber, subMessage, extensionRegistry); - appendToRepeated(tagNumber, subMessage); - break; - - case PbFieldType._REPEATED_INT32: - readPackable(wireType, tagNumber, input_A.readInt32); - break; - - case PbFieldType._REPEATED_INT64: - readPackable(wireType, tagNumber, input_A.readInt64); - break; - - case PbFieldType._REPEATED_SINT32: - readPackable(wireType, tagNumber, input_A.readSint32); - break; - - case PbFieldType._REPEATED_SINT64: - readPackable(wireType, tagNumber, input_A.readSint64); - break; - - case PbFieldType._REPEATED_UINT32: - readPackable(wireType, tagNumber, input_A.readUint32); - break; - - case PbFieldType._REPEATED_UINT64: - readPackable(wireType, tagNumber, input_A.readUint64); - break; - - case PbFieldType._REPEATED_FIXED32: - readPackable(wireType, tagNumber, input_A.readFixed32); - break; - - case PbFieldType._REPEATED_FIXED64: - readPackable(wireType, tagNumber, input_A.readFixed64); - break; - - case PbFieldType._REPEATED_SFIXED32: - readPackable(wireType, tagNumber, input_A.readSfixed32); - break; - - case PbFieldType._REPEATED_SFIXED64: - readPackable(wireType, tagNumber, input_A.readSfixed64); - break; - - case PbFieldType._REPEATED_MESSAGE: - GeneratedMessage subMessage = _getEmptyMessage(tagNumber, extensionRegistry); - input_A.readMessage(subMessage, extensionRegistry); - appendToRepeated(tagNumber, subMessage); - break; - - default: - throw 'Unknown field type ${fieldType}'; - } - } - } + void writeToCodedBufferWriter(CodedBufferWriter output) => _writeToCodedBufferWriter(_fieldSet, output); + void mergeFromCodedBufferReader(CodedBufferReader input_A, [ExtensionRegistry extensionRegistry = ExtensionRegistry.EMPTY]) => _mergeFromCodedBufferReader(_fieldSet, input_A, extensionRegistry); void mergeFromBuffer(List input_A, [ExtensionRegistry extensionRegistry = ExtensionRegistry.EMPTY]) { CodedBufferReader codedInput = new CodedBufferReader(input_A); - mergeFromCodedBufferReader(codedInput, extensionRegistry); + _mergeFromCodedBufferReader(_fieldSet, codedInput, extensionRegistry); codedInput.checkLastTagWas(0); } - Map writeToJsonMap() { - convertToMap(fieldValue, fieldType) { - int baseType = PbFieldType._baseType(fieldType); - if (_isRepeated(fieldType)) { - return new List.from(fieldValue.map((e) => convertToMap(e, baseType))); - } - switch (baseType) { - case PbFieldType._BOOL_BIT: case PbFieldType._STRING_BIT: case PbFieldType._FLOAT_BIT: case PbFieldType._DOUBLE_BIT: case PbFieldType._INT32_BIT: case PbFieldType._SINT32_BIT: case PbFieldType._UINT32_BIT: case PbFieldType._FIXED32_BIT: case PbFieldType._SFIXED32_BIT: - return fieldValue; - - case PbFieldType._BYTES_BIT: - return CryptoUtils.bytesToBase64_A(fieldValue); - - case PbFieldType._ENUM_BIT: - return fieldValue.value; - - case PbFieldType._INT64_BIT: case PbFieldType._SINT64_BIT: case PbFieldType._UINT64_BIT: case PbFieldType._FIXED64_BIT: case PbFieldType._SFIXED64_BIT: - if (MIN_JSON_INT <= fieldValue && fieldValue <= MAX_JSON_INT) { - return fieldValue.toInt(); - } - return fieldValue.toString(); - - case PbFieldType._GROUP_BIT: case PbFieldType._MESSAGE_BIT: - return fieldValue.writeToJsonMap(); - - default: - throw 'Unknown type ${fieldType}'; - } - } - var result_A = {}; - for (int tagNumber in sorted(_fieldValues.keys)) { - var value_A = _fieldValues[tagNumber]; - if (value_A is List && value_A.isEmpty) { - continue; - } - var fi = _ensureFieldInfo(tagNumber); - result_A['${tagNumber}'] = convertToMap(value_A, fi.type); - } - return result_A; - } - bool extensionsAreInitialized() { - return _extensions.keys.every((int tagNumber) { - return info_._isFieldInitialized(_fieldValues, tagNumber, _extensions[tagNumber].type); - }); - } + Map writeToJsonMap() => _writeToJsonMap(_fieldSet); getExtension(Extension extension) { - _checkExtension(extension); - _addExtensionToMap(extension); - return getField(extension.tagNumber); - } - getField(int tagNumber) { - var value_A = _fieldValues[tagNumber]; - if (value_A != null) return value_A; - var fi = _ensureFieldInfo(tagNumber); - if (fi.isRepeated) { - return _getDefaultRepeatedField(tagNumber, fi); - } else { - return fi.makeDefault(); - } - } - FieldInfo _ensureFieldInfo(int tagNumber) { - var fi = info_.fieldInfo[tagNumber]; - if (fi != null) return fi; - fi = _extensions[tagNumber]; - if (fi != null) return fi; - throw new ArgumentError("tag ${tagNumber} not defined in ${info_.messageName}"); - } - List _getDefaultRepeatedField(int tagNumber, FieldInfo fi) { - var value_A = createRepeatedField(tagNumber, fi); - _setField(fi, value_A); - return value_A; + if (_isReadOnly) return extension.readonlyDefault; + return _fieldSet._ensureExtensions()._getFieldOrDefault(extension); } + getField(int tagNumber) => _fieldSet._getField(tagNumber); List createRepeatedField(int tagNumber, FieldInfo fi) { if (fi.check != null) { return new PbList(check: fi.check); @@ -2839,103 +3223,61 @@ abstract class GeneratedMessage { return fi.makeDefault(); } } - bool hasExtension(Extension extension) { - _checkExtension(extension); - return hasField(extension.tagNumber); - } - bool hasField(int tagNumber) { - if (!_fieldValues.containsKey(tagNumber)) { - return false; + bool hasExtension(Extension extension) => _fieldSet._hasExtensions && _fieldSet._extensions._getFieldOrNull(extension) != null; + bool hasField(int tagNumber) => _fieldSet._hasField(tagNumber); + void mergeFromMessage(GeneratedMessage other) => _fieldSet._mergeFromMessage(other._fieldSet); + void setField(int tagNumber, value_A) => _fieldSet._setField(tagNumber, value_A); +} +Int64 _MAX_JSON_INT = new Int64.fromInts(0x200000, 0); +Int64 _MIN_JSON_INT = -_MAX_JSON_INT; +Map _writeToJsonMap(_FieldSet fs) { + convertToMap(fieldValue, fieldType) { + int baseType = PbFieldType._baseType(fieldType); + if (_isRepeated(fieldType)) { + return new List.from(fieldValue.map((e) => convertToMap(e, baseType))); } - var value_A = _fieldValues[tagNumber]; - if (value_A is List && value_A.isEmpty) { - return false; - } - return true; - } - void mergeFromMessage(GeneratedMessage other) { - for (int tagNumber in other._fieldValues.keys) { - var fieldValue = other._fieldValues[tagNumber]; - var fi = info_.fieldInfo[tagNumber]; - if (fi == null) { - fi = other._extensions[tagNumber]; - if (fi != null) { - _checkExtension(fi); - _addExtensionToMap(fi); + switch (baseType) { + case PbFieldType._BOOL_BIT: case PbFieldType._STRING_BIT: case PbFieldType._FLOAT_BIT: case PbFieldType._DOUBLE_BIT: case PbFieldType._INT32_BIT: case PbFieldType._SINT32_BIT: case PbFieldType._UINT32_BIT: case PbFieldType._FIXED32_BIT: case PbFieldType._SFIXED32_BIT: + return fieldValue; + + case PbFieldType._BYTES_BIT: + return CryptoUtils.bytesToBase64_A(fieldValue); + + case PbFieldType._ENUM_BIT: + return fieldValue.value; + + case PbFieldType._INT64_BIT: case PbFieldType._SINT64_BIT: case PbFieldType._UINT64_BIT: case PbFieldType._FIXED64_BIT: case PbFieldType._SFIXED64_BIT: + if (_MIN_JSON_INT <= fieldValue && fieldValue <= _MAX_JSON_INT) { + return fieldValue.toInt(); } + return fieldValue.toString(); + + case PbFieldType._GROUP_BIT: case PbFieldType._MESSAGE_BIT: + return fieldValue.writeToJsonMap(); + + default: + throw 'Unknown type ${fieldType}'; + } + } + var result_A = {}; + for (var fi in fs._infosSortedByTag) { + var value_A = fs._values_A[fi.index]; + if (value_A == null || (value_A is List && value_A.isEmpty)) { + continue; + } + result_A['${fi.tagNumber}'] = convertToMap(value_A, fi.type); + } + if (fs._hasExtensions) { + for (int tagNumber in sorted(fs._extensions._tagNumbers)) { + var value_A = fs._extensions._values_A[tagNumber]; + if (value_A is List && value_A.isEmpty) { + continue; } - var otherType = other._ensureFieldInfo(tagNumber).type; - var cloner = (x_A) => x_A; - if (_isGroupOrMessage(otherType)) { - cloner = (message_A) => message_A.clone(); - } - if (fi.isRepeated) { - getField(tagNumber).addAll(new List.from(fieldValue).map(cloner)); - } else { - fieldValue = cloner(fieldValue); - _validate_A(tagNumber, fi.type, fieldValue); - _setField(fi, fieldValue); - } - } - mergeUnknownFields(other.unknownFields); - } - void mergeUnknownFields(UnknownFieldSet unknownFieldSet) { - unknownFields.mergeFromUnknownFieldSet(unknownFieldSet); - } - void setField(int tagNumber, value_A) { - if (value_A == null) throw new ArgumentError('value is null'); - var fi = _ensureFieldInfo(tagNumber); - if (fi.isRepeated) { - throw new ArgumentError(_generateMessage(tagNumber, value_A, 'repeating field (use get + .add())')); - } - _validate_A(tagNumber, fi.type, value_A); - _setField(fi, value_A); - } - void _setField(FieldInfo fi, value_A) { - assert(fi != null); - if (_hasObservers) { - eventPlugin.beforeSetField(fi, value_A); - } - _fieldValues[fi.tagNumber] = value_A; - } - void _addExtensionToMap(Extension extension) { - _extensions[extension.tagNumber] = extension; - } - void _checkExtension(Extension extension) { - if (extension.extendee != info_.messageName) { - throw new ArgumentError('Extension ${extension} not legal for message ${info_.messageName}'); - } - } - GeneratedMessage _getEmptyMessage(int tagNumber, ExtensionRegistry extensionRegistry) { - CreateBuilderFunc subBuilderFunc = info_.subBuilder(tagNumber); - if (subBuilderFunc == null && extensionRegistry != null) { - subBuilderFunc = extensionRegistry.getExtension(info_.messageName, tagNumber).subBuilder; - } - return subBuilderFunc(); - } - ValueOfFunc _getValueOfFunc(int tagNumber, ExtensionRegistry extensionRegistry) { - ValueOfFunc valueOfFunc = info_.valueOfFunc(tagNumber); - if (valueOfFunc == null && extensionRegistry != null) { - valueOfFunc = extensionRegistry.getExtension(info_.messageName, tagNumber).valueOf_D; - } - return valueOfFunc; - } - String _generateMessage(int tagNumber, var value_A, String detail) { - String fieldName; - if (_extensions[tagNumber] != null) { - fieldName = _extensions[tagNumber].name; - } else { - fieldName = info_.fieldName(tagNumber); - } - String messageType_A = info_.messageName; - return 'Illegal to set field ${fieldName} (${tagNumber}) of ${messageType_A}' ' to value (${value_A}): ${detail}'; - } - void _validate_A(int tagNumber, int fieldType, var value_A) { - var message_A = _getFieldError(fieldType, value_A); - if (message_A != null) { - throw new ArgumentError(_generateMessage(tagNumber, value_A, message_A)); + var fi = fs._extensions._getInfoOrNull(tagNumber); + result_A['${tagNumber}'] = convertToMap(value_A, fi.type); } } + return result_A; } typedef dynamic CheckFunc(_0); class PbList extends Object with ListMixin implements List { @@ -3015,17 +3357,14 @@ class ProtobufEnum { int get hashCode => value; String toString() => name; } -final _emptyList = new List.unmodifiable([]); abstract class ReadonlyMessageMixin { - static final _emptyUnknownFields = new _ReadonlyUnknownFieldSet(); BuilderInfo get info_; - get unknownFields => _emptyUnknownFields; - List _getDefaultRepeatedField(int tagNumber, FieldInfo fi) => _emptyList; + get _isReadOnly => true; void clear() => _readonly("clear"); + createRepeatedField(int tagNumber, FieldInfo fi) => _readonly("createRepeatedField"); void mergeFromBuffer(List input_A, [ExtensionRegistry extensionRegistry = ExtensionRegistry.EMPTY]) => _readonly("mergeFromBuffer"); void mergeFromCodedBufferReader(CodedBufferReader input_A, [ExtensionRegistry extensionRegistry = ExtensionRegistry.EMPTY]) => _readonly("mergeFromCodedBufferReader"); void mergeFromMessage(GeneratedMessage other) => _readonly("mergeFromMessage"); - void mergeUnknownFields(UnknownFieldSet unknownFieldSet) => _readonly("mergeUnknownFields"); void setField(int tagNumber, var value_A, [int fieldType = null]) => _readonly("setField"); void _readonly(String methodName) { String messageType_A = info_.messageName; @@ -3033,6 +3372,7 @@ abstract class ReadonlyMessageMixin { } } class _ReadonlyUnknownFieldSet extends UnknownFieldSet { + static final _empty_A = new _ReadonlyUnknownFieldSet(); void clear() => _readonly("clear"); void mergeField(int number, UnknownFieldSetField field) => _readonly("mergeField"); bool mergeFieldFromBuffer(int tag, CodedBufferReader input_A) { @@ -3056,6 +3396,8 @@ class UnknownFieldSet { mergeFromUnknownFieldSet(unknownFieldSet); } UnknownFieldSet clone() => new UnknownFieldSet._clone_A(this); + bool get isEmpty => _fields.isEmpty; + bool get isNotEmpty => _fields.isNotEmpty; Map asMap() => new Map.from(_fields); void clear() { _fields.clear(); @@ -3151,8 +3493,8 @@ class UnknownFieldSet { }); return hash; } - String toString() => _toString(''); - String _toString(String indent_A) { + String toString() => _toString_A(''); + String _toString_A(String indent_A) { var stringBuffer = new StringBuffer(); for (int tag in sorted(_fields.keys)) { var field = _fields[tag]; @@ -3160,7 +3502,7 @@ class UnknownFieldSet { if (value_A is UnknownFieldSet) { stringBuffer ..write('${indent_A}${tag}: {\n') - ..write(value_A._toString('${indent_A} ')) + ..write(value_A._toString_A('${indent_A} ')) ..write('${indent_A}}\n'); } else { if (value_A is ByteData) { @@ -3307,7 +3649,7 @@ bool _wireTypeMatches(int fieldType, int wireType) { return false; } } -const List GeneratedMessage_reservedNames = const['hashCode', 'noSuchMethod', 'runtimeType', 'toString', 'fromBuffer', 'fromJson', 'hasRequiredFields', 'isInitialized', 'clear', 'getTagNumber', 'check', 'writeToBuffer', 'writeToCodedBufferWriter', 'mergeFromCodedBufferReader', 'mergeFromBuffer', 'writeToJson', 'mergeFromJson', 'writeToJsonMap', 'mergeFromJsonMap', 'addExtension', 'getExtension', 'setExtension', 'hasExtension', 'clearExtension', 'getField', 'getFieldOrNull', 'getDefaultForField', 'setField', 'hasField', 'clearField', 'extensionsAreInitialized', 'mergeFromMessage', 'mergeUnknownFields', '==', 'info_', 'GeneratedMessage', 'Object', 'eventPlugin', 'createRepeatedField']; +const List GeneratedMessage_reservedNames = const['hashCode', 'noSuchMethod', 'runtimeType', 'toString', 'fromBuffer', 'fromJson', 'hasRequiredFields', 'isInitialized', 'clear', 'getTagNumber', 'check', 'writeToBuffer', 'writeToCodedBufferWriter', 'mergeFromCodedBufferReader', 'mergeFromBuffer', 'writeToJson', 'mergeFromJson', 'writeToJsonMap', 'mergeFromJsonMap', 'addExtension', 'getExtension', 'setExtension', 'hasExtension', 'clearExtension', 'getField', 'getFieldOrNull', 'getDefaultForField', 'setField', 'hasField', 'clearField', 'extensionsAreInitialized', 'mergeFromMessage', 'mergeUnknownFields', '==', 'info_', 'GeneratedMessage', 'Object', 'eventPlugin', 'createRepeatedField', 'unknownFields', r'$_get', r'$_has', r'$_setBool', r'$_setBytes', r'$_setString', r'$_setFloat', r'$_setDouble', r'$_setSignedInt32', r'$_setUnsignedInt32', r'$_setInt64']; PbMixin findMixin(String name_A) { for (var m in _exportedMixins) { if (m.name == name_A) { @@ -3349,8 +3691,9 @@ class BaseType { final FieldDescriptorProto_Type descriptor; final String unprefixed; final String typeConstantSuffix; + final String setter; final ProtobufContainer generator; - const BaseType._raw_A(this.descriptor, this.typeConstantSuffix, this.unprefixed, this.generator); + const BaseType._raw_A(this.descriptor, this.typeConstantSuffix, this.unprefixed, this.setter, this.generator); bool get isGroup => descriptor == FieldDescriptorProto_Type.TYPE_GROUP; bool get isMessage => descriptor == FieldDescriptorProto_Type.TYPE_MESSAGE; bool get isEnum => descriptor == FieldDescriptorProto_Type.TYPE_ENUM; @@ -3367,49 +3710,49 @@ class BaseType { String constSuffix; switch (field.type) { case FieldDescriptorProto_Type.TYPE_BOOL: - return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_BOOL, "B", "bool", null); + return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_BOOL, "B", "bool", r"$_setBool", null); case FieldDescriptorProto_Type.TYPE_FLOAT: - return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_FLOAT, "F", "double", null); + return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_FLOAT, "F", "double", r"$_setFloat", null); case FieldDescriptorProto_Type.TYPE_DOUBLE: - return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_DOUBLE, "D", "double", null); + return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_DOUBLE, "D", "double", r"$_setDouble", null); case FieldDescriptorProto_Type.TYPE_INT32: - return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_INT32, "3", "int", null); + return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_INT32, "3", "int", r"$_setUnsignedInt32", null); case FieldDescriptorProto_Type.TYPE_UINT32: - return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_UINT32, "U3", "int", null); + return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_UINT32, "U3", "int", r"$_setUnsignedInt32", null); case FieldDescriptorProto_Type.TYPE_SINT32: - return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_SINT32, "S3", "int", null); + return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_SINT32, "S3", "int", r"$_setSignedInt32", null); case FieldDescriptorProto_Type.TYPE_FIXED32: - return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_FIXED32, "F3", "int", null); + return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_FIXED32, "F3", "int", r"$_setUnsignedInt32", null); case FieldDescriptorProto_Type.TYPE_SFIXED32: - return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_SFIXED32, "SF3", "int", null); + return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_SFIXED32, "SF3", "int", r"$_setSignedInt32", null); case FieldDescriptorProto_Type.TYPE_INT64: - return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_INT64, "6", "Int64", null); + return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_INT64, "6", "Int64", r"$_setInt64", null); case FieldDescriptorProto_Type.TYPE_UINT64: - return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_UINT64, "U6", "Int64", null); + return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_UINT64, "U6", "Int64", r"$_setInt64", null); case FieldDescriptorProto_Type.TYPE_SINT64: - return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_SINT64, "S6", "Int64", null); + return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_SINT64, "S6", "Int64", r"$_setInt64", null); case FieldDescriptorProto_Type.TYPE_FIXED64: - return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_FIXED64, "F6", "Int64", null); + return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_FIXED64, "F6", "Int64", r"$_setInt64", null); case FieldDescriptorProto_Type.TYPE_SFIXED64: - return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_SFIXED64, "SF6", "Int64", null); + return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_SFIXED64, "SF6", "Int64", r"$_setInt64", null); case FieldDescriptorProto_Type.TYPE_STRING: - return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_STRING, "S", "String", null); + return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_STRING, "S", "String", r"$_setString", null); case FieldDescriptorProto_Type.TYPE_BYTES: - return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_BYTES, "Y", "List", null); + return const BaseType._raw_A(FieldDescriptorProto_Type.TYPE_BYTES, "Y", "List", r"$_setBytes", null); case FieldDescriptorProto_Type.TYPE_GROUP: constSuffix = "G"; @@ -3430,7 +3773,7 @@ class BaseType { if (generator_A == null) { throw 'FAILURE: Unknown type reference ${field.typeName}'; } - return new BaseType._raw_A(field.type, constSuffix, generator_A.classname, generator_A); + return new BaseType._raw_A(field.type, constSuffix, generator_A.classname, null, generator_A); } } class ClientApiGenerator { @@ -3493,7 +3836,7 @@ class CodeGenerator extends ProtobufContainer { for (var gen in generators) { var name_A = gen._fileDescriptor.name; if (request.fileToGenerate.contains(name_A)) { - response_A.file_A.add(gen.generateResponse(config)); + response_A.file.add(gen.generateResponse(config)); } } _streamOut.add(response_A.writeToBuffer()); @@ -3510,13 +3853,13 @@ class EnumAlias { EnumAlias(this.value, this.canonicalValue); } class EnumGenerator extends ProtobufContainer { - final ProtobufContainer _parent; + final ProtobufContainer _parent_A; final String classname; final String fqname; final EnumDescriptorProto _descriptor; final List _canonicalValues = []; final List _aliases = []; - EnumGenerator(EnumDescriptorProto descriptor, ProtobufContainer parent_A) : _parent = parent_A, classname = (parent_A == null || parent_A is FileGenerator) ? descriptor.name : '${parent_A.classname}_${descriptor.name}', fqname = (parent_A == null || parent_A.fqname == null) ? descriptor.name : (parent_A.fqname == '.' ? '.${descriptor.name}' : '${parent_A.fqname}.${descriptor.name}'), _descriptor = descriptor { + EnumGenerator(EnumDescriptorProto descriptor, ProtobufContainer parent_A) : _parent_A = parent_A, classname = (parent_A == null || parent_A is FileGenerator) ? descriptor.name : '${parent_A.classname}_${descriptor.name}', fqname = (parent_A == null || parent_A.fqname == null) ? descriptor.name : (parent_A.fqname == '.' ? '.${descriptor.name}' : '${parent_A.fqname}.${descriptor.name}'), _descriptor = descriptor { for (EnumValueDescriptorProto value_A in descriptor.value) { EnumValueDescriptorProto canonicalValue = descriptor.value.firstWhere((v) => v.number == value_A.number); if (value_A == canonicalValue) { @@ -3526,9 +3869,9 @@ class EnumGenerator extends ProtobufContainer { } } } - String get package => _parent.package; - FileGenerator get fileGen => _parent.fileGen; - void register(GenerationContext ctx) { + String get package => _parent_A.package; + FileGenerator get fileGen => _parent_A.fileGen; + void register_A(GenerationContext ctx) { ctx.registerFieldType(fqname, this); } String getJsonConstant(FileGenerator usage) { @@ -3576,23 +3919,23 @@ class EnumGenerator extends ProtobufContainer { } class ExtensionGenerator { final FieldDescriptorProto _descriptor; - final ProtobufContainer _parent; + final ProtobufContainer _parent_A; ProtobufField _field; String _extendedClassName = ""; - ExtensionGenerator(this._descriptor, this._parent); + ExtensionGenerator(this._descriptor, this._parent_A); void resolve(GenerationContext ctx) { - _field = new ProtobufField(_descriptor, _parent, ctx); + _field = new ProtobufField(_descriptor, null, _parent_A, ctx); ProtobufContainer extendedType = ctx.getFieldType(_descriptor.extendee); if (extendedType != null) { _extendedClassName = extendedType.classname; } } - String get package => _parent.package; - FileGenerator get fileGen => _parent.fileGen; + String get package => _parent_A.package; + FileGenerator get fileGen => _parent_A.fileGen; String get name { if (_field == null) throw new StateError("resolve not called"); String name_A = _field.dartFieldName; - return _parent is MessageGenerator ? '${_parent.classname}.${name_A}' : name_A; + return _parent_A is MessageGenerator ? '${_parent_A.classname}.${name_A}' : name_A; } bool get needsFixnumImport { if (_field == null) throw new StateError("resolve not called"); @@ -3837,10 +4180,10 @@ void link(GenerationOptions options, Iterable files) { for (var f in files) { ctx.registerProtoFile(f); for (var m in f.messageGenerators) { - m.register(ctx); + m.register_A(ctx); } for (var e in f.enumGenerators) { - e.register(ctx); + e.register_A(ctx); } } for (var f in files) { @@ -3854,11 +4197,11 @@ void link(GenerationOptions options, Iterable files) { } class GenerationContext { final GenerationOptions options; - final Map _files_A = {}; + final Map _files = {}; final Map _typeRegistry = {}; GenerationContext(this.options); void registerProtoFile(FileGenerator f) { - _files_A[f._fileDescriptor.name] = f; + _files[f._fileDescriptor.name] = f; } void registerFieldType(String name_A, ProtobufContainer type_A) { _typeRegistry[name_A] = type_A; @@ -3883,14 +4226,14 @@ class MessageGenerator extends ProtobufContainer { final String classname; final String fqname; final PbMixin mixin_A; - final ProtobufContainer _parent; + final ProtobufContainer _parent_A; final DescriptorProto _descriptor; final List _enumGenerators = []; final List _messageGenerators = []; final List _extensionGenerators = []; List _fieldList; final Set _methodNames = new Set(); - MessageGenerator(DescriptorProto descriptor, ProtobufContainer parent_A, PbMixin defaultMixin_A) : _descriptor = descriptor, _parent = parent_A, classname = (parent_A.classname == '') ? descriptor.name : '${parent_A.classname}_${descriptor.name}', fqname = (parent_A == null || parent_A.fqname == null) ? descriptor.name : (parent_A.fqname == '.' ? '.${descriptor.name}' : '${parent_A.fqname}.${descriptor.name}'), mixin_A = _getMixin(descriptor, defaultMixin_A) { + MessageGenerator(DescriptorProto descriptor, ProtobufContainer parent_A, PbMixin defaultMixin_A) : _descriptor = descriptor, _parent_A = parent_A, classname = (parent_A.classname == '') ? descriptor.name : '${parent_A.classname}_${descriptor.name}', fqname = (parent_A == null || parent_A.fqname == null) ? descriptor.name : (parent_A.fqname == '.' ? '.${descriptor.name}' : '${parent_A.fqname}.${descriptor.name}'), mixin_A = _getMixin(descriptor, defaultMixin_A) { for (EnumDescriptorProto e in _descriptor.enumType) { _enumGenerators.add(new EnumGenerator(e, this)); } @@ -3901,8 +4244,8 @@ class MessageGenerator extends ProtobufContainer { _extensionGenerators.add(new ExtensionGenerator(x_A, this)); } } - String get package => _parent.package; - FileGenerator get fileGen => _parent.fileGen; + String get package => _parent_A.package; + FileGenerator get fileGen => _parent_A.fileGen; void checkResolved() { if (_fieldList == null) { throw new StateError("message not resolved: ${fqname}"); @@ -3923,20 +4266,27 @@ class MessageGenerator extends ProtobufContainer { m.addMixinsTo(output); } } - void register(GenerationContext ctx) { + void register_A(GenerationContext ctx) { ctx.registerFieldType(fqname, this); for (var m in _messageGenerators) { - m.register(ctx); + m.register_A(ctx); } for (var e in _enumGenerators) { - e.register(ctx); + e.register_A(ctx); } } void resolve(GenerationContext ctx) { if (_fieldList != null) throw new StateError("message already resolved"); + var sorted_A = new List.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}"; + }); _fieldList = []; - for (FieldDescriptorProto field in _descriptor.field) { - _fieldList.add(new ProtobufField(field, this, ctx)); + for (FieldDescriptorProto field in sorted_A) { + int index_A = _fieldList.length; + _fieldList.add(new ProtobufField(field, index_A, this, ctx)); } for (var m in _messageGenerators) { m.resolve(ctx); @@ -4001,7 +4351,7 @@ class MessageGenerator extends ProtobufContainer { if (_descriptor.extensionRange.length > 0) { out.println('..hasExtensions = true'); } - if (!_hasRequiredFields(this, new Set())) { + if (!_hasRequiredFields_A(this, new Set())) { out.println('..hasRequiredFields = false'); } }); @@ -4030,7 +4380,7 @@ class MessageGenerator extends ProtobufContainer { out.println('class _Readonly${classname} extends ${classname} with ReadonlyMessageMixin {}'); out.println(); } - bool _hasRequiredFields(MessageGenerator type_A, Set alreadySeen) { + bool _hasRequiredFields_A(MessageGenerator type_A, Set alreadySeen) { if (type_A._fieldList == null) throw new StateError("message not resolved"); if (alreadySeen.contains(type_A.fqname)) { return false; @@ -4045,7 +4395,7 @@ class MessageGenerator extends ProtobufContainer { } if (field.baseType.isMessage) { MessageGenerator child = field.baseType.generator; - if (_hasRequiredFields(child, alreadySeen)) { + if (_hasRequiredFields_A(child, alreadySeen)) { return true; } } @@ -4074,10 +4424,16 @@ class MessageGenerator extends ProtobufContainer { _methodNames.add(identifier); } var fieldTypeString = field.getDartType(package); - out.println('${fieldTypeString} get ${identifier}' ' => getField(${field.number});'); + var defaultExpr = field.getDefaultExpr(); + out.println('${fieldTypeString} get ${identifier}' ' => \$_get(${field.index}, ${field.number}, ${defaultExpr});'); if (!field.isRepeated) { - out.println('void set ${identifier}' '(${fieldTypeString} v) ' '{ setField(${field.number}, v); }'); - out.println('bool ${hasIdentifier}() =>' ' hasField(${field.number});'); + var fastSetter = field.baseType.setter; + if (fastSetter != null) { + out.println('void set ${identifier}' '(${fieldTypeString} v) { ' '${fastSetter}(${field.index}, ${field.number}, v);' ' }'); + } else { + out.println('void set ${identifier}' '(${fieldTypeString} v) { ' 'setField(${field.number}, v);' ' }'); + } + out.println('bool ${hasIdentifier}() =>' ' \$_has(${field.index}, ${field.number});'); out.println('void ${clearIdentifier}() =>' ' clearField(${field.number});'); } } @@ -4205,10 +4561,11 @@ class ProtobufField { static final RegExp DECIMAL_LITERAL_REGEX_A = new RegExp(r'^[+-]?([0-9]*)\.[0-9]+(e[+-]?[0-9]+)?$', multiLine: false, caseSensitive: false); static final RegExp DECIMAL_LITERAL_REGEX_B = new RegExp(r'^[+-]?[0-9]+e[+-]?[0-9]+$', multiLine: false, caseSensitive: false); final FieldDescriptorProto _field; + final int index; final String fqname; final BaseType baseType; final GenerationOptions _genOptions; - ProtobufField(FieldDescriptorProto field, ProtobufContainer parent_A, GenerationContext ctx) : _field = field, fqname = '${parent_A.fqname}.${field.name}', baseType = new BaseType(field, ctx), _genOptions = ctx.options; + ProtobufField(FieldDescriptorProto field, this.index, ProtobufContainer parent_A, GenerationContext ctx) : _field = field, fqname = '${parent_A.fqname}.${field.name}', baseType = new BaseType(field, ctx), _genOptions = ctx.options; int get number => _field.number; bool get isRequired => _field.label == FieldDescriptorProto_Label.LABEL_REQUIRED; bool get isRepeated => _field.label == FieldDescriptorProto_Label.LABEL_REPEATED; @@ -4275,6 +4632,22 @@ class ProtobufField { } return prefix + ', ${makeDefault})'; } + 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"; + } + } String generateDefaultFunction(String package) { if (isRepeated) { return '() => new PbList()'; @@ -4282,10 +4655,7 @@ class ProtobufField { bool samePackage = package == baseType.package; switch (_field.type) { case FieldDescriptorProto_Type.TYPE_BOOL: - if (_field.hasDefaultValue() && 'false' != _field.defaultValue) { - return '${_field.defaultValue}'; - } - return null; + return _getDefaultAsBoolExpr(null); case FieldDescriptorProto_Type.TYPE_FLOAT: case FieldDescriptorProto_Type.TYPE_DOUBLE: if (!_field.hasDefaultValue()) { @@ -4308,10 +4678,7 @@ class ProtobufField { throw _invalidDefaultValue; 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: - if (_field.hasDefaultValue() && '0' != _field.defaultValue) { - return '${_field.defaultValue}'; - } - return null; + return _getDefaultAsInt32Expr(null); case FieldDescriptorProto_Type.TYPE_INT64: case FieldDescriptorProto_Type.TYPE_UINT64: case FieldDescriptorProto_Type.TYPE_SINT64: case FieldDescriptorProto_Type.TYPE_FIXED64: case FieldDescriptorProto_Type.TYPE_SFIXED64: var value_A = '0'; @@ -4320,11 +4687,7 @@ class ProtobufField { return "parseLongInt('${value_A}')"; case FieldDescriptorProto_Type.TYPE_STRING: - if (!_field.hasDefaultValue() || _field.defaultValue.isEmpty) { - return null; - } - String value_A = _field.defaultValue.replaceAll(r'$', r'\$'); - return '\'${value_A}\''; + return _getDefaultAsStringExpr(null); case FieldDescriptorProto_Type.TYPE_BYTES: if (!_field.hasDefaultValue() || _field.defaultValue.isEmpty) { @@ -4351,6 +4714,25 @@ class ProtobufField { throw _typeNotImplemented("generatedDefaultFunction"); } } + String _getDefaultAsBoolExpr(String noDefault) { + if (_field.hasDefaultValue() && 'false' != _field.defaultValue) { + return '${_field.defaultValue}'; + } + return noDefault; + } + String _getDefaultAsStringExpr(String noDefault) { + if (!_field.hasDefaultValue() || _field.defaultValue.isEmpty) { + return noDefault; + } + String value_A = _field.defaultValue.replaceAll(r'$', r'\$'); + return '\'${value_A}\''; + } + String _getDefaultAsInt32Expr(String noDefault) { + if (_field.hasDefaultValue() && '0' != _field.defaultValue) { + return '${_field.defaultValue}'; + } + return noDefault; + } get _invalidDefaultValue => "dart-protoc-plugin:" " invalid default value (${_field.defaultValue})" " found in field ${fqname}"; _typeNotImplemented(String methodName) => "dart-protoc-plugin:" " ${methodName} not implemented for type (${_field.type})" " found in field ${fqname}"; } @@ -4576,7 +4958,7 @@ void _writeMapItems(IndentingWriter out, Map val, {bool vertica } } class IndentingWriter { - final StringBuffer _buffer_B = new StringBuffer(); + final StringBuffer _buffer_C = new StringBuffer(); String _indent_A = ""; bool _needIndent = true; void print(String text) { @@ -4613,18 +4995,18 @@ class IndentingWriter { print(end_A); } } - String toString() => _buffer_B.toString(); + String toString() => _buffer_C.toString(); void _writeChunk(String chunk) { assert(!chunk.contains('\n')); if (chunk.isEmpty) return; if (_needIndent) { - _buffer_B.write(_indent_A); + _buffer_C.write(_indent_A); _needIndent = false; } - _buffer_B.write(chunk); + _buffer_C.write(chunk); } void _newline() { - _buffer_B.writeln(); + _buffer_C.writeln(); _needIndent = true; } }