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

Unified Diff: lib/protobuf/runtime/ExtensionRegistry.dart

Issue 10595002: Protocol Buffer runtime library and 'protoc' plugin (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Work around http://code.google.com/p/dart/issues/detail?id=3806 Created 8 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
« no previous file with comments | « lib/protobuf/runtime/Extension.dart ('k') | lib/protobuf/runtime/FieldInfo.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/protobuf/runtime/ExtensionRegistry.dart
diff --git a/lib/protobuf/runtime/ExtensionRegistry.dart b/lib/protobuf/runtime/ExtensionRegistry.dart
new file mode 100644
index 0000000000000000000000000000000000000000..08a4177b4926a76c9fd02878dee354999311bee6
--- /dev/null
+++ b/lib/protobuf/runtime/ExtensionRegistry.dart
@@ -0,0 +1,56 @@
+// Copyright (c) 2011, 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.
+
+/**
+ * A collection of [Extension] objects, organized by the message type they
+ * extend.
+ */
+class ExtensionRegistry {
+
+ Map<String, Map<int, Extension>> _extensions;
+
+ ExtensionRegistry() : _extensions =
+ new Map<String, Map<int, Extension>>();
+
+ static ExtensionRegistry _EMPTY_REGISTRY;
+
+ static ExtensionRegistry get EMPTY_REGISTRY() {
+ if (_EMPTY_REGISTRY == null) {
+ _EMPTY_REGISTRY = new _EmptyExtensionRegistry();
+ }
+ return _EMPTY_REGISTRY;
+ }
+
+ /**
+ * Store an extension in the registry.
+ */
+ void add(Extension extension) {
+ Map<int, Extension> map = _extensions[extension.extendee];
+ if (map == null) {
+ map = new Map<int, Extension>();
+ _extensions[extension.extendee] = map;
+ }
+ map[extension.tagNumber] = extension;
+ }
+
+ /**
+ * Retrieve an extension from the registry that adds the given tag
+ * number to the given message type.
+ */
+ Extension getExtension(String messageName, int tagNumber) {
+ Map<int, Extension> map = _extensions[messageName];
+ if (map != null) {
+ return map[tagNumber];
+ }
+ return null;
+ }
+}
+
+class _EmptyExtensionRegistry extends ExtensionRegistry {
+ void add(Extension extension) {
+ throw new UnsupportedOperationException("Immutable ExtensionRegistry");
+ }
+
+ Extension getExtension(String messageName, int tagNumber) => null;
+}
« no previous file with comments | « lib/protobuf/runtime/Extension.dart ('k') | lib/protobuf/runtime/FieldInfo.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698