Index: third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/MapFactories.java |
diff --git a/third_party/protobuf/src/google/protobuf/unittest_mset.proto b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/MapFactories.java |
similarity index 58% |
copy from third_party/protobuf/src/google/protobuf/unittest_mset.proto |
copy to third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/MapFactories.java |
index 3497f09fa6d41b7b38357e7f2610dfb5c087d3e4..98fa4877bc404451ff9d36483f23f7ac0a059f4b 100644 |
--- a/third_party/protobuf/src/google/protobuf/unittest_mset.proto |
+++ b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/MapFactories.java |
@@ -1,6 +1,6 @@ |
// Protocol Buffers - Google's data interchange format |
-// Copyright 2008 Google Inc. All rights reserved. |
-// http://code.google.com/p/protobuf/ |
+// Copyright 2013 Google Inc. All rights reserved. |
+// https://developers.google.com/protocol-buffers/ |
// |
// Redistribution and use in source and binary forms, with or without |
// modification, are permitted provided that the following conditions are |
@@ -28,45 +28,40 @@ |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
-// Author: kenton@google.com (Kenton Varda) |
-// Based on original Protocol Buffers design by |
-// Sanjay Ghemawat, Jeff Dean, and others. |
-// |
-// This file contains messages for testing message_set_wire_format. |
- |
-package protobuf_unittest; |
+package com.google.protobuf.nano; |
-option optimize_for = SPEED; |
+import java.util.HashMap; |
+import java.util.Map; |
-// A message with message_set_wire_format. |
-message TestMessageSet { |
- option message_set_wire_format = true; |
- extensions 4 to max; |
-} |
- |
-message TestMessageSetContainer { |
- optional TestMessageSet message_set = 1; |
-} |
+/** |
+ * Utility class for maps support. |
+ */ |
+public final class MapFactories { |
+ public static interface MapFactory { |
+ <K, V> Map<K, V> forMap(Map<K, V> oldMap); |
+ } |
-message TestMessageSetExtension1 { |
- extend TestMessageSet { |
- optional TestMessageSetExtension1 message_set_extension = 1545008; |
+ // NOTE(liujisi): The factory setter is temporarily marked as package private. |
+ // The way to provide customized implementations of maps for different |
+ // platforms are still under discussion. Mark it as private to avoid exposing |
+ // the API in proto3 alpha release. |
+ /* public */ static void setMapFactory(MapFactory newMapFactory) { |
+ mapFactory = newMapFactory; |
} |
- optional int32 i = 15; |
-} |
-message TestMessageSetExtension2 { |
- extend TestMessageSet { |
- optional TestMessageSetExtension2 message_set_extension = 1547769; |
+ public static MapFactory getMapFactory() { |
+ return mapFactory; |
} |
- optional string str = 25; |
-} |
-// MessageSet wire format is equivalent to this. |
-message RawMessageSet { |
- repeated group Item = 1 { |
- required int32 type_id = 2; |
- required bytes message = 3; |
+ private static class DefaultMapFactory implements MapFactory { |
+ public <K, V> Map<K, V> forMap(Map<K, V> oldMap) { |
+ if (oldMap == null) { |
+ return new HashMap<K, V>(); |
+ } |
+ return oldMap; |
+ } |
} |
-} |
+ private static volatile MapFactory mapFactory = new DefaultMapFactory(); |
+ private MapFactories() {} |
+} |