-
-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deserialize and serialize unknown fields (#2153)
- Loading branch information
Showing
55 changed files
with
864 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import 'dart:collection'; | ||
|
||
import 'package:meta/meta.dart'; | ||
|
||
@internal | ||
class AccessAwareMap<String, V> extends MapBase<String, V> { | ||
AccessAwareMap(this._map); | ||
|
||
final Map<String, V> _map; | ||
final Set<String> _accessedKeysWithValues = {}; | ||
|
||
Set<String> get accessedKeysWithValues => _accessedKeysWithValues; | ||
|
||
@override | ||
V? operator [](Object? key) { | ||
if (key is String && _map.containsKey(key)) { | ||
_accessedKeysWithValues.add(key); | ||
} | ||
return _map[key]; | ||
} | ||
|
||
@override | ||
void operator []=(String key, V value) { | ||
_map[key] = value; | ||
} | ||
|
||
@override | ||
void clear() { | ||
_map.clear(); | ||
_accessedKeysWithValues.clear(); | ||
} | ||
|
||
@override | ||
Iterable<String> get keys => _map.keys; | ||
|
||
@override | ||
V? remove(Object? key) { | ||
return _map.remove(key); | ||
} | ||
|
||
Map<String, dynamic>? notAccessed() { | ||
if (_accessedKeysWithValues.length == _map.length) { | ||
return null; | ||
} | ||
Map<String, dynamic> unknown = _map.keys | ||
.where((key) => !_accessedKeysWithValues.contains(key)) | ||
.fold<Map<String, dynamic>>({}, (map, key) { | ||
map[key] = _map[key]; | ||
return map; | ||
}); | ||
return unknown.isNotEmpty ? unknown : null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.