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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « lib/protobuf/runtime/Extension.dart ('k') | lib/protobuf/runtime/FieldInfo.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011, 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 /**
6 * A collection of [Extension] objects, organized by the message type they
7 * extend.
8 */
9 class ExtensionRegistry {
10
11 Map<String, Map<int, Extension>> _extensions;
12
13 ExtensionRegistry() : _extensions =
14 new Map<String, Map<int, Extension>>();
15
16 static ExtensionRegistry _EMPTY_REGISTRY;
17
18 static ExtensionRegistry get EMPTY_REGISTRY() {
19 if (_EMPTY_REGISTRY == null) {
20 _EMPTY_REGISTRY = new _EmptyExtensionRegistry();
21 }
22 return _EMPTY_REGISTRY;
23 }
24
25 /**
26 * Store an extension in the registry.
27 */
28 void add(Extension extension) {
29 Map<int, Extension> map = _extensions[extension.extendee];
30 if (map == null) {
31 map = new Map<int, Extension>();
32 _extensions[extension.extendee] = map;
33 }
34 map[extension.tagNumber] = extension;
35 }
36
37 /**
38 * Retrieve an extension from the registry that adds the given tag
39 * number to the given message type.
40 */
41 Extension getExtension(String messageName, int tagNumber) {
42 Map<int, Extension> map = _extensions[messageName];
43 if (map != null) {
44 return map[tagNumber];
45 }
46 return null;
47 }
48 }
49
50 class _EmptyExtensionRegistry extends ExtensionRegistry {
51 void add(Extension extension) {
52 throw new UnsupportedOperationException("Immutable ExtensionRegistry");
53 }
54
55 Extension getExtension(String messageName, int tagNumber) => null;
56 }
OLDNEW
« 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