Skip to content

Commit

Permalink
Add type param to ProtobufEnum.initByValue (flutter#128)
Browse files Browse the repository at this point in the history
Will allow generated code to omit a runtime cast on `valueOf`
  • Loading branch information
kevmoo authored Sep 21, 2018
1 parent e7ee1f8 commit 5e5bc71
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.10.3

* Added type argument to `ProtobufEnum.initByValue` which allows the return
value to be fully typed.

## 0.10.2

* Added ProtobufEnum reserved names.
Expand Down
9 changes: 3 additions & 6 deletions lib/src/protobuf/protobuf_enum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,9 @@ class ProtobufEnum {

/// Returns a Map for all of the [ProtobufEnum]s in [byIndex], mapping each
/// [ProtobufEnum]'s [value] to the [ProtobufEnum].
// Cannot type return type as Map<int, ProtobufEnum> as it will be
// assigned to Map<int, subtype of ProtobufEnum>.
static Map<int, dynamic> initByValue(List<ProtobufEnum> byIndex) {
var byValue = new Map<int, dynamic>();
for (ProtobufEnum v in byIndex) {
static Map<int, T> initByValue<T extends ProtobufEnum>(List<T> byIndex) {
var byValue = new Map<int, T>();
for (T v in byIndex) {
byValue[v.value] = v;
}
return byValue;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: protobuf
version: 0.10.2
version: 0.10.3
author: Dart Team <misc@dartlang.org>
description: >
Runtime library for protocol buffers support.
Expand Down

0 comments on commit 5e5bc71

Please sign in to comment.