OLD | NEW |
1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
4 // | 4 // |
5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
7 // met: | 7 // met: |
8 // | 8 // |
9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
(...skipping 14 matching lines...) Expand all Loading... |
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | 30 |
31 syntax = "proto2"; | 31 syntax = "proto2"; |
32 | 32 |
33 | 33 |
34 option java_outer_classname = "MapForProto2TestProto"; | 34 option java_outer_classname = "MapForProto2TestProto"; |
| 35 option java_generate_equals_and_hash = true; |
35 | 36 |
36 message TestMap { | 37 message TestMap { |
37 message MessageValue { | 38 message MessageValue { |
38 optional int32 value = 1; | 39 optional int32 value = 1; |
39 } | 40 } |
40 enum EnumValue { | 41 enum EnumValue { |
41 FOO = 0; | 42 FOO = 0; |
42 BAR = 1; | 43 BAR = 1; |
43 BAZ = 2; | 44 BAZ = 2; |
44 QUX = 3; | 45 QUX = 3; |
(...skipping 17 matching lines...) Expand all Loading... |
62 // parsing behavior of TestMap regarding unknown enum values. | 63 // parsing behavior of TestMap regarding unknown enum values. |
63 map<int32, int32> int32_to_int32_field = 4; | 64 map<int32, int32> int32_to_int32_field = 4; |
64 } | 65 } |
65 | 66 |
66 // Test that the maps initialization code works correctly when the map field | 67 // Test that the maps initialization code works correctly when the map field |
67 // references the containing message. | 68 // references the containing message. |
68 message TestRecursiveMap { | 69 message TestRecursiveMap { |
69 optional int32 value = 1; | 70 optional int32 value = 1; |
70 map<int32, TestRecursiveMap> recursive_map_field = 2; | 71 map<int32, TestRecursiveMap> recursive_map_field = 2; |
71 } | 72 } |
72 | |
73 | |
74 // a decoy of TestMap for testing parsing errors | |
75 message BizarroTestMap { | |
76 map<int32, bytes> int32_to_int32_field = 1; // same key type, different value | |
77 map<string, int32> int32_to_string_field = 2; // different key and value types | |
78 map<string, int32> int32_to_bytes_field = 3; // different key types, same valu
e | |
79 map<string, bytes> int32_to_enum_field = 4; // different key and value types | |
80 map<string, bytes> int32_to_message_field = 5; // different key and value type
s | |
81 map<string, bytes> string_to_int32_field = 6; // same key type, different val
ue | |
82 } | |
83 | |
84 // Used to test that java reserved words can be used as protobuf field names | |
85 // Not all reserved words are tested (to avoid bloat) but instead an arbitrary | |
86 // subset of them chosen to cover various keyword categories like | |
87 // type, modifier, declaration, etc. | |
88 message ReservedAsMapField { | |
89 map<string, uint32> if = 1; | |
90 map<string, uint32> const = 2; | |
91 map<string, uint32> private = 3; | |
92 map<string, uint32> class = 4; | |
93 map<string, uint32> int = 5; | |
94 map<string, uint32> void = 6; | |
95 map<string, uint32> string = 7; // These are also proto keywords | |
96 map<string, uint32> package = 8; | |
97 map<string, uint32> enum = 9; // Most recent Java reserved word | |
98 map<string, uint32> null = 10; | |
99 // null is not a 'reserved word' per se but as a literal needs similar care | |
100 } | |
101 | |
102 message ReservedAsMapFieldWithEnumValue { | |
103 enum SampleEnum { | |
104 A = 0; | |
105 B = 1; | |
106 } | |
107 map<string, SampleEnum> if = 1; | |
108 map<string, SampleEnum> const = 2; | |
109 map<string, SampleEnum> private = 3; | |
110 map<string, SampleEnum> class = 4; | |
111 map<string, SampleEnum> int = 5; | |
112 map<string, SampleEnum> void = 6; | |
113 map<string, SampleEnum> string = 7; // These are also proto keywords | |
114 map<string, SampleEnum> package = 8; | |
115 map<string, SampleEnum> enum = 9; // Most recent Java reserved word | |
116 map<string, SampleEnum> null = 10; | |
117 // null is not a 'reserved word' per se but as a literal needs similar care | |
118 } | |
119 package map_for_proto2_lite_test; | 73 package map_for_proto2_lite_test; |
120 option java_package = "map_lite_test"; | 74 option java_package = "map_lite_test"; |
121 option optimize_for = LITE_RUNTIME; | 75 option optimize_for = LITE_RUNTIME; |
OLD | NEW |