diff --git a/protobuf/lib/src/protobuf/extension_field_set.dart b/protobuf/lib/src/protobuf/extension_field_set.dart index 5b7e1c92e..cad43e9ed 100644 --- a/protobuf/lib/src/protobuf/extension_field_set.dart +++ b/protobuf/lib/src/protobuf/extension_field_set.dart @@ -6,11 +6,20 @@ part of protobuf; class _ExtensionFieldSet { final _FieldSet _parent; - final Map _info = {}; - final Map _values = {}; - bool _isReadOnly = false; - _ExtensionFieldSet(this._parent); + final Map _info; + + final Map _values; + + bool _isReadOnly; + + _ExtensionFieldSet(this._parent) + : _info = {}, + _values = {}, + _isReadOnly = false; + + _ExtensionFieldSet._( + this._parent, this._info, this._values, this._isReadOnly); Extension? _getInfoOrNull(int tagNumber) => _info[tagNumber]; @@ -203,4 +212,66 @@ class _ExtensionFieldSet { 'use `ExtensionRegistry.reparseMessage`.'); } } + + _ExtensionFieldSet deepCopy(_FieldSet parent, {bool freeze = false}) { + final values = {}; + + for (final entry in _values.entries) { + final key = entry.key; + final value = entry.value; + final fieldInfo = _info[key]!; + + if (fieldInfo.isRepeated) { + final repeated = fieldInfo._createRepeatedField(parent._message!); + values[key] = repeated; + + if (_isGroupOrMessage(fieldInfo.type)) { + final List listValue = value; + for (final message in listValue) { + repeated.add(message.deepCopy()); + } + // repeated.addAll(listValue.map((message) => message.deepCopy())); + } else { + final List listValue = value; + repeated.addAll(listValue); + } + + continue; + } + + if (fieldInfo.isMapField) { + final MapFieldInfo mapFieldInfo = + fieldInfo as dynamic; + final map = mapFieldInfo._createMapField(parent._message!); + values[key] = map; + + if (_isGroupOrMessage(mapFieldInfo.valueFieldType)) { + Map mapValue = value; + for (final entry in mapValue.entries) { + map[entry.key] = entry.value.deepCopy(); + } + } else { + Map mapValue = value; + map.addAll(mapValue); + } + + continue; + } + + if (fieldInfo.isGroupOrMessage) { + final GeneratedMessage messageValue = value; + values[key] = messageValue.deepCopy(freeze: freeze); + continue; + } + + values[key] = value; + } + + return _ExtensionFieldSet._( + parent, + _info, + values, + freeze, + ); + } } diff --git a/protobuf/lib/src/protobuf/field_set.dart b/protobuf/lib/src/protobuf/field_set.dart index ed8394e57..c80258142 100644 --- a/protobuf/lib/src/protobuf/field_set.dart +++ b/protobuf/lib/src/protobuf/field_set.dart @@ -78,6 +78,9 @@ class _FieldSet { : _values = _makeValueList(meta.byIndex.length), _oneofCases = meta.oneofs.isEmpty ? null : {}; + _FieldSet._(this._message, this._eventPlugin, this._values, this._extensions, + this._unknownFields, this._frozenState, this._oneofCases); + static List _makeValueList(int length) { if (length == 0) return _zeroList; return List.filled(length, null, growable: false); @@ -905,4 +908,79 @@ class _FieldSet { _oneofCases?.addAll(original._oneofCases!); } + + _FieldSet deepCopy(GeneratedMessage message, EventPlugin? eventPlugin, + {bool freeze = false}) { + final values = _makeValueList(_values.length); + final meta = _meta; + + for (var valueIdx = 0; valueIdx < _values.length; valueIdx += 1) { + final value = _values[valueIdx]; + + if (value == null) { + continue; + } + + final fieldInfo = meta.byIndex[valueIdx]; + + if (fieldInfo.isRepeated) { + final repeated = fieldInfo._createRepeatedField(message); + values[valueIdx] = repeated; + + if (_isGroupOrMessage(fieldInfo.type)) { + final List listValue = value; + for (final message in listValue) { + repeated.add(message.deepCopy()); + } + // repeated.addAll(listValue.map((message) => message.deepCopy())); + } else { + final List listValue = value; + repeated.addAll(listValue); + } + + continue; + } + + if (fieldInfo.isMapField) { + final MapFieldInfo mapFieldInfo = + fieldInfo as dynamic; + final map = mapFieldInfo._createMapField(message); + values[valueIdx] = map; + + if (_isGroupOrMessage(mapFieldInfo.valueFieldType)) { + Map mapValue = value; + for (final entry in mapValue.entries) { + map[entry.key] = entry.value.deepCopy(); + } + } else { + Map mapValue = value; + map.addAll(mapValue); + } + + continue; + } + + if (fieldInfo.isGroupOrMessage) { + final GeneratedMessage messageValue = value; + values[valueIdx] = messageValue.deepCopy(freeze: freeze); + continue; + } + + values[valueIdx] = value; + } + + final copy = _FieldSet._( + message, + eventPlugin, + values, + null, + _unknownFields?.deepCopy(freeze: freeze), + freeze, // TODO: Can we use `_frozenState` here? + _oneofCases == null ? null : Map.from(_oneofCases!), + ); + + copy._extensions = _extensions?.deepCopy(copy, freeze: freeze); + + return copy; + } } diff --git a/protobuf/lib/src/protobuf/generated_message.dart b/protobuf/lib/src/protobuf/generated_message.dart index c77a17e2e..b47b28c8a 100644 --- a/protobuf/lib/src/protobuf/generated_message.dart +++ b/protobuf/lib/src/protobuf/generated_message.dart @@ -578,5 +578,11 @@ extension GeneratedMessageGenericExtensions on T { } /// Returns a writable deep copy of this message. - T deepCopy() => info_.createEmptyInstance!() as T..mergeFromMessage(this); + T deepCopy({bool freeze = false}) { + final T message = info_.createEmptyInstance!() as dynamic; + final eventPlugin = message.eventPlugin; + message.__fieldSet = + __fieldSet?.deepCopy(message, eventPlugin, freeze: freeze); + return message; + } } diff --git a/protobuf/lib/src/protobuf/pb_list.dart b/protobuf/lib/src/protobuf/pb_list.dart index 3c17c4791..e13480590 100644 --- a/protobuf/lib/src/protobuf/pb_list.dart +++ b/protobuf/lib/src/protobuf/pb_list.dart @@ -14,13 +14,14 @@ class PbList extends ListBase { final List _wrappedList; final CheckFunc _check; - bool _isReadOnly = false; + bool _isReadOnly; bool get isFrozen => _isReadOnly; PbList({CheckFunc check = _checkNotNull}) : _wrappedList = [], - _check = check; + _check = check, + _isReadOnly = false; PbList.unmodifiable() : _wrappedList = const [], @@ -29,7 +30,8 @@ class PbList extends ListBase { PbList.from(List from) : _wrappedList = List.from(from), - _check = _checkNotNull; + _check = _checkNotNull, + _isReadOnly = false; @override void add(E element) { diff --git a/protobuf/lib/src/protobuf/unknown_field_set.dart b/protobuf/lib/src/protobuf/unknown_field_set.dart index 5e000581f..95433f83d 100644 --- a/protobuf/lib/src/protobuf/unknown_field_set.dart +++ b/protobuf/lib/src/protobuf/unknown_field_set.dart @@ -8,11 +8,15 @@ part of protobuf; class UnknownFieldSet { static final UnknownFieldSet emptyUnknownFieldSet = UnknownFieldSet() .._markReadOnly(); - final Map _fields = {}; - UnknownFieldSet(); + final Map _fields; - UnknownFieldSet._clone(UnknownFieldSet unknownFieldSet) { + UnknownFieldSet() : _fields = {}; + + UnknownFieldSet._(this._fields, this._isReadOnly); + + UnknownFieldSet._clone(UnknownFieldSet unknownFieldSet) + : _fields = {} { mergeFromUnknownFieldSet(unknownFieldSet); } @@ -195,15 +199,37 @@ class UnknownFieldSet { _throwFrozenMessageModificationError('UnknownFieldSet', methodName); } } + + UnknownFieldSet deepCopy({bool freeze = false}) { + final fields = {}; + + for (final entry in _fields.entries) { + final key = entry.key; + final value = entry.value; + fields[key] = value.deepCopy(freeze: freeze); + } + + return UnknownFieldSet._(fields, freeze); + } } /// An unknown field in a [UnknownFieldSet]. class UnknownFieldSetField { - List> _lengthDelimited = >[]; - List _varints = []; - List _fixed32s = []; - List _fixed64s = []; - List _groups = []; + List> _lengthDelimited; + List _varints; + List _fixed32s; + List _fixed64s; + List _groups; + + UnknownFieldSetField() + : _lengthDelimited = >[], + _varints = [], + _fixed32s = [], + _fixed64s = [], + _groups = []; + + UnknownFieldSetField._(this._lengthDelimited, this._varints, this._fixed32s, + this._fixed64s, this._groups); List> get lengthDelimited => _lengthDelimited; List get varints => _varints; @@ -309,4 +335,14 @@ class UnknownFieldSetField { void addVarint(Int64 value) { varints.add(value); } + + UnknownFieldSetField deepCopy({bool freeze = false}) { + return UnknownFieldSetField._( + _lengthDelimited.map((List e) => List.from(e)).toList(), + List.from(_varints), + List.from(_fixed32s), + List.from(_fixed64s), + List.from(_groups.map((e) => e.deepCopy(freeze: freeze))), + ); + } } diff --git a/protoc_plugin/lib/src/generated/dart_options.pb.dart b/protoc_plugin/lib/src/generated/dart_options.pb.dart index b69d0f042..f895e4801 100644 --- a/protoc_plugin/lib/src/generated/dart_options.pb.dart +++ b/protoc_plugin/lib/src/generated/dart_options.pb.dart @@ -47,7 +47,7 @@ class DartMixin extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - DartMixin clone() => DartMixin()..mergeFromMessage(this); + DartMixin clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -131,7 +131,7 @@ class Imports extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - Imports clone() => Imports()..mergeFromMessage(this); + Imports clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') diff --git a/protoc_plugin/lib/src/generated/descriptor.pb.dart b/protoc_plugin/lib/src/generated/descriptor.pb.dart index f1afdbafe..ebee2c2e9 100644 --- a/protoc_plugin/lib/src/generated/descriptor.pb.dart +++ b/protoc_plugin/lib/src/generated/descriptor.pb.dart @@ -43,7 +43,7 @@ class FileDescriptorSet extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - FileDescriptorSet clone() => FileDescriptorSet()..mergeFromMessage(this); + FileDescriptorSet clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -159,7 +159,7 @@ class FileDescriptorProto extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - FileDescriptorProto clone() => FileDescriptorProto()..mergeFromMessage(this); + FileDescriptorProto clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -303,8 +303,7 @@ class DescriptorProto_ExtensionRange extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - DescriptorProto_ExtensionRange clone() => - DescriptorProto_ExtensionRange()..mergeFromMessage(this); + DescriptorProto_ExtensionRange clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -399,8 +398,7 @@ class DescriptorProto_ReservedRange extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - DescriptorProto_ReservedRange clone() => - DescriptorProto_ReservedRange()..mergeFromMessage(this); + DescriptorProto_ReservedRange clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -533,7 +531,7 @@ class DescriptorProto extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - DescriptorProto clone() => DescriptorProto()..mergeFromMessage(this); + DescriptorProto clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -632,8 +630,7 @@ class ExtensionRangeOptions extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - ExtensionRangeOptions clone() => - ExtensionRangeOptions()..mergeFromMessage(this); + ExtensionRangeOptions clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -744,8 +741,7 @@ class FieldDescriptorProto extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - FieldDescriptorProto clone() => - FieldDescriptorProto()..mergeFromMessage(this); + FieldDescriptorProto clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -931,8 +927,7 @@ class OneofDescriptorProto extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - OneofDescriptorProto clone() => - OneofDescriptorProto()..mergeFromMessage(this); + OneofDescriptorProto clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -1013,8 +1008,7 @@ class EnumDescriptorProto_EnumReservedRange extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - EnumDescriptorProto_EnumReservedRange clone() => - EnumDescriptorProto_EnumReservedRange()..mergeFromMessage(this); + EnumDescriptorProto_EnumReservedRange clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -1113,7 +1107,7 @@ class EnumDescriptorProto extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - EnumDescriptorProto clone() => EnumDescriptorProto()..mergeFromMessage(this); + EnumDescriptorProto clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -1207,8 +1201,7 @@ class EnumValueDescriptorProto extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - EnumValueDescriptorProto clone() => - EnumValueDescriptorProto()..mergeFromMessage(this); + EnumValueDescriptorProto clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -1306,8 +1299,7 @@ class ServiceDescriptorProto extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - ServiceDescriptorProto clone() => - ServiceDescriptorProto()..mergeFromMessage(this); + ServiceDescriptorProto clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -1409,8 +1401,7 @@ class MethodDescriptorProto extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - MethodDescriptorProto clone() => - MethodDescriptorProto()..mergeFromMessage(this); + MethodDescriptorProto clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -1640,7 +1631,7 @@ class FileOptions extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - FileOptions clone() => FileOptions()..mergeFromMessage(this); + FileOptions clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -1955,7 +1946,7 @@ class MessageOptions extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - MessageOptions clone() => MessageOptions()..mergeFromMessage(this); + MessageOptions clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -2093,7 +2084,7 @@ class FieldOptions extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - FieldOptions clone() => FieldOptions()..mergeFromMessage(this); + FieldOptions clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -2217,7 +2208,7 @@ class OneofOptions extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - OneofOptions clone() => OneofOptions()..mergeFromMessage(this); + OneofOptions clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -2279,7 +2270,7 @@ class EnumOptions extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - EnumOptions clone() => EnumOptions()..mergeFromMessage(this); + EnumOptions clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -2359,7 +2350,7 @@ class EnumValueOptions extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - EnumValueOptions clone() => EnumValueOptions()..mergeFromMessage(this); + EnumValueOptions clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -2428,7 +2419,7 @@ class ServiceOptions extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - ServiceOptions clone() => ServiceOptions()..mergeFromMessage(this); + ServiceOptions clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -2506,7 +2497,7 @@ class MethodOptions extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - MethodOptions clone() => MethodOptions()..mergeFromMessage(this); + MethodOptions clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -2585,8 +2576,7 @@ class UninterpretedOption_NamePart extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - UninterpretedOption_NamePart clone() => - UninterpretedOption_NamePart()..mergeFromMessage(this); + UninterpretedOption_NamePart clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -2695,7 +2685,7 @@ class UninterpretedOption extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - UninterpretedOption clone() => UninterpretedOption()..mergeFromMessage(this); + UninterpretedOption clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -2839,8 +2829,7 @@ class SourceCodeInfo_Location extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - SourceCodeInfo_Location clone() => - SourceCodeInfo_Location()..mergeFromMessage(this); + SourceCodeInfo_Location clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -2923,7 +2912,7 @@ class SourceCodeInfo extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - SourceCodeInfo clone() => SourceCodeInfo()..mergeFromMessage(this); + SourceCodeInfo clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -2991,8 +2980,7 @@ class GeneratedCodeInfo_Annotation extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - GeneratedCodeInfo_Annotation clone() => - GeneratedCodeInfo_Annotation()..mergeFromMessage(this); + GeneratedCodeInfo_Annotation clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -3083,7 +3071,7 @@ class GeneratedCodeInfo extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - GeneratedCodeInfo clone() => GeneratedCodeInfo()..mergeFromMessage(this); + GeneratedCodeInfo clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') diff --git a/protoc_plugin/lib/src/generated/plugin.pb.dart b/protoc_plugin/lib/src/generated/plugin.pb.dart index 42e60cb89..f285091c6 100644 --- a/protoc_plugin/lib/src/generated/plugin.pb.dart +++ b/protoc_plugin/lib/src/generated/plugin.pb.dart @@ -60,7 +60,7 @@ class Version extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - Version clone() => Version()..mergeFromMessage(this); + Version clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -171,8 +171,7 @@ class CodeGeneratorRequest extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - CodeGeneratorRequest clone() => - CodeGeneratorRequest()..mergeFromMessage(this); + CodeGeneratorRequest clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -267,8 +266,7 @@ class CodeGeneratorResponse_File extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - CodeGeneratorResponse_File clone() => - CodeGeneratorResponse_File()..mergeFromMessage(this); + CodeGeneratorResponse_File clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') @@ -381,8 +379,7 @@ class CodeGeneratorResponse extends $pb.GeneratedMessage { @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - CodeGeneratorResponse clone() => - CodeGeneratorResponse()..mergeFromMessage(this); + CodeGeneratorResponse clone() => deepCopy(); @$core.Deprecated('Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') diff --git a/protoc_plugin/lib/src/message_generator.dart b/protoc_plugin/lib/src/message_generator.dart index cfbcdeec1..9cb3c7491 100644 --- a/protoc_plugin/lib/src/message_generator.dart +++ b/protoc_plugin/lib/src/message_generator.dart @@ -374,8 +374,7 @@ class MessageGenerator extends ProtobufContainer { 'Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version')'''); - out.println('$classname clone() =>' - ' $classname()..mergeFromMessage(this);'); + out.println('$classname clone() => deepCopy();'); out.println('''@$coreImportPrefix.Deprecated( 'Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' diff --git a/protoc_plugin/test/goldens/grpc_service.pb b/protoc_plugin/test/goldens/grpc_service.pb index 40d318a93..2731ef776 100644 --- a/protoc_plugin/test/goldens/grpc_service.pb +++ b/protoc_plugin/test/goldens/grpc_service.pb @@ -22,7 +22,7 @@ class Empty extends $pb.GeneratedMessage { 'Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - Empty clone() => Empty()..mergeFromMessage(this); + Empty clone() => deepCopy(); @$core.Deprecated( 'Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' diff --git a/protoc_plugin/test/goldens/imports.pb b/protoc_plugin/test/goldens/imports.pb index 51edcc115..aac9b6cfc 100644 --- a/protoc_plugin/test/goldens/imports.pb +++ b/protoc_plugin/test/goldens/imports.pb @@ -28,7 +28,7 @@ class M extends $pb.GeneratedMessage { 'Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - M clone() => M()..mergeFromMessage(this); + M clone() => deepCopy(); @$core.Deprecated( 'Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' diff --git a/protoc_plugin/test/goldens/int64.pb b/protoc_plugin/test/goldens/int64.pb index ce2101cc1..eb8af4d04 100644 --- a/protoc_plugin/test/goldens/int64.pb +++ b/protoc_plugin/test/goldens/int64.pb @@ -24,7 +24,7 @@ class Int64 extends $pb.GeneratedMessage { 'Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - Int64 clone() => Int64()..mergeFromMessage(this); + Int64 clone() => deepCopy(); @$core.Deprecated( 'Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' diff --git a/protoc_plugin/test/goldens/messageGenerator b/protoc_plugin/test/goldens/messageGenerator index 6840a22ff..8e9604154 100644 --- a/protoc_plugin/test/goldens/messageGenerator +++ b/protoc_plugin/test/goldens/messageGenerator @@ -14,7 +14,7 @@ class PhoneNumber extends $pb.GeneratedMessage { 'Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - PhoneNumber clone() => PhoneNumber()..mergeFromMessage(this); + PhoneNumber clone() => deepCopy(); @$core.Deprecated( 'Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' diff --git a/protoc_plugin/test/goldens/messageGenerator.meta b/protoc_plugin/test/goldens/messageGenerator.meta index e852febac..78e9c93c9 100644 --- a/protoc_plugin/test/goldens/messageGenerator.meta +++ b/protoc_plugin/test/goldens/messageGenerator.meta @@ -18,8 +18,8 @@ annotation: { path: 2 path: 1 sourceFile: - begin: 2263 - end: 2269 + begin: 2236 + end: 2242 } annotation: { path: 4 @@ -27,8 +27,8 @@ annotation: { path: 2 path: 1 sourceFile: - begin: 2311 - end: 2317 + begin: 2284 + end: 2290 } annotation: { path: 4 @@ -36,8 +36,8 @@ annotation: { path: 2 path: 1 sourceFile: - begin: 2390 - end: 2399 + begin: 2363 + end: 2372 } annotation: { path: 4 @@ -45,8 +45,8 @@ annotation: { path: 2 path: 1 sourceFile: - begin: 2442 - end: 2453 + begin: 2415 + end: 2426 } annotation: { path: 4 @@ -54,8 +54,8 @@ annotation: { path: 2 path: 0 sourceFile: - begin: 2523 - end: 2527 + begin: 2496 + end: 2500 } annotation: { path: 4 @@ -63,8 +63,8 @@ annotation: { path: 2 path: 0 sourceFile: - begin: 2568 - end: 2572 + begin: 2541 + end: 2545 } annotation: { path: 4 @@ -72,8 +72,8 @@ annotation: { path: 2 path: 0 sourceFile: - begin: 2651 - end: 2658 + begin: 2624 + end: 2631 } annotation: { path: 4 @@ -81,8 +81,8 @@ annotation: { path: 2 path: 0 sourceFile: - begin: 2701 - end: 2710 + begin: 2674 + end: 2683 } annotation: { path: 4 @@ -90,8 +90,8 @@ annotation: { path: 2 path: 2 sourceFile: - begin: 2771 - end: 2775 + begin: 2744 + end: 2748 } annotation: { path: 4 @@ -99,8 +99,8 @@ annotation: { path: 2 path: 2 sourceFile: - begin: 2822 - end: 2826 + begin: 2795 + end: 2799 } annotation: { path: 4 @@ -108,8 +108,8 @@ annotation: { path: 2 path: 2 sourceFile: - begin: 2899 - end: 2906 + begin: 2872 + end: 2879 } annotation: { path: 4 @@ -117,8 +117,8 @@ annotation: { path: 2 path: 2 sourceFile: - begin: 2949 - end: 2958 + begin: 2922 + end: 2931 } annotation: { path: 4 @@ -126,8 +126,8 @@ annotation: { path: 2 path: 3 sourceFile: - begin: 3068 - end: 3083 + begin: 3041 + end: 3056 } annotation: { path: 4 @@ -135,8 +135,8 @@ annotation: { path: 2 path: 3 sourceFile: - begin: 3174 - end: 3189 + begin: 3147 + end: 3162 } annotation: { path: 4 @@ -144,8 +144,8 @@ annotation: { path: 2 path: 3 sourceFile: - begin: 3311 - end: 3329 + begin: 3284 + end: 3302 } annotation: { path: 4 @@ -153,6 +153,6 @@ annotation: { path: 2 path: 3 sourceFile: - begin: 3421 - end: 3441 + begin: 3394 + end: 3414 } diff --git a/protoc_plugin/test/goldens/oneMessage.pb b/protoc_plugin/test/goldens/oneMessage.pb index 5c7885b2e..18921ae3a 100644 --- a/protoc_plugin/test/goldens/oneMessage.pb +++ b/protoc_plugin/test/goldens/oneMessage.pb @@ -24,7 +24,7 @@ class PhoneNumber extends $pb.GeneratedMessage { 'Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - PhoneNumber clone() => PhoneNumber()..mergeFromMessage(this); + PhoneNumber clone() => deepCopy(); @$core.Deprecated( 'Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' diff --git a/protoc_plugin/test/goldens/oneMessage.pb.meta b/protoc_plugin/test/goldens/oneMessage.pb.meta index 2dc041564..b9d529797 100644 --- a/protoc_plugin/test/goldens/oneMessage.pb.meta +++ b/protoc_plugin/test/goldens/oneMessage.pb.meta @@ -18,8 +18,8 @@ annotation: { path: 2 path: 0 sourceFile: test - begin: 2455 - end: 2461 + begin: 2428 + end: 2434 } annotation: { path: 4 @@ -27,8 +27,8 @@ annotation: { path: 2 path: 0 sourceFile: test - begin: 2503 - end: 2509 + begin: 2476 + end: 2482 } annotation: { path: 4 @@ -36,8 +36,8 @@ annotation: { path: 2 path: 0 sourceFile: test - begin: 2582 - end: 2591 + begin: 2555 + end: 2564 } annotation: { path: 4 @@ -45,8 +45,8 @@ annotation: { path: 2 path: 0 sourceFile: test - begin: 2634 - end: 2645 + begin: 2607 + end: 2618 } annotation: { path: 4 @@ -54,8 +54,8 @@ annotation: { path: 2 path: 1 sourceFile: test - begin: 2703 - end: 2707 + begin: 2676 + end: 2680 } annotation: { path: 4 @@ -63,8 +63,8 @@ annotation: { path: 2 path: 1 sourceFile: test - begin: 2749 - end: 2753 + begin: 2722 + end: 2726 } annotation: { path: 4 @@ -72,8 +72,8 @@ annotation: { path: 2 path: 1 sourceFile: test - begin: 2828 - end: 2835 + begin: 2801 + end: 2808 } annotation: { path: 4 @@ -81,8 +81,8 @@ annotation: { path: 2 path: 1 sourceFile: test - begin: 2878 - end: 2887 + begin: 2851 + end: 2860 } annotation: { path: 4 @@ -90,8 +90,8 @@ annotation: { path: 2 path: 2 sourceFile: test - begin: 2948 - end: 2952 + begin: 2921 + end: 2925 } annotation: { path: 4 @@ -99,8 +99,8 @@ annotation: { path: 2 path: 2 sourceFile: test - begin: 2999 - end: 3003 + begin: 2972 + end: 2976 } annotation: { path: 4 @@ -108,8 +108,8 @@ annotation: { path: 2 path: 2 sourceFile: test - begin: 3076 - end: 3083 + begin: 3049 + end: 3056 } annotation: { path: 4 @@ -117,6 +117,6 @@ annotation: { path: 2 path: 2 sourceFile: test - begin: 3126 - end: 3135 + begin: 3099 + end: 3108 } diff --git a/protoc_plugin/test/goldens/service.pb b/protoc_plugin/test/goldens/service.pb index ef803ecc5..5fa9749af 100644 --- a/protoc_plugin/test/goldens/service.pb +++ b/protoc_plugin/test/goldens/service.pb @@ -23,7 +23,7 @@ class Empty extends $pb.GeneratedMessage { 'Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - Empty clone() => Empty()..mergeFromMessage(this); + Empty clone() => deepCopy(); @$core.Deprecated( 'Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. '