Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update getList and getMap return types #903

Merged
merged 6 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions protobuf/lib/src/protobuf/field_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ class _FieldSet {
}

/// The implementation of a generated getter for repeated fields.
List<T> _$getList<T>(int index) {
PbList<T> _$getList<T>(int index) {
final value = _values[index];
if (value != null) return value;

Expand All @@ -387,9 +387,9 @@ class _FieldSet {
}

/// The implementation of a generated getter for map fields.
Map<K, V> _$getMap<K, V>(GeneratedMessage parentMessage, int index) {
PbMap<K, V> _$getMap<K, V>(GeneratedMessage parentMessage, int index) {
final value = _values[index];
if (value != null) return value as Map<K, V>;
if (value != null) return value;

final fi = _nonExtensionInfoByIndex(index) as MapFieldInfo<K, V>;
assert(fi.isMapField);
Expand Down
5 changes: 3 additions & 2 deletions protobuf/lib/src/protobuf/generated_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,12 @@ abstract class GeneratedMessage {

/// For generated code only.
/// @nodoc
List<T> $_getList<T>(int index) => _fieldSet._$getList<T>(index);
PbList<T> $_getList<T>(int index) => _fieldSet._$getList<T>(index);

/// For generated code only.
/// @nodoc
Map<K, V> $_getMap<K, V>(int index) => _fieldSet._$getMap<K, V>(this, index);
PbMap<K, V> $_getMap<K, V>(int index) =>
_fieldSet._$getMap<K, V>(this, index);

/// For generated code only.
/// @nodoc
Expand Down
5 changes: 5 additions & 0 deletions protoc_plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
## 22.0.0-dev

* Remove `PbEventMixin` mixin. ([#738])
* Type of repeated fields is now `PbList` (instead of `List`), type of map
fields is now `PbMap` (instead of `Map`). ([#903])

This change requires protobuf-4.0.0.

[#738]: https://github.com/google/protobuf.dart/issues/738
[#903]: https://github.com/google/protobuf.dart/pull/903

## 21.1.2

Expand Down
2 changes: 1 addition & 1 deletion protoc_plugin/lib/src/base_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class BaseType {
: prefixed;

String getRepeatedDartType(FileGenerator fileGen) =>
'$coreImportPrefix.List<${getDartType(fileGen)}>';
'$protobufImportPrefix.PbList<${getDartType(fileGen)}>';

String getRepeatedDartTypeIterable(FileGenerator fileGen) =>
'$coreImportPrefix.Iterable<${getDartType(fileGen)}>';
Expand Down
2 changes: 1 addition & 1 deletion protoc_plugin/lib/src/protobuf_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class ProtobufField {
final d = baseType.generator as MessageGenerator;
final keyType = d._fieldList[0].baseType.getDartType(parent.fileGen!);
final valueType = d._fieldList[1].baseType.getDartType(parent.fileGen!);
return '$coreImportPrefix.Map<$keyType, $valueType>';
return '$protobufImportPrefix.PbMap<$keyType, $valueType>';
}
if (isRepeated) return baseType.getRepeatedDartType(parent.fileGen!);
return baseType.getDartType(parent.fileGen!);
Expand Down
Loading