Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(791)

Side by Side Diff: lib/src/protobuf/mixins/map_mixin.dart

Issue 2019423002: Make PbMapMixin implement Map<String, dynamic> (Closed) Base URL: https://github.com/dart-lang/dart-protobuf.git@master
Patch Set: nits Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library protobuf.mixins.map; 5 library protobuf.mixins.map;
6 6
7 import "package:protobuf/protobuf.dart" show BuilderInfo; 7 import "package:protobuf/protobuf.dart" show BuilderInfo;
8 8
9 /// A PbMapMixin provides an experimental implementation of the 9 /// A PbMapMixin provides an experimental implementation of the
10 /// Map interface for a GeneratedMessage. 10 /// Map interface for a GeneratedMessage.
11 /// 11 ///
12 /// This mixin is enabled via an option in 12 /// This mixin is enabled via an option in
13 /// dart_options.proto in dart-protoc-plugin. 13 /// dart_options.proto in dart-protoc-plugin.
14 abstract class PbMapMixin implements Map { 14 abstract class PbMapMixin implements Map<String, dynamic> {
15 // GeneratedMessage properties and methods used by this mixin. 15 // GeneratedMessage properties and methods used by this mixin.
16 16
17 BuilderInfo get info_; 17 BuilderInfo get info_;
18 void clear(); 18 void clear();
19 int getTagNumber(String fieldName); 19 int getTagNumber(String fieldName);
20 getField(int tagNumber); 20 getField(int tagNumber);
21 void setField(int tagNumber, var value); 21 void setField(int tagNumber, var value);
22 22
23 @override 23 @override
24 operator [](key) { 24 operator [](key) {
25 if (key is! String) return null; 25 if (key is! String) return null;
26 var tag = getTagNumber(key); 26 var tag = getTagNumber(key);
27 if (tag == null) return null; 27 if (tag == null) return null;
28 return getField(tag); 28 return getField(tag);
29 } 29 }
30 30
31 @override 31 @override
32 operator []=(key, val) { 32 void operator []=(String key, val) {
33 var tag = getTagNumber(key as String); 33 var tag = getTagNumber(key);
34 if (tag == null) { 34 if (tag == null) {
35 throw new ArgumentError( 35 throw new ArgumentError(
36 "field '${key}' not found in ${info_.messageName}"); 36 "field '${key}' not found in ${info_.messageName}");
37 } 37 }
38 setField(tag, val); 38 setField(tag, val);
39 } 39 }
40 40
41 @override 41 @override
42 get keys => info_.byName.keys; 42 Iterable<String> get keys => info_.byName.keys;
43 43
44 @override 44 @override
45 bool containsKey(Object key) => info_.byName.containsKey(key); 45 bool containsKey(Object key) => info_.byName.containsKey(key);
46 46
47 @override 47 @override
48 get length => info_.byName.length; 48 int get length => info_.byName.length;
49 49
50 @override 50 @override
51 remove(key) { 51 remove(key) {
52 throw new UnsupportedError( 52 throw new UnsupportedError(
53 "remove() not supported by ${info_.messageName}"); 53 "remove() not supported by ${info_.messageName}");
54 } 54 }
55 } 55 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698