protobuffy 3.6.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +67 -0
  4. data/.rubocop_todo.yml +145 -0
  5. data/.travis.yml +25 -5
  6. data/CHANGES.md +55 -0
  7. data/CONTRIBUTING.md +1 -1
  8. data/LICENSE.txt +17 -9
  9. data/README.md +13 -12
  10. data/Rakefile +15 -11
  11. data/bin/protoc-gen-ruby +8 -3
  12. data/bin/rpc_server +1 -0
  13. data/examples/lib/example/reverse-client.rb +2 -2
  14. data/install-protobuf.sh +28 -0
  15. data/lib/protobuf.rb +57 -53
  16. data/lib/protobuf/cli.rb +94 -74
  17. data/lib/protobuf/code_generator.rb +60 -9
  18. data/lib/protobuf/decoder.rb +19 -65
  19. data/lib/protobuf/deprecation.rb +117 -0
  20. data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +11 -1
  21. data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +55 -3
  22. data/lib/protobuf/encoder.rb +13 -53
  23. data/lib/protobuf/enum.rb +58 -63
  24. data/lib/protobuf/field.rb +4 -4
  25. data/lib/protobuf/field/base_field.rb +101 -173
  26. data/lib/protobuf/field/bool_field.rb +17 -11
  27. data/lib/protobuf/field/bytes_field.rb +21 -35
  28. data/lib/protobuf/field/double_field.rb +0 -1
  29. data/lib/protobuf/field/enum_field.rb +23 -22
  30. data/lib/protobuf/field/field_array.rb +5 -4
  31. data/lib/protobuf/field/fixed32_field.rb +1 -1
  32. data/lib/protobuf/field/fixed64_field.rb +0 -1
  33. data/lib/protobuf/field/float_field.rb +4 -1
  34. data/lib/protobuf/field/int32_field.rb +0 -1
  35. data/lib/protobuf/field/int64_field.rb +0 -1
  36. data/lib/protobuf/field/integer_field.rb +0 -1
  37. data/lib/protobuf/field/message_field.rb +13 -28
  38. data/lib/protobuf/field/sfixed32_field.rb +0 -1
  39. data/lib/protobuf/field/sfixed64_field.rb +0 -1
  40. data/lib/protobuf/field/signed_integer_field.rb +0 -1
  41. data/lib/protobuf/field/sint32_field.rb +0 -1
  42. data/lib/protobuf/field/sint64_field.rb +0 -1
  43. data/lib/protobuf/field/string_field.rb +2 -4
  44. data/lib/protobuf/field/uint32_field.rb +0 -1
  45. data/lib/protobuf/field/uint64_field.rb +0 -1
  46. data/lib/protobuf/field/varint_field.rb +30 -13
  47. data/lib/protobuf/generators/base.rb +30 -16
  48. data/lib/protobuf/generators/enum_generator.rb +6 -9
  49. data/lib/protobuf/generators/extension_generator.rb +1 -2
  50. data/lib/protobuf/generators/field_generator.rb +25 -13
  51. data/lib/protobuf/generators/file_generator.rb +157 -35
  52. data/lib/protobuf/generators/group_generator.rb +22 -17
  53. data/lib/protobuf/generators/message_generator.rb +13 -14
  54. data/lib/protobuf/generators/option_generator.rb +17 -0
  55. data/lib/protobuf/generators/printable.rb +12 -13
  56. data/lib/protobuf/generators/service_generator.rb +2 -3
  57. data/lib/protobuf/http.rb +2 -2
  58. data/lib/protobuf/lifecycle.rb +20 -33
  59. data/lib/protobuf/logging.rb +39 -0
  60. data/lib/protobuf/message.rb +114 -47
  61. data/lib/protobuf/message/fields.rb +170 -88
  62. data/lib/protobuf/message/serialization.rb +19 -18
  63. data/lib/protobuf/optionable.rb +53 -6
  64. data/lib/protobuf/rpc/buffer.rb +18 -19
  65. data/lib/protobuf/rpc/client.rb +22 -50
  66. data/lib/protobuf/rpc/connectors/base.rb +177 -12
  67. data/lib/protobuf/rpc/connectors/http.rb +14 -9
  68. data/lib/protobuf/rpc/connectors/ping.rb +89 -0
  69. data/lib/protobuf/rpc/connectors/socket.rb +13 -8
  70. data/lib/protobuf/rpc/connectors/zmq.rb +178 -73
  71. data/lib/protobuf/rpc/dynamic_discovery.pb.rb +4 -1
  72. data/lib/protobuf/rpc/env.rb +12 -12
  73. data/lib/protobuf/rpc/error.rb +3 -3
  74. data/lib/protobuf/rpc/error/client_error.rb +4 -4
  75. data/lib/protobuf/rpc/error/server_error.rb +9 -9
  76. data/lib/protobuf/rpc/middleware/exception_handler.rb +6 -2
  77. data/lib/protobuf/rpc/middleware/logger.rb +8 -4
  78. data/lib/protobuf/rpc/middleware/request_decoder.rb +17 -21
  79. data/lib/protobuf/rpc/middleware/response_encoder.rb +22 -27
  80. data/lib/protobuf/rpc/middleware/statsd.rb +3 -3
  81. data/lib/protobuf/rpc/rpc.pb.rb +4 -1
  82. data/lib/protobuf/rpc/server.rb +1 -1
  83. data/lib/protobuf/rpc/servers/http/server.rb +19 -17
  84. data/lib/protobuf/rpc/servers/socket/server.rb +78 -70
  85. data/lib/protobuf/rpc/servers/socket/worker.rb +4 -4
  86. data/lib/protobuf/rpc/servers/socket_runner.rb +27 -15
  87. data/lib/protobuf/rpc/servers/zmq/broker.rb +70 -31
  88. data/lib/protobuf/rpc/servers/zmq/server.rb +55 -47
  89. data/lib/protobuf/rpc/servers/zmq/util.rb +14 -13
  90. data/lib/protobuf/rpc/servers/zmq/worker.rb +16 -16
  91. data/lib/protobuf/rpc/servers/zmq_runner.rb +26 -7
  92. data/lib/protobuf/rpc/service.rb +21 -27
  93. data/lib/protobuf/rpc/service_directory.rb +43 -27
  94. data/lib/protobuf/rpc/service_dispatcher.rb +9 -10
  95. data/lib/protobuf/rpc/service_filters.rb +32 -55
  96. data/lib/protobuf/rpc/stat.rb +4 -8
  97. data/lib/protobuf/socket.rb +1 -2
  98. data/lib/protobuf/tasks/compile.rake +3 -4
  99. data/lib/protobuf/varint.rb +9 -0
  100. data/lib/protobuf/varint_pure.rb +13 -0
  101. data/lib/protobuf/version.rb +1 -1
  102. data/lib/protobuf/zmq.rb +2 -2
  103. data/proto/google/protobuf/descriptor.proto +190 -31
  104. data/protobuffy.gemspec +30 -17
  105. data/spec/benchmark/tasks.rb +27 -19
  106. data/spec/bin/protoc-gen-ruby_spec.rb +11 -6
  107. data/spec/encoding/all_types_spec.rb +96 -84
  108. data/spec/encoding/extreme_values_spec.rb +0 -0
  109. data/spec/functional/class_inheritance_spec.rb +52 -0
  110. data/spec/functional/code_generator_spec.rb +38 -0
  111. data/spec/functional/socket_server_spec.rb +15 -15
  112. data/spec/functional/zmq_server_spec.rb +29 -27
  113. data/spec/lib/protobuf/cli_spec.rb +82 -67
  114. data/spec/lib/protobuf/code_generator_spec.rb +37 -10
  115. data/spec/lib/protobuf/enum_spec.rb +77 -46
  116. data/spec/lib/protobuf/field/bool_field_spec.rb +91 -0
  117. data/spec/lib/protobuf/field/double_field_spec.rb +9 -0
  118. data/spec/lib/protobuf/field/enum_field_spec.rb +26 -0
  119. data/spec/lib/protobuf/field/field_array_spec.rb +69 -0
  120. data/spec/lib/protobuf/field/fixed32_field_spec.rb +7 -0
  121. data/spec/lib/protobuf/field/fixed64_field_spec.rb +7 -0
  122. data/spec/lib/protobuf/field/float_field_spec.rb +90 -0
  123. data/spec/lib/protobuf/field/int32_field_spec.rb +114 -1
  124. data/spec/lib/protobuf/field/int64_field_spec.rb +7 -0
  125. data/spec/lib/protobuf/field/message_field_spec.rb +132 -0
  126. data/spec/lib/protobuf/field/sfixed32_field_spec.rb +9 -0
  127. data/spec/lib/protobuf/field/sfixed64_field_spec.rb +9 -0
  128. data/spec/lib/protobuf/field/sint32_field_spec.rb +9 -0
  129. data/spec/lib/protobuf/field/sint64_field_spec.rb +9 -0
  130. data/spec/lib/protobuf/field/string_field_spec.rb +44 -11
  131. data/spec/lib/protobuf/field/uint32_field_spec.rb +7 -0
  132. data/spec/lib/protobuf/field/uint64_field_spec.rb +7 -0
  133. data/spec/lib/protobuf/field_spec.rb +4 -6
  134. data/spec/lib/protobuf/generators/base_spec.rb +80 -13
  135. data/spec/lib/protobuf/generators/enum_generator_spec.rb +35 -21
  136. data/spec/lib/protobuf/generators/extension_generator_spec.rb +12 -13
  137. data/spec/lib/protobuf/generators/field_generator_spec.rb +73 -21
  138. data/spec/lib/protobuf/generators/file_generator_spec.rb +89 -6
  139. data/spec/lib/protobuf/generators/service_generator_spec.rb +25 -13
  140. data/spec/lib/protobuf/lifecycle_spec.rb +25 -20
  141. data/spec/lib/protobuf/message_spec.rb +578 -79
  142. data/spec/lib/protobuf/optionable_spec.rb +202 -26
  143. data/spec/lib/protobuf/rpc/client_spec.rb +16 -16
  144. data/spec/lib/protobuf/rpc/connectors/base_spec.rb +167 -13
  145. data/spec/lib/protobuf/rpc/connectors/connector_spec.rb +4 -5
  146. data/spec/lib/protobuf/rpc/connectors/http_spec.rb +13 -11
  147. data/spec/lib/protobuf/rpc/connectors/ping_spec.rb +69 -0
  148. data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +6 -7
  149. data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +35 -52
  150. data/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +10 -10
  151. data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +11 -11
  152. data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +23 -23
  153. data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +11 -11
  154. data/spec/lib/protobuf/rpc/middleware/statsd_spec.rb +6 -6
  155. data/spec/lib/protobuf/rpc/servers/http/server_spec.rb +47 -44
  156. data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +6 -6
  157. data/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +12 -10
  158. data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +11 -11
  159. data/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +7 -7
  160. data/spec/lib/protobuf/rpc/service_directory_spec.rb +47 -49
  161. data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +8 -25
  162. data/spec/lib/protobuf/rpc/service_filters_spec.rb +102 -69
  163. data/spec/lib/protobuf/rpc/service_spec.rb +37 -36
  164. data/spec/lib/protobuf/rpc/stat_spec.rb +7 -9
  165. data/spec/lib/protobuf/varint_spec.rb +29 -0
  166. data/spec/lib/protobuf_spec.rb +55 -28
  167. data/spec/spec_helper.rb +12 -27
  168. data/spec/support/all.rb +0 -1
  169. data/spec/support/packed_field.rb +4 -3
  170. data/spec/support/{test → protos}/all_types.data.bin +0 -0
  171. data/spec/support/{test → protos}/all_types.data.txt +0 -0
  172. data/spec/support/{test → protos}/enum.pb.rb +8 -4
  173. data/spec/support/{test → protos}/enum.proto +4 -1
  174. data/spec/support/{test → protos}/extreme_values.data.bin +0 -0
  175. data/spec/support/protos/google_unittest.bin +0 -0
  176. data/spec/support/protos/google_unittest.pb.rb +798 -0
  177. data/spec/support/{test → protos}/google_unittest.proto +237 -66
  178. data/spec/support/protos/google_unittest_custom_options.bin +0 -0
  179. data/spec/support/protos/google_unittest_custom_options.pb.rb +268 -0
  180. data/spec/support/protos/google_unittest_custom_options.proto +424 -0
  181. data/spec/support/protos/google_unittest_import.pb.rb +55 -0
  182. data/spec/support/{test → protos}/google_unittest_import.proto +19 -10
  183. data/spec/support/protos/google_unittest_import_public.pb.rb +31 -0
  184. data/spec/support/{test → protos}/google_unittest_import_public.proto +8 -5
  185. data/spec/support/{test → protos}/multi_field_extensions.pb.rb +5 -2
  186. data/spec/support/{test → protos}/multi_field_extensions.proto +2 -0
  187. data/spec/support/{test → protos}/resource.pb.rb +47 -11
  188. data/spec/support/{test → protos}/resource.proto +24 -1
  189. data/spec/support/resource_service.rb +23 -0
  190. data/spec/support/server.rb +32 -61
  191. metadata +119 -59
  192. data/lib/protobuf/deprecator.rb +0 -42
  193. data/lib/protobuf/logger.rb +0 -93
  194. data/lib/protobuf/rpc/connector.rb +0 -21
  195. data/lib/protobuf/rpc/connectors/common.rb +0 -172
  196. data/spec/data/data.bin +0 -3
  197. data/spec/data/types.bin +0 -0
  198. data/spec/lib/protobuf/logger_spec.rb +0 -145
  199. data/spec/lib/protobuf/rpc/connector_spec.rb +0 -26
  200. data/spec/lib/protobuf/rpc/connectors/common_spec.rb +0 -170
  201. data/spec/support/test/defaults.pb.rb +0 -25
  202. data/spec/support/test/defaults.proto +0 -9
  203. data/spec/support/test/extended.pb.rb +0 -22
  204. data/spec/support/test/extended.proto +0 -10
  205. data/spec/support/test/google_unittest.pb.rb +0 -543
  206. data/spec/support/test/google_unittest_import.pb.rb +0 -37
  207. data/spec/support/test/google_unittest_import_public.pb.rb +0 -8
  208. data/spec/support/test/resource_service.rb +0 -26
  209. data/spec/support/tolerance_matcher.rb +0 -40
@@ -1,6 +1,6 @@
1
1
  // Protocol Buffers - Google's data interchange format
2
2
  // Copyright 2008 Google Inc. All rights reserved.
3
- // http://code.google.com/p/protobuf/
3
+ // https://developers.google.com/protocol-buffers/
4
4
  //
5
5
  // Redistribution and use in source and binary forms, with or without
6
6
  // modification, are permitted provided that the following conditions are
@@ -34,12 +34,28 @@
34
34
  //
35
35
  // A proto file we will use for unit testing.
36
36
 
37
- import "test/google_unittest_import.proto";
37
+ syntax = "proto2";
38
+
39
+ // Some generic_services option(s) added automatically.
40
+ // See: http://go/proto2-generic-services-default
41
+ option cc_generic_services = true; // auto-added
42
+ option java_generic_services = true; // auto-added
43
+ option py_generic_services = true; // auto-added
44
+ option cc_enable_arenas = true;
45
+
46
+ import "protos/google_unittest_import.proto";
38
47
 
39
48
  // We don't put this in a package within proto2 because we need to make sure
40
49
  // that the generated code doesn't depend on being in the proto2 namespace.
41
- // In test_util.h we do "using namespace unittest = google_unittest".
42
- package googleUnittest;
50
+ // In test_util.h we do "using namespace unittest = protobuf_unittest".
51
+ package protobuf_unittest;
52
+
53
+ // Protos optimized for SPEED use a strict superset of the generated code
54
+ // of equivalent ones optimized for CODE_SIZE, so we should optimize all our
55
+ // tests for speed unless explicitly testing code size optimization.
56
+ option optimize_for = SPEED;
57
+
58
+ option java_outer_classname = "UnittestProto";
43
59
 
44
60
  // This proto includes every type of field in both singular and repeated
45
61
  // forms.
@@ -55,6 +71,7 @@ message TestAllTypes {
55
71
  FOO = 1;
56
72
  BAR = 2;
57
73
  BAZ = 3;
74
+ NEG = -1; // Intentionally negative.
58
75
  }
59
76
 
60
77
  // Singular
@@ -74,27 +91,26 @@ message TestAllTypes {
74
91
  optional string optional_string = 14;
75
92
  optional bytes optional_bytes = 15;
76
93
 
77
- // TODO: Support groups
78
- //optional group OptionalGroup = 16 {
79
- // optional int32 a = 17;
80
- //}
94
+ optional group OptionalGroup = 16 {
95
+ optional int32 a = 17;
96
+ }
81
97
 
82
98
  optional NestedMessage optional_nested_message = 18;
83
99
  optional ForeignMessage optional_foreign_message = 19;
84
- optional googleUnittestImport.ImportMessage optional_import_message = 20;
100
+ optional protobuf_unittest_import.ImportMessage optional_import_message = 20;
85
101
 
86
102
  optional NestedEnum optional_nested_enum = 21;
87
103
  optional ForeignEnum optional_foreign_enum = 22;
88
- optional googleUnittestImport.ImportEnum optional_import_enum = 23;
104
+ optional protobuf_unittest_import.ImportEnum optional_import_enum = 23;
89
105
 
90
106
  optional string optional_string_piece = 24 [ctype=STRING_PIECE];
91
107
  optional string optional_cord = 25 [ctype=CORD];
92
108
 
93
109
  // Defined in unittest_import_public.proto
94
- optional googleUnittestImport.PublicImportMessage
110
+ optional protobuf_unittest_import.PublicImportMessage
95
111
  optional_public_import_message = 26;
96
112
 
97
- optional NestedMessage optional_lazy_message = 27; // [lazy=true];
113
+ optional NestedMessage optional_lazy_message = 27 [lazy=true];
98
114
 
99
115
  // Repeated
100
116
  repeated int32 repeated_int32 = 31;
@@ -113,23 +129,22 @@ message TestAllTypes {
113
129
  repeated string repeated_string = 44;
114
130
  repeated bytes repeated_bytes = 45;
115
131
 
116
- // TODO: Support groups
117
- //repeated group RepeatedGroup = 46 {
118
- // optional int32 a = 47;
119
- //}
132
+ repeated group RepeatedGroup = 46 {
133
+ optional int32 a = 47;
134
+ }
120
135
 
121
136
  repeated NestedMessage repeated_nested_message = 48;
122
137
  repeated ForeignMessage repeated_foreign_message = 49;
123
- repeated googleUnittestImport.ImportMessage repeated_import_message = 50;
138
+ repeated protobuf_unittest_import.ImportMessage repeated_import_message = 50;
124
139
 
125
140
  repeated NestedEnum repeated_nested_enum = 51;
126
141
  repeated ForeignEnum repeated_foreign_enum = 52;
127
- repeated googleUnittestImport.ImportEnum repeated_import_enum = 53;
142
+ repeated protobuf_unittest_import.ImportEnum repeated_import_enum = 53;
128
143
 
129
144
  repeated string repeated_string_piece = 54 [ctype=STRING_PIECE];
130
145
  repeated string repeated_cord = 55 [ctype=CORD];
131
146
 
132
- repeated NestedMessage repeated_lazy_message = 57; // [lazy=true];
147
+ repeated NestedMessage repeated_lazy_message = 57 [lazy=true];
133
148
 
134
149
  // Singular with defaults
135
150
  optional int32 default_int32 = 61 [default = 41 ];
@@ -150,11 +165,26 @@ message TestAllTypes {
150
165
 
151
166
  optional NestedEnum default_nested_enum = 81 [default = BAR ];
152
167
  optional ForeignEnum default_foreign_enum = 82 [default = FOREIGN_BAR];
153
- optional googleUnittestImport.ImportEnum
168
+ optional protobuf_unittest_import.ImportEnum
154
169
  default_import_enum = 83 [default = IMPORT_BAR];
155
170
 
156
171
  optional string default_string_piece = 84 [ctype=STRING_PIECE,default="abc"];
157
172
  optional string default_cord = 85 [ctype=CORD,default="123"];
173
+
174
+ // For oneof test
175
+ oneof oneof_field {
176
+ uint32 oneof_uint32 = 111;
177
+ NestedMessage oneof_nested_message = 112;
178
+ string oneof_string = 113;
179
+ bytes oneof_bytes = 114;
180
+ }
181
+ }
182
+
183
+ // This proto includes a recusively nested message.
184
+ message NestedTestAllTypes {
185
+ optional NestedTestAllTypes child = 1;
186
+ optional TestAllTypes payload = 2;
187
+ repeated NestedTestAllTypes repeated_child = 3;
158
188
  }
159
189
 
160
190
  message TestDeprecatedFields {
@@ -173,6 +203,11 @@ enum ForeignEnum {
173
203
  FOREIGN_BAZ = 6;
174
204
  }
175
205
 
206
+ message TestReservedFields {
207
+ reserved 2, 15, 9 to 11;
208
+ reserved "bar", "baz";
209
+ }
210
+
176
211
  message TestAllExtensions {
177
212
  extensions 1 to max;
178
213
  }
@@ -195,29 +230,28 @@ extend TestAllExtensions {
195
230
  optional string optional_string_extension = 14;
196
231
  optional bytes optional_bytes_extension = 15;
197
232
 
198
- // TODO: Support groups
199
- //optional group OptionalGroup_extension = 16 {
200
- // optional int32 a = 17;
201
- //}
233
+ optional group OptionalGroup_extension = 16 {
234
+ optional int32 a = 17;
235
+ }
202
236
 
203
237
  optional TestAllTypes.NestedMessage optional_nested_message_extension = 18;
204
238
  optional ForeignMessage optional_foreign_message_extension = 19;
205
- optional googleUnittestImport.ImportMessage
239
+ optional protobuf_unittest_import.ImportMessage
206
240
  optional_import_message_extension = 20;
207
241
 
208
242
  optional TestAllTypes.NestedEnum optional_nested_enum_extension = 21;
209
243
  optional ForeignEnum optional_foreign_enum_extension = 22;
210
- optional googleUnittestImport.ImportEnum
244
+ optional protobuf_unittest_import.ImportEnum
211
245
  optional_import_enum_extension = 23;
212
246
 
213
247
  optional string optional_string_piece_extension = 24 [ctype=STRING_PIECE];
214
248
  optional string optional_cord_extension = 25 [ctype=CORD];
215
249
 
216
- optional googleUnittestImport.PublicImportMessage
250
+ optional protobuf_unittest_import.PublicImportMessage
217
251
  optional_public_import_message_extension = 26;
218
252
 
219
253
  optional TestAllTypes.NestedMessage
220
- optional_lazy_message_extension = 27; // [lazy=true];
254
+ optional_lazy_message_extension = 27 [lazy=true];
221
255
 
222
256
  // Repeated
223
257
  repeated int32 repeated_int32_extension = 31;
@@ -236,26 +270,25 @@ extend TestAllExtensions {
236
270
  repeated string repeated_string_extension = 44;
237
271
  repeated bytes repeated_bytes_extension = 45;
238
272
 
239
- // TODO: Support groups
240
- //repeated group RepeatedGroup_extension = 46 {
241
- // optional int32 a = 47;
242
- //}
273
+ repeated group RepeatedGroup_extension = 46 {
274
+ optional int32 a = 47;
275
+ }
243
276
 
244
277
  repeated TestAllTypes.NestedMessage repeated_nested_message_extension = 48;
245
278
  repeated ForeignMessage repeated_foreign_message_extension = 49;
246
- repeated googleUnittestImport.ImportMessage
279
+ repeated protobuf_unittest_import.ImportMessage
247
280
  repeated_import_message_extension = 50;
248
281
 
249
282
  repeated TestAllTypes.NestedEnum repeated_nested_enum_extension = 51;
250
283
  repeated ForeignEnum repeated_foreign_enum_extension = 52;
251
- repeated googleUnittestImport.ImportEnum
284
+ repeated protobuf_unittest_import.ImportEnum
252
285
  repeated_import_enum_extension = 53;
253
286
 
254
287
  repeated string repeated_string_piece_extension = 54 [ctype=STRING_PIECE];
255
288
  repeated string repeated_cord_extension = 55 [ctype=CORD];
256
289
 
257
290
  repeated TestAllTypes.NestedMessage
258
- repeated_lazy_message_extension = 57; // [lazy=true];
291
+ repeated_lazy_message_extension = 57 [lazy=true];
259
292
 
260
293
  // Singular with defaults
261
294
  optional int32 default_int32_extension = 61 [default = 41 ];
@@ -278,12 +311,18 @@ extend TestAllExtensions {
278
311
  default_nested_enum_extension = 81 [default = BAR];
279
312
  optional ForeignEnum
280
313
  default_foreign_enum_extension = 82 [default = FOREIGN_BAR];
281
- optional googleUnittestImport.ImportEnum
314
+ optional protobuf_unittest_import.ImportEnum
282
315
  default_import_enum_extension = 83 [default = IMPORT_BAR];
283
316
 
284
317
  optional string default_string_piece_extension = 84 [ctype=STRING_PIECE,
285
318
  default="abc"];
286
319
  optional string default_cord_extension = 85 [ctype=CORD, default="123"];
320
+
321
+ // For oneof test
322
+ optional uint32 oneof_uint32_extension = 111;
323
+ optional TestAllTypes.NestedMessage oneof_nested_message_extension = 112;
324
+ optional string oneof_string_extension = 113;
325
+ optional bytes oneof_bytes_extension = 114;
287
326
  }
288
327
 
289
328
  message TestNestedExtension {
@@ -291,6 +330,16 @@ message TestNestedExtension {
291
330
  // Check for bug where string extensions declared in tested scope did not
292
331
  // compile.
293
332
  optional string test = 1002 [default="test"];
333
+ // Used to test if generated extension name is correct when there are
334
+ // underscores.
335
+ optional string nested_string_extension = 1003;
336
+ }
337
+ }
338
+
339
+ message TestMoreNestedExtension {
340
+ extend TestAllExtensions {
341
+ // Check that duplicate field names in different namespaces work
342
+ optional string test = 1004 [default="a different test"];
294
343
  }
295
344
  }
296
345
 
@@ -395,22 +444,21 @@ message TestMutualRecursionB {
395
444
  }
396
445
 
397
446
  // Test that groups have disjoint field numbers from their siblings and
398
- // parents. This is NOT possible in proto1; only proto2. When attempting
447
+ // parents. This is NOT possible in proto1; only google.protobuf. When attempting
399
448
  // to compile with proto1, this will emit an error; so we only include it
400
- // in google_unittest_proto.
449
+ // in protobuf_unittest_proto.
401
450
  message TestDupFieldNumber { // NO_PROTO1
402
451
  optional int32 a = 1; // NO_PROTO1
403
- // TODO: Support groups
404
- //optional group Foo = 2 { optional int32 a = 1; } // NO_PROTO1
405
- //optional group Bar = 3 { optional int32 a = 1; } // NO_PROTO1
452
+ optional group Foo = 2 { optional int32 a = 1; } // NO_PROTO1
453
+ optional group Bar = 3 { optional int32 a = 1; } // NO_PROTO1
406
454
  } // NO_PROTO1
407
455
 
408
456
  // Additional messages for testing lazy fields.
409
457
  message TestEagerMessage {
410
- optional TestAllTypes sub_message = 1; // [lazy=false];
458
+ optional TestAllTypes sub_message = 1 [lazy=false];
411
459
  }
412
460
  message TestLazyMessage {
413
- optional TestAllTypes sub_message = 1; // [lazy=true];
461
+ optional TestAllTypes sub_message = 1 [lazy=true];
414
462
  }
415
463
 
416
464
  // Needed for a Python test.
@@ -424,15 +472,15 @@ message TestNestedMessageHasBits {
424
472
 
425
473
 
426
474
  // Test an enum that has multiple values with the same number.
427
- // TODO: update and test this when the new compiler is released
428
- // enum TestEnumWithDupValue {
429
- // option allow_alias = true;
430
- // FOO1 = 1;
431
- // BAR1 = 2;
432
- // BAZ = 3;
433
- // FOO2 = 1;
434
- // BAR2 = 2;
435
- // }
475
+ enum TestEnumWithDupValue {
476
+ option allow_alias = true;
477
+
478
+ FOO1 = 1;
479
+ BAR1 = 2;
480
+ BAZ = 3;
481
+ FOO2 = 1;
482
+ BAR2 = 2;
483
+ }
436
484
 
437
485
  // Test an enum with large, unordered values.
438
486
  enum TestSparseEnum {
@@ -472,6 +520,15 @@ message TestFieldOrderings {
472
520
  optional int64 my_int = 1;
473
521
  extensions 12 to 100;
474
522
  optional float my_float = 101;
523
+ message NestedMessage {
524
+ optional int64 oo = 2;
525
+ // The field name "b" fails to compile in proto1 because it conflicts with
526
+ // a local variable named "b" in one of the generated methods. Doh.
527
+ // This file needs to compile in proto1 to test backwards-compatibility.
528
+ optional int32 bb = 1;
529
+ }
530
+
531
+ optional NestedMessage optional_nested_message = 200;
475
532
  }
476
533
 
477
534
 
@@ -527,6 +584,7 @@ message TestExtremeDefaultValues {
527
584
  default="ab\000c"];
528
585
  optional string cord_with_zero = 26 [ctype=CORD,
529
586
  default="12\0003"];
587
+ optional string replacement_string = 27 [default="${unknown}"];
530
588
  }
531
589
 
532
590
  message SparseEnumMessage {
@@ -550,6 +608,100 @@ message MoreBytes {
550
608
  repeated bytes data = 1;
551
609
  }
552
610
 
611
+ // Test int32, uint32, int64, uint64, and bool are all compatible
612
+ message Int32Message {
613
+ optional int32 data = 1;
614
+ }
615
+
616
+ message Uint32Message {
617
+ optional uint32 data = 1;
618
+ }
619
+
620
+ message Int64Message {
621
+ optional int64 data = 1;
622
+ }
623
+
624
+ message Uint64Message {
625
+ optional uint64 data = 1;
626
+ }
627
+
628
+ message BoolMessage {
629
+ optional bool data = 1;
630
+ }
631
+
632
+ // Test oneofs.
633
+ message TestOneof {
634
+ oneof foo {
635
+ int32 foo_int = 1;
636
+ string foo_string = 2;
637
+ TestAllTypes foo_message = 3;
638
+ group FooGroup = 4 {
639
+ optional int32 a = 5;
640
+ optional string b = 6;
641
+ }
642
+ }
643
+ }
644
+
645
+ message TestOneofBackwardsCompatible {
646
+ optional int32 foo_int = 1;
647
+ optional string foo_string = 2;
648
+ optional TestAllTypes foo_message = 3;
649
+ optional group FooGroup = 4 {
650
+ optional int32 a = 5;
651
+ optional string b = 6;
652
+ }
653
+ }
654
+
655
+ message TestOneof2 {
656
+ oneof foo {
657
+ int32 foo_int = 1;
658
+ string foo_string = 2;
659
+ string foo_cord = 3 [ctype=CORD];
660
+ string foo_string_piece = 4 [ctype=STRING_PIECE];
661
+ bytes foo_bytes = 5;
662
+ NestedEnum foo_enum = 6;
663
+ NestedMessage foo_message = 7;
664
+ group FooGroup = 8 {
665
+ optional int32 a = 9;
666
+ optional string b = 10;
667
+ }
668
+ NestedMessage foo_lazy_message = 11 [lazy=true];
669
+ }
670
+
671
+ oneof bar {
672
+ int32 bar_int = 12 [default = 5];
673
+ string bar_string = 13 [default = "STRING"];
674
+ string bar_cord = 14 [ctype=CORD, default = "CORD"];
675
+ string bar_string_piece = 15 [ctype=STRING_PIECE, default = "SPIECE"];
676
+ bytes bar_bytes = 16 [default = "BYTES"];
677
+ NestedEnum bar_enum = 17 [default = BAR];
678
+ }
679
+
680
+ optional int32 baz_int = 18;
681
+ optional string baz_string = 19 [default = "BAZ"];
682
+
683
+ message NestedMessage {
684
+ optional int64 qux_int = 1;
685
+ repeated int32 corge_int = 2;
686
+ }
687
+
688
+ enum NestedEnum {
689
+ FOO = 1;
690
+ BAR = 2;
691
+ BAZ = 3;
692
+ }
693
+ }
694
+
695
+ message TestRequiredOneof {
696
+ oneof foo {
697
+ int32 foo_int = 1;
698
+ string foo_string = 2;
699
+ NestedMessage foo_message = 3;
700
+ }
701
+ message NestedMessage {
702
+ required double required_double = 1;
703
+ }
704
+ }
553
705
 
554
706
  // Test messages for packed fields
555
707
 
@@ -610,6 +762,27 @@ extend TestPackedExtensions {
610
762
  repeated ForeignEnum packed_enum_extension = 103 [packed = true];
611
763
  }
612
764
 
765
+ message TestUnpackedExtensions {
766
+ extensions 1 to max;
767
+ }
768
+
769
+ extend TestUnpackedExtensions {
770
+ repeated int32 unpacked_int32_extension = 90 [packed = false];
771
+ repeated int64 unpacked_int64_extension = 91 [packed = false];
772
+ repeated uint32 unpacked_uint32_extension = 92 [packed = false];
773
+ repeated uint64 unpacked_uint64_extension = 93 [packed = false];
774
+ repeated sint32 unpacked_sint32_extension = 94 [packed = false];
775
+ repeated sint64 unpacked_sint64_extension = 95 [packed = false];
776
+ repeated fixed32 unpacked_fixed32_extension = 96 [packed = false];
777
+ repeated fixed64 unpacked_fixed64_extension = 97 [packed = false];
778
+ repeated sfixed32 unpacked_sfixed32_extension = 98 [packed = false];
779
+ repeated sfixed64 unpacked_sfixed64_extension = 99 [packed = false];
780
+ repeated float unpacked_float_extension = 100 [packed = false];
781
+ repeated double unpacked_double_extension = 101 [packed = false];
782
+ repeated bool unpacked_bool_extension = 102 [packed = false];
783
+ repeated ForeignEnum unpacked_enum_extension = 103 [packed = false];
784
+ }
785
+
613
786
  // Used by ExtensionSetTest/DynamicExtensions. The test actually builds
614
787
  // a set of extensions to TestAllExtensions dynamically, based on the fields
615
788
  // of this message type.
@@ -663,26 +836,24 @@ message TestParsingMerge {
663
836
  repeated TestAllTypes field1 = 1;
664
837
  repeated TestAllTypes field2 = 2;
665
838
  repeated TestAllTypes field3 = 3;
666
- // TODO: Support groups
667
- //repeated group Group1 = 10 {
668
- // optional TestAllTypes field1 = 11;
669
- //}
670
- //repeated group Group2 = 20 {
671
- // optional TestAllTypes field1 = 21;
672
- //}
839
+ repeated group Group1 = 10 {
840
+ optional TestAllTypes field1 = 11;
841
+ }
842
+ repeated group Group2 = 20 {
843
+ optional TestAllTypes field1 = 21;
844
+ }
673
845
  repeated TestAllTypes ext1 = 1000;
674
846
  repeated TestAllTypes ext2 = 1001;
675
847
  }
676
848
  required TestAllTypes required_all_types = 1;
677
849
  optional TestAllTypes optional_all_types = 2;
678
850
  repeated TestAllTypes repeated_all_types = 3;
679
- // TODO: Support groups
680
- //optional group OptionalGroup = 10 {
681
- // optional TestAllTypes optional_group_all_types = 11;
682
- //}
683
- //repeated group RepeatedGroup = 20 {
684
- // optional TestAllTypes repeated_group_all_types = 21;
685
- //}
851
+ optional group OptionalGroup = 10 {
852
+ optional TestAllTypes optional_group_all_types = 11;
853
+ }
854
+ repeated group RepeatedGroup = 20 {
855
+ optional TestAllTypes repeated_group_all_types = 21;
856
+ }
686
857
  extensions 1000 to max;
687
858
  extend TestParsingMerge {
688
859
  optional TestAllTypes optional_ext = 1000;