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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: lib/src/protobuf/mixins/map_mixin.dart
diff --git a/lib/src/protobuf/mixins/map_mixin.dart b/lib/src/protobuf/mixins/map_mixin.dart
new file mode 100644
index 0000000000000000000000000000000000000000..93006408dc66371d9fccc684be17e70a57d3a80e
--- /dev/null
+++ b/lib/src/protobuf/mixins/map_mixin.dart
@@ -0,0 +1,56 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library protobuf.mixins.map;
+
+import "package:protobuf/protobuf.dart" show BuilderInfo;
+
+/// A PbMapMixin provides an experimental implementation of the
+/// Map interface for a GeneratedMessage.
+///
+/// This mixin is enabled via an option in
+/// dart_options.proto in dart-protoc-plugin.
+abstract class PbMapMixin implements Map<String, dynamic> {
+
+ // GeneratedMessage properties and methods used by this mixin.
+
+ BuilderInfo info_;
+ void clear();
+ int getTagNumber(String fieldName);
+ getField(int tagNumber);
+ void setField(int tagNumber, var value, [int fieldType = null]);
+
+ @override
+ operator [](key) {
+ if (key is! String) return null;
+ var tag = getTagNumber(key);
+ if (tag == null) return null;
+ return getField(tag);
+ }
+
+ @override
+ operator []=(String key, val) {
+ var tag = getTagNumber(key);
+ if (tag == null) {
+ throw new ArgumentError(
+ "field '${key}' not found in ${info_.messageName}");
+ }
+ setField(tag, val);
+ }
+
+ @override
+ get keys => info_.byName.keys;
+
+ @override
+ bool containsKey(Object key) => info_.byName.containsKey(key);
+
+ @override
+ get length => info_.byName.length;
+
+ @override
+ remove(key) {
+ throw new UnsupportedError(
+ "remove() not supported by ${info_.messageName}");
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698