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

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

Issue 1196773004: changes for 0.3.9 (Closed) Base URL: https://github.com/dart-lang/dart-protobuf.git@master
Patch Set: add mixins_meta, move PbMapMixin to separate library Created 5 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library protobuf.mixins.map;
6
7 import "package:protobuf/protobuf.dart" show BuilderInfo;
8
9 /// A PbMapMixin provides an experimental implementation of the
10 /// Map interface for a GeneratedMessage.
11 ///
12 /// This mixin is enabled via an option in
13 /// dart_options.proto in dart-protoc-plugin.
14 abstract class PbMapMixin implements Map<String, dynamic> {
15
16 // GeneratedMessage properties and methods used by this mixin.
17
18 BuilderInfo info_;
19 void clear();
20 int getTagNumber(String fieldName);
21 getField(int tagNumber);
22 void setField(int tagNumber, var value, [int fieldType = null]);
23
24 @override
25 operator [](key) {
26 if (key is! String) return null;
27 var tag = getTagNumber(key);
28 if (tag == null) return null;
29 return getField(tag);
30 }
31
32 @override
33 operator []=(String key, val) {
34 var tag = getTagNumber(key);
35 if (tag == null) {
36 throw new ArgumentError(
37 "field '${key}' not found in ${info_.messageName}");
38 }
39 setField(tag, val);
40 }
41
42 @override
43 get keys => info_.byName.keys;
44
45 @override
46 bool containsKey(Object key) => info_.byName.containsKey(key);
47
48 @override
49 get length => info_.byName.length;
50
51 @override
52 remove(key) {
53 throw new UnsupportedError(
54 "remove() not supported by ${info_.messageName}");
55 }
56 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698