protobuffy 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.travis.yml +12 -0
  4. data/.yardopts +5 -0
  5. data/CHANGES.md +261 -0
  6. data/CONTRIBUTING.md +16 -0
  7. data/Gemfile +3 -0
  8. data/LICENSE.txt +14 -0
  9. data/README.md +58 -0
  10. data/Rakefile +61 -0
  11. data/bin/protoc-gen-ruby +17 -0
  12. data/bin/rpc_server +4 -0
  13. data/examples/bin/reverse-client-http +4 -0
  14. data/examples/bin/reverse-client-socket +4 -0
  15. data/examples/bin/reverse-client-zmq +4 -0
  16. data/examples/config.ru +6 -0
  17. data/examples/definitions/example/reverse.proto +12 -0
  18. data/examples/lib/example/reverse-client.rb +23 -0
  19. data/examples/lib/example/reverse-service.rb +9 -0
  20. data/examples/lib/example/reverse.pb.rb +36 -0
  21. data/lib/protobuf.rb +106 -0
  22. data/lib/protobuf/cli.rb +249 -0
  23. data/lib/protobuf/code_generator.rb +41 -0
  24. data/lib/protobuf/decoder.rb +74 -0
  25. data/lib/protobuf/deprecator.rb +42 -0
  26. data/lib/protobuf/descriptors.rb +3 -0
  27. data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +52 -0
  28. data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +249 -0
  29. data/lib/protobuf/encoder.rb +62 -0
  30. data/lib/protobuf/enum.rb +319 -0
  31. data/lib/protobuf/exceptions.rb +9 -0
  32. data/lib/protobuf/field.rb +74 -0
  33. data/lib/protobuf/field/base_field.rb +280 -0
  34. data/lib/protobuf/field/bool_field.rb +53 -0
  35. data/lib/protobuf/field/bytes_field.rb +81 -0
  36. data/lib/protobuf/field/double_field.rb +26 -0
  37. data/lib/protobuf/field/enum_field.rb +57 -0
  38. data/lib/protobuf/field/field_array.rb +86 -0
  39. data/lib/protobuf/field/fixed32_field.rb +25 -0
  40. data/lib/protobuf/field/fixed64_field.rb +29 -0
  41. data/lib/protobuf/field/float_field.rb +38 -0
  42. data/lib/protobuf/field/int32_field.rb +22 -0
  43. data/lib/protobuf/field/int64_field.rb +22 -0
  44. data/lib/protobuf/field/integer_field.rb +24 -0
  45. data/lib/protobuf/field/message_field.rb +66 -0
  46. data/lib/protobuf/field/sfixed32_field.rb +28 -0
  47. data/lib/protobuf/field/sfixed64_field.rb +29 -0
  48. data/lib/protobuf/field/signed_integer_field.rb +30 -0
  49. data/lib/protobuf/field/sint32_field.rb +22 -0
  50. data/lib/protobuf/field/sint64_field.rb +22 -0
  51. data/lib/protobuf/field/string_field.rb +35 -0
  52. data/lib/protobuf/field/uint32_field.rb +22 -0
  53. data/lib/protobuf/field/uint64_field.rb +22 -0
  54. data/lib/protobuf/field/varint_field.rb +68 -0
  55. data/lib/protobuf/generators/base.rb +71 -0
  56. data/lib/protobuf/generators/enum_generator.rb +42 -0
  57. data/lib/protobuf/generators/extension_generator.rb +28 -0
  58. data/lib/protobuf/generators/field_generator.rb +132 -0
  59. data/lib/protobuf/generators/file_generator.rb +140 -0
  60. data/lib/protobuf/generators/group_generator.rb +113 -0
  61. data/lib/protobuf/generators/message_generator.rb +99 -0
  62. data/lib/protobuf/generators/printable.rb +161 -0
  63. data/lib/protobuf/generators/service_generator.rb +27 -0
  64. data/lib/protobuf/http.rb +20 -0
  65. data/lib/protobuf/lifecycle.rb +46 -0
  66. data/lib/protobuf/logger.rb +86 -0
  67. data/lib/protobuf/message.rb +182 -0
  68. data/lib/protobuf/message/fields.rb +122 -0
  69. data/lib/protobuf/message/serialization.rb +84 -0
  70. data/lib/protobuf/optionable.rb +23 -0
  71. data/lib/protobuf/rpc/buffer.rb +79 -0
  72. data/lib/protobuf/rpc/client.rb +168 -0
  73. data/lib/protobuf/rpc/connector.rb +21 -0
  74. data/lib/protobuf/rpc/connectors/base.rb +54 -0
  75. data/lib/protobuf/rpc/connectors/common.rb +172 -0
  76. data/lib/protobuf/rpc/connectors/http.rb +90 -0
  77. data/lib/protobuf/rpc/connectors/socket.rb +73 -0
  78. data/lib/protobuf/rpc/connectors/zmq.rb +205 -0
  79. data/lib/protobuf/rpc/dynamic_discovery.pb.rb +47 -0
  80. data/lib/protobuf/rpc/env.rb +58 -0
  81. data/lib/protobuf/rpc/error.rb +28 -0
  82. data/lib/protobuf/rpc/error/client_error.rb +31 -0
  83. data/lib/protobuf/rpc/error/server_error.rb +43 -0
  84. data/lib/protobuf/rpc/middleware.rb +25 -0
  85. data/lib/protobuf/rpc/middleware/exception_handler.rb +36 -0
  86. data/lib/protobuf/rpc/middleware/logger.rb +91 -0
  87. data/lib/protobuf/rpc/middleware/request_decoder.rb +83 -0
  88. data/lib/protobuf/rpc/middleware/response_encoder.rb +88 -0
  89. data/lib/protobuf/rpc/middleware/runner.rb +18 -0
  90. data/lib/protobuf/rpc/rpc.pb.rb +53 -0
  91. data/lib/protobuf/rpc/server.rb +39 -0
  92. data/lib/protobuf/rpc/servers/http/server.rb +101 -0
  93. data/lib/protobuf/rpc/servers/http_runner.rb +34 -0
  94. data/lib/protobuf/rpc/servers/socket/server.rb +113 -0
  95. data/lib/protobuf/rpc/servers/socket/worker.rb +56 -0
  96. data/lib/protobuf/rpc/servers/socket_runner.rb +34 -0
  97. data/lib/protobuf/rpc/servers/zmq/broker.rb +155 -0
  98. data/lib/protobuf/rpc/servers/zmq/server.rb +313 -0
  99. data/lib/protobuf/rpc/servers/zmq/util.rb +47 -0
  100. data/lib/protobuf/rpc/servers/zmq/worker.rb +105 -0
  101. data/lib/protobuf/rpc/servers/zmq_runner.rb +51 -0
  102. data/lib/protobuf/rpc/service.rb +179 -0
  103. data/lib/protobuf/rpc/service_directory.rb +245 -0
  104. data/lib/protobuf/rpc/service_dispatcher.rb +46 -0
  105. data/lib/protobuf/rpc/service_filters.rb +273 -0
  106. data/lib/protobuf/rpc/stat.rb +148 -0
  107. data/lib/protobuf/socket.rb +22 -0
  108. data/lib/protobuf/tasks.rb +1 -0
  109. data/lib/protobuf/tasks/compile.rake +61 -0
  110. data/lib/protobuf/version.rb +3 -0
  111. data/lib/protobuf/wire_type.rb +10 -0
  112. data/lib/protobuf/zmq.rb +21 -0
  113. data/proto/dynamic_discovery.proto +44 -0
  114. data/proto/google/protobuf/compiler/plugin.proto +147 -0
  115. data/proto/google/protobuf/descriptor.proto +620 -0
  116. data/proto/rpc.proto +62 -0
  117. data/protobuffy.gemspec +37 -0
  118. data/spec/benchmark/tasks.rb +113 -0
  119. data/spec/bin/protoc-gen-ruby_spec.rb +18 -0
  120. data/spec/data/data.bin +3 -0
  121. data/spec/data/types.bin +0 -0
  122. data/spec/encoding/all_types_spec.rb +91 -0
  123. data/spec/encoding/extreme_values_spec.rb +0 -0
  124. data/spec/functional/socket_server_spec.rb +59 -0
  125. data/spec/functional/zmq_server_spec.rb +103 -0
  126. data/spec/lib/protobuf/cli_spec.rb +267 -0
  127. data/spec/lib/protobuf/code_generator_spec.rb +60 -0
  128. data/spec/lib/protobuf/enum_spec.rb +239 -0
  129. data/spec/lib/protobuf/field/int32_field_spec.rb +7 -0
  130. data/spec/lib/protobuf/field/string_field_spec.rb +46 -0
  131. data/spec/lib/protobuf/field_spec.rb +194 -0
  132. data/spec/lib/protobuf/generators/base_spec.rb +87 -0
  133. data/spec/lib/protobuf/generators/enum_generator_spec.rb +68 -0
  134. data/spec/lib/protobuf/generators/extension_generator_spec.rb +43 -0
  135. data/spec/lib/protobuf/generators/field_generator_spec.rb +99 -0
  136. data/spec/lib/protobuf/generators/file_generator_spec.rb +29 -0
  137. data/spec/lib/protobuf/generators/message_generator_spec.rb +0 -0
  138. data/spec/lib/protobuf/generators/service_generator_spec.rb +43 -0
  139. data/spec/lib/protobuf/lifecycle_spec.rb +89 -0
  140. data/spec/lib/protobuf/logger_spec.rb +136 -0
  141. data/spec/lib/protobuf/message_spec.rb +368 -0
  142. data/spec/lib/protobuf/optionable_spec.rb +46 -0
  143. data/spec/lib/protobuf/rpc/client_spec.rb +66 -0
  144. data/spec/lib/protobuf/rpc/connector_spec.rb +26 -0
  145. data/spec/lib/protobuf/rpc/connectors/base_spec.rb +50 -0
  146. data/spec/lib/protobuf/rpc/connectors/common_spec.rb +170 -0
  147. data/spec/lib/protobuf/rpc/connectors/connector_spec.rb +13 -0
  148. data/spec/lib/protobuf/rpc/connectors/http_spec.rb +61 -0
  149. data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +24 -0
  150. data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +129 -0
  151. data/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +62 -0
  152. data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +49 -0
  153. data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +115 -0
  154. data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +75 -0
  155. data/spec/lib/protobuf/rpc/servers/http/server_spec.rb +104 -0
  156. data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +38 -0
  157. data/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +41 -0
  158. data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +55 -0
  159. data/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +35 -0
  160. data/spec/lib/protobuf/rpc/service_directory_spec.rb +295 -0
  161. data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +52 -0
  162. data/spec/lib/protobuf/rpc/service_filters_spec.rb +484 -0
  163. data/spec/lib/protobuf/rpc/service_spec.rb +161 -0
  164. data/spec/lib/protobuf/rpc/stat_spec.rb +151 -0
  165. data/spec/lib/protobuf_spec.rb +78 -0
  166. data/spec/spec_helper.rb +57 -0
  167. data/spec/support/all.rb +7 -0
  168. data/spec/support/packed_field.rb +22 -0
  169. data/spec/support/server.rb +94 -0
  170. data/spec/support/test/all_types.data.bin +0 -0
  171. data/spec/support/test/all_types.data.txt +119 -0
  172. data/spec/support/test/defaults.pb.rb +25 -0
  173. data/spec/support/test/defaults.proto +9 -0
  174. data/spec/support/test/enum.pb.rb +59 -0
  175. data/spec/support/test/enum.proto +34 -0
  176. data/spec/support/test/extended.pb.rb +22 -0
  177. data/spec/support/test/extended.proto +10 -0
  178. data/spec/support/test/extreme_values.data.bin +0 -0
  179. data/spec/support/test/google_unittest.pb.rb +543 -0
  180. data/spec/support/test/google_unittest.proto +713 -0
  181. data/spec/support/test/google_unittest_import.pb.rb +37 -0
  182. data/spec/support/test/google_unittest_import.proto +64 -0
  183. data/spec/support/test/google_unittest_import_public.pb.rb +8 -0
  184. data/spec/support/test/google_unittest_import_public.proto +38 -0
  185. data/spec/support/test/multi_field_extensions.pb.rb +56 -0
  186. data/spec/support/test/multi_field_extensions.proto +33 -0
  187. data/spec/support/test/resource.pb.rb +117 -0
  188. data/spec/support/test/resource.proto +94 -0
  189. data/spec/support/test/resource_service.rb +26 -0
  190. data/spec/support/test_app_file.rb +2 -0
  191. data/spec/support/tolerance_matcher.rb +40 -0
  192. metadata +367 -0
@@ -0,0 +1,713 @@
1
+ // Protocol Buffers - Google's data interchange format
2
+ // Copyright 2008 Google Inc. All rights reserved.
3
+ // http://code.google.com/p/protobuf/
4
+ //
5
+ // Redistribution and use in source and binary forms, with or without
6
+ // modification, are permitted provided that the following conditions are
7
+ // met:
8
+ //
9
+ // * Redistributions of source code must retain the above copyright
10
+ // notice, this list of conditions and the following disclaimer.
11
+ // * Redistributions in binary form must reproduce the above
12
+ // copyright notice, this list of conditions and the following disclaimer
13
+ // in the documentation and/or other materials provided with the
14
+ // distribution.
15
+ // * Neither the name of Google Inc. nor the names of its
16
+ // contributors may be used to endorse or promote products derived from
17
+ // this software without specific prior written permission.
18
+ //
19
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
30
+
31
+ // Author: kenton@google.com (Kenton Varda)
32
+ // Based on original Protocol Buffers design by
33
+ // Sanjay Ghemawat, Jeff Dean, and others.
34
+ //
35
+ // A proto file we will use for unit testing.
36
+
37
+ import "test/google_unittest_import.proto";
38
+
39
+ // We don't put this in a package within proto2 because we need to make sure
40
+ // 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;
43
+
44
+ // This proto includes every type of field in both singular and repeated
45
+ // forms.
46
+ message TestAllTypes {
47
+ message NestedMessage {
48
+ // The field name "b" fails to compile in proto1 because it conflicts with
49
+ // a local variable named "b" in one of the generated methods. Doh.
50
+ // This file needs to compile in proto1 to test backwards-compatibility.
51
+ optional int32 bb = 1;
52
+ }
53
+
54
+ enum NestedEnum {
55
+ FOO = 1;
56
+ BAR = 2;
57
+ BAZ = 3;
58
+ }
59
+
60
+ // Singular
61
+ optional int32 optional_int32 = 1;
62
+ optional int64 optional_int64 = 2;
63
+ optional uint32 optional_uint32 = 3;
64
+ optional uint64 optional_uint64 = 4;
65
+ optional sint32 optional_sint32 = 5;
66
+ optional sint64 optional_sint64 = 6;
67
+ optional fixed32 optional_fixed32 = 7;
68
+ optional fixed64 optional_fixed64 = 8;
69
+ optional sfixed32 optional_sfixed32 = 9;
70
+ optional sfixed64 optional_sfixed64 = 10;
71
+ optional float optional_float = 11;
72
+ optional double optional_double = 12;
73
+ optional bool optional_bool = 13;
74
+ optional string optional_string = 14;
75
+ optional bytes optional_bytes = 15;
76
+
77
+ // TODO: Support groups
78
+ //optional group OptionalGroup = 16 {
79
+ // optional int32 a = 17;
80
+ //}
81
+
82
+ optional NestedMessage optional_nested_message = 18;
83
+ optional ForeignMessage optional_foreign_message = 19;
84
+ optional googleUnittestImport.ImportMessage optional_import_message = 20;
85
+
86
+ optional NestedEnum optional_nested_enum = 21;
87
+ optional ForeignEnum optional_foreign_enum = 22;
88
+ optional googleUnittestImport.ImportEnum optional_import_enum = 23;
89
+
90
+ optional string optional_string_piece = 24 [ctype=STRING_PIECE];
91
+ optional string optional_cord = 25 [ctype=CORD];
92
+
93
+ // Defined in unittest_import_public.proto
94
+ optional googleUnittestImport.PublicImportMessage
95
+ optional_public_import_message = 26;
96
+
97
+ optional NestedMessage optional_lazy_message = 27; // [lazy=true];
98
+
99
+ // Repeated
100
+ repeated int32 repeated_int32 = 31;
101
+ repeated int64 repeated_int64 = 32;
102
+ repeated uint32 repeated_uint32 = 33;
103
+ repeated uint64 repeated_uint64 = 34;
104
+ repeated sint32 repeated_sint32 = 35;
105
+ repeated sint64 repeated_sint64 = 36;
106
+ repeated fixed32 repeated_fixed32 = 37;
107
+ repeated fixed64 repeated_fixed64 = 38;
108
+ repeated sfixed32 repeated_sfixed32 = 39;
109
+ repeated sfixed64 repeated_sfixed64 = 40;
110
+ repeated float repeated_float = 41;
111
+ repeated double repeated_double = 42;
112
+ repeated bool repeated_bool = 43;
113
+ repeated string repeated_string = 44;
114
+ repeated bytes repeated_bytes = 45;
115
+
116
+ // TODO: Support groups
117
+ //repeated group RepeatedGroup = 46 {
118
+ // optional int32 a = 47;
119
+ //}
120
+
121
+ repeated NestedMessage repeated_nested_message = 48;
122
+ repeated ForeignMessage repeated_foreign_message = 49;
123
+ repeated googleUnittestImport.ImportMessage repeated_import_message = 50;
124
+
125
+ repeated NestedEnum repeated_nested_enum = 51;
126
+ repeated ForeignEnum repeated_foreign_enum = 52;
127
+ repeated googleUnittestImport.ImportEnum repeated_import_enum = 53;
128
+
129
+ repeated string repeated_string_piece = 54 [ctype=STRING_PIECE];
130
+ repeated string repeated_cord = 55 [ctype=CORD];
131
+
132
+ repeated NestedMessage repeated_lazy_message = 57; // [lazy=true];
133
+
134
+ // Singular with defaults
135
+ optional int32 default_int32 = 61 [default = 41 ];
136
+ optional int64 default_int64 = 62 [default = 42 ];
137
+ optional uint32 default_uint32 = 63 [default = 43 ];
138
+ optional uint64 default_uint64 = 64 [default = 44 ];
139
+ optional sint32 default_sint32 = 65 [default = -45 ];
140
+ optional sint64 default_sint64 = 66 [default = 46 ];
141
+ optional fixed32 default_fixed32 = 67 [default = 47 ];
142
+ optional fixed64 default_fixed64 = 68 [default = 48 ];
143
+ optional sfixed32 default_sfixed32 = 69 [default = 49 ];
144
+ optional sfixed64 default_sfixed64 = 70 [default = -50 ];
145
+ optional float default_float = 71 [default = 51.5 ];
146
+ optional double default_double = 72 [default = 52e3 ];
147
+ optional bool default_bool = 73 [default = true ];
148
+ optional string default_string = 74 [default = "hello"];
149
+ optional bytes default_bytes = 75 [default = "world"];
150
+
151
+ optional NestedEnum default_nested_enum = 81 [default = BAR ];
152
+ optional ForeignEnum default_foreign_enum = 82 [default = FOREIGN_BAR];
153
+ optional googleUnittestImport.ImportEnum
154
+ default_import_enum = 83 [default = IMPORT_BAR];
155
+
156
+ optional string default_string_piece = 84 [ctype=STRING_PIECE,default="abc"];
157
+ optional string default_cord = 85 [ctype=CORD,default="123"];
158
+ }
159
+
160
+ message TestDeprecatedFields {
161
+ optional int32 deprecated_int32 = 1 [deprecated=true];
162
+ }
163
+
164
+ // Define these after TestAllTypes to make sure the compiler can handle
165
+ // that.
166
+ message ForeignMessage {
167
+ optional int32 c = 1;
168
+ }
169
+
170
+ enum ForeignEnum {
171
+ FOREIGN_FOO = 4;
172
+ FOREIGN_BAR = 5;
173
+ FOREIGN_BAZ = 6;
174
+ }
175
+
176
+ message TestAllExtensions {
177
+ extensions 1 to max;
178
+ }
179
+
180
+ extend TestAllExtensions {
181
+ // Singular
182
+ optional int32 optional_int32_extension = 1;
183
+ optional int64 optional_int64_extension = 2;
184
+ optional uint32 optional_uint32_extension = 3;
185
+ optional uint64 optional_uint64_extension = 4;
186
+ optional sint32 optional_sint32_extension = 5;
187
+ optional sint64 optional_sint64_extension = 6;
188
+ optional fixed32 optional_fixed32_extension = 7;
189
+ optional fixed64 optional_fixed64_extension = 8;
190
+ optional sfixed32 optional_sfixed32_extension = 9;
191
+ optional sfixed64 optional_sfixed64_extension = 10;
192
+ optional float optional_float_extension = 11;
193
+ optional double optional_double_extension = 12;
194
+ optional bool optional_bool_extension = 13;
195
+ optional string optional_string_extension = 14;
196
+ optional bytes optional_bytes_extension = 15;
197
+
198
+ // TODO: Support groups
199
+ //optional group OptionalGroup_extension = 16 {
200
+ // optional int32 a = 17;
201
+ //}
202
+
203
+ optional TestAllTypes.NestedMessage optional_nested_message_extension = 18;
204
+ optional ForeignMessage optional_foreign_message_extension = 19;
205
+ optional googleUnittestImport.ImportMessage
206
+ optional_import_message_extension = 20;
207
+
208
+ optional TestAllTypes.NestedEnum optional_nested_enum_extension = 21;
209
+ optional ForeignEnum optional_foreign_enum_extension = 22;
210
+ optional googleUnittestImport.ImportEnum
211
+ optional_import_enum_extension = 23;
212
+
213
+ optional string optional_string_piece_extension = 24 [ctype=STRING_PIECE];
214
+ optional string optional_cord_extension = 25 [ctype=CORD];
215
+
216
+ optional googleUnittestImport.PublicImportMessage
217
+ optional_public_import_message_extension = 26;
218
+
219
+ optional TestAllTypes.NestedMessage
220
+ optional_lazy_message_extension = 27; // [lazy=true];
221
+
222
+ // Repeated
223
+ repeated int32 repeated_int32_extension = 31;
224
+ repeated int64 repeated_int64_extension = 32;
225
+ repeated uint32 repeated_uint32_extension = 33;
226
+ repeated uint64 repeated_uint64_extension = 34;
227
+ repeated sint32 repeated_sint32_extension = 35;
228
+ repeated sint64 repeated_sint64_extension = 36;
229
+ repeated fixed32 repeated_fixed32_extension = 37;
230
+ repeated fixed64 repeated_fixed64_extension = 38;
231
+ repeated sfixed32 repeated_sfixed32_extension = 39;
232
+ repeated sfixed64 repeated_sfixed64_extension = 40;
233
+ repeated float repeated_float_extension = 41;
234
+ repeated double repeated_double_extension = 42;
235
+ repeated bool repeated_bool_extension = 43;
236
+ repeated string repeated_string_extension = 44;
237
+ repeated bytes repeated_bytes_extension = 45;
238
+
239
+ // TODO: Support groups
240
+ //repeated group RepeatedGroup_extension = 46 {
241
+ // optional int32 a = 47;
242
+ //}
243
+
244
+ repeated TestAllTypes.NestedMessage repeated_nested_message_extension = 48;
245
+ repeated ForeignMessage repeated_foreign_message_extension = 49;
246
+ repeated googleUnittestImport.ImportMessage
247
+ repeated_import_message_extension = 50;
248
+
249
+ repeated TestAllTypes.NestedEnum repeated_nested_enum_extension = 51;
250
+ repeated ForeignEnum repeated_foreign_enum_extension = 52;
251
+ repeated googleUnittestImport.ImportEnum
252
+ repeated_import_enum_extension = 53;
253
+
254
+ repeated string repeated_string_piece_extension = 54 [ctype=STRING_PIECE];
255
+ repeated string repeated_cord_extension = 55 [ctype=CORD];
256
+
257
+ repeated TestAllTypes.NestedMessage
258
+ repeated_lazy_message_extension = 57; // [lazy=true];
259
+
260
+ // Singular with defaults
261
+ optional int32 default_int32_extension = 61 [default = 41 ];
262
+ optional int64 default_int64_extension = 62 [default = 42 ];
263
+ optional uint32 default_uint32_extension = 63 [default = 43 ];
264
+ optional uint64 default_uint64_extension = 64 [default = 44 ];
265
+ optional sint32 default_sint32_extension = 65 [default = -45 ];
266
+ optional sint64 default_sint64_extension = 66 [default = 46 ];
267
+ optional fixed32 default_fixed32_extension = 67 [default = 47 ];
268
+ optional fixed64 default_fixed64_extension = 68 [default = 48 ];
269
+ optional sfixed32 default_sfixed32_extension = 69 [default = 49 ];
270
+ optional sfixed64 default_sfixed64_extension = 70 [default = -50 ];
271
+ optional float default_float_extension = 71 [default = 51.5 ];
272
+ optional double default_double_extension = 72 [default = 52e3 ];
273
+ optional bool default_bool_extension = 73 [default = true ];
274
+ optional string default_string_extension = 74 [default = "hello"];
275
+ optional bytes default_bytes_extension = 75 [default = "world"];
276
+
277
+ optional TestAllTypes.NestedEnum
278
+ default_nested_enum_extension = 81 [default = BAR];
279
+ optional ForeignEnum
280
+ default_foreign_enum_extension = 82 [default = FOREIGN_BAR];
281
+ optional googleUnittestImport.ImportEnum
282
+ default_import_enum_extension = 83 [default = IMPORT_BAR];
283
+
284
+ optional string default_string_piece_extension = 84 [ctype=STRING_PIECE,
285
+ default="abc"];
286
+ optional string default_cord_extension = 85 [ctype=CORD, default="123"];
287
+ }
288
+
289
+ message TestNestedExtension {
290
+ extend TestAllExtensions {
291
+ // Check for bug where string extensions declared in tested scope did not
292
+ // compile.
293
+ optional string test = 1002 [default="test"];
294
+ }
295
+ }
296
+
297
+ // We have separate messages for testing required fields because it's
298
+ // annoying to have to fill in required fields in TestProto in order to
299
+ // do anything with it. Note that we don't need to test every type of
300
+ // required filed because the code output is basically identical to
301
+ // optional fields for all types.
302
+ message TestRequired {
303
+ required int32 a = 1;
304
+ optional int32 dummy2 = 2;
305
+ required int32 b = 3;
306
+
307
+ extend TestAllExtensions {
308
+ optional TestRequired single = 1000;
309
+ repeated TestRequired multi = 1001;
310
+ }
311
+
312
+ // Pad the field count to 32 so that we can test that IsInitialized()
313
+ // properly checks multiple elements of has_bits_.
314
+ optional int32 dummy4 = 4;
315
+ optional int32 dummy5 = 5;
316
+ optional int32 dummy6 = 6;
317
+ optional int32 dummy7 = 7;
318
+ optional int32 dummy8 = 8;
319
+ optional int32 dummy9 = 9;
320
+ optional int32 dummy10 = 10;
321
+ optional int32 dummy11 = 11;
322
+ optional int32 dummy12 = 12;
323
+ optional int32 dummy13 = 13;
324
+ optional int32 dummy14 = 14;
325
+ optional int32 dummy15 = 15;
326
+ optional int32 dummy16 = 16;
327
+ optional int32 dummy17 = 17;
328
+ optional int32 dummy18 = 18;
329
+ optional int32 dummy19 = 19;
330
+ optional int32 dummy20 = 20;
331
+ optional int32 dummy21 = 21;
332
+ optional int32 dummy22 = 22;
333
+ optional int32 dummy23 = 23;
334
+ optional int32 dummy24 = 24;
335
+ optional int32 dummy25 = 25;
336
+ optional int32 dummy26 = 26;
337
+ optional int32 dummy27 = 27;
338
+ optional int32 dummy28 = 28;
339
+ optional int32 dummy29 = 29;
340
+ optional int32 dummy30 = 30;
341
+ optional int32 dummy31 = 31;
342
+ optional int32 dummy32 = 32;
343
+
344
+ required int32 c = 33;
345
+ }
346
+
347
+ message TestRequiredForeign {
348
+ optional TestRequired optional_message = 1;
349
+ repeated TestRequired repeated_message = 2;
350
+ optional int32 dummy = 3;
351
+ }
352
+
353
+ // Test that we can use NestedMessage from outside TestAllTypes.
354
+ message TestForeignNested {
355
+ optional TestAllTypes.NestedMessage foreign_nested = 1;
356
+ }
357
+
358
+ // TestEmptyMessage is used to test unknown field support.
359
+ message TestEmptyMessage {
360
+ }
361
+
362
+ // Like above, but declare all field numbers as potential extensions. No
363
+ // actual extensions should ever be defined for this type.
364
+ message TestEmptyMessageWithExtensions {
365
+ extensions 1 to max;
366
+ }
367
+
368
+ message TestMultipleExtensionRanges {
369
+ extensions 42;
370
+ extensions 4143 to 4243;
371
+ extensions 65536 to max;
372
+ }
373
+
374
+ // Test that really large tag numbers don't break anything.
375
+ message TestReallyLargeTagNumber {
376
+ // The largest possible tag number is 2^28 - 1, since the wire format uses
377
+ // three bits to communicate wire type.
378
+ optional int32 a = 1;
379
+ optional int32 bb = 268435455;
380
+ }
381
+
382
+ message TestRecursiveMessage {
383
+ optional TestRecursiveMessage a = 1;
384
+ optional int32 i = 2;
385
+ }
386
+
387
+ // Test that mutual recursion works.
388
+ message TestMutualRecursionA {
389
+ optional TestMutualRecursionB bb = 1;
390
+ }
391
+
392
+ message TestMutualRecursionB {
393
+ optional TestMutualRecursionA a = 1;
394
+ optional int32 optional_int32 = 2;
395
+ }
396
+
397
+ // Test that groups have disjoint field numbers from their siblings and
398
+ // parents. This is NOT possible in proto1; only proto2. When attempting
399
+ // to compile with proto1, this will emit an error; so we only include it
400
+ // in google_unittest_proto.
401
+ message TestDupFieldNumber { // NO_PROTO1
402
+ 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
406
+ } // NO_PROTO1
407
+
408
+ // Additional messages for testing lazy fields.
409
+ message TestEagerMessage {
410
+ optional TestAllTypes sub_message = 1; // [lazy=false];
411
+ }
412
+ message TestLazyMessage {
413
+ optional TestAllTypes sub_message = 1; // [lazy=true];
414
+ }
415
+
416
+ // Needed for a Python test.
417
+ message TestNestedMessageHasBits {
418
+ message NestedMessage {
419
+ repeated int32 nestedmessage_repeated_int32 = 1;
420
+ repeated ForeignMessage nestedmessage_repeated_foreignmessage = 2;
421
+ }
422
+ optional NestedMessage optional_nested_message = 1;
423
+ }
424
+
425
+
426
+ // 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
+ // }
436
+
437
+ // Test an enum with large, unordered values.
438
+ enum TestSparseEnum {
439
+ SPARSE_A = 123;
440
+ SPARSE_B = 62374;
441
+ SPARSE_C = 12589234;
442
+ SPARSE_D = -15;
443
+ SPARSE_E = -53452;
444
+ SPARSE_F = 0;
445
+ SPARSE_G = 2;
446
+ }
447
+
448
+ // Test message with CamelCase field names. This violates Protocol Buffer
449
+ // standard style.
450
+ message TestCamelCaseFieldNames {
451
+ optional int32 PrimitiveField = 1;
452
+ optional string StringField = 2;
453
+ optional ForeignEnum EnumField = 3;
454
+ optional ForeignMessage MessageField = 4;
455
+ optional string StringPieceField = 5 [ctype=STRING_PIECE];
456
+ optional string CordField = 6 [ctype=CORD];
457
+
458
+ repeated int32 RepeatedPrimitiveField = 7;
459
+ repeated string RepeatedStringField = 8;
460
+ repeated ForeignEnum RepeatedEnumField = 9;
461
+ repeated ForeignMessage RepeatedMessageField = 10;
462
+ repeated string RepeatedStringPieceField = 11 [ctype=STRING_PIECE];
463
+ repeated string RepeatedCordField = 12 [ctype=CORD];
464
+ }
465
+
466
+
467
+ // We list fields out of order, to ensure that we're using field number and not
468
+ // field index to determine serialization order.
469
+ message TestFieldOrderings {
470
+ optional string my_string = 11;
471
+ extensions 2 to 10;
472
+ optional int64 my_int = 1;
473
+ extensions 12 to 100;
474
+ optional float my_float = 101;
475
+ }
476
+
477
+
478
+ extend TestFieldOrderings {
479
+ optional string my_extension_string = 50;
480
+ optional int32 my_extension_int = 5;
481
+ }
482
+
483
+
484
+ message TestExtremeDefaultValues {
485
+ optional bytes escaped_bytes = 1 [default = "\0\001\a\b\f\n\r\t\v\\\'\"\xfe"];
486
+ optional uint32 large_uint32 = 2 [default = 0xFFFFFFFF];
487
+ optional uint64 large_uint64 = 3 [default = 0xFFFFFFFFFFFFFFFF];
488
+ optional int32 small_int32 = 4 [default = -0x7FFFFFFF];
489
+ optional int64 small_int64 = 5 [default = -0x7FFFFFFFFFFFFFFF];
490
+ optional int32 really_small_int32 = 21 [default = -0x80000000];
491
+ optional int64 really_small_int64 = 22 [default = -0x8000000000000000];
492
+
493
+ // The default value here is UTF-8 for "\u1234". (We could also just type
494
+ // the UTF-8 text directly into this text file rather than escape it, but
495
+ // lots of people use editors that would be confused by this.)
496
+ optional string utf8_string = 6 [default = "\341\210\264"];
497
+
498
+ // Tests for single-precision floating-point values.
499
+ optional float zero_float = 7 [default = 0];
500
+ optional float one_float = 8 [default = 1];
501
+ optional float small_float = 9 [default = 1.5];
502
+ optional float negative_one_float = 10 [default = -1];
503
+ optional float negative_float = 11 [default = -1.5];
504
+ // Using exponents
505
+ optional float large_float = 12 [default = 2E8];
506
+ optional float small_negative_float = 13 [default = -8e-28];
507
+
508
+ // Text for nonfinite floating-point values.
509
+ optional double inf_double = 14 [default = inf];
510
+ optional double neg_inf_double = 15 [default = -inf];
511
+ optional double nan_double = 16 [default = nan];
512
+ optional float inf_float = 17 [default = inf];
513
+ optional float neg_inf_float = 18 [default = -inf];
514
+ optional float nan_float = 19 [default = nan];
515
+
516
+ // Tests for C++ trigraphs.
517
+ // Trigraphs should be escaped in C++ generated files, but they should not be
518
+ // escaped for other languages.
519
+ // Note that in .proto file, "\?" is a valid way to escape ? in string
520
+ // literals.
521
+ optional string cpp_trigraph = 20 [default = "? \? ?? \?? \??? ??/ ?\?-"];
522
+
523
+ // String defaults containing the character '\000'
524
+ optional string string_with_zero = 23 [default = "hel\000lo"];
525
+ optional bytes bytes_with_zero = 24 [default = "wor\000ld"];
526
+ optional string string_piece_with_zero = 25 [ctype=STRING_PIECE,
527
+ default="ab\000c"];
528
+ optional string cord_with_zero = 26 [ctype=CORD,
529
+ default="12\0003"];
530
+ }
531
+
532
+ message SparseEnumMessage {
533
+ optional TestSparseEnum sparse_enum = 1;
534
+ }
535
+
536
+ // Test String and Bytes: string is for valid UTF-8 strings
537
+ message OneString {
538
+ optional string data = 1;
539
+ }
540
+
541
+ message MoreString {
542
+ repeated string data = 1;
543
+ }
544
+
545
+ message OneBytes {
546
+ optional bytes data = 1;
547
+ }
548
+
549
+ message MoreBytes {
550
+ repeated bytes data = 1;
551
+ }
552
+
553
+
554
+ // Test messages for packed fields
555
+
556
+ message TestPackedTypes {
557
+ repeated int32 packed_int32 = 90 [packed = true];
558
+ repeated int64 packed_int64 = 91 [packed = true];
559
+ repeated uint32 packed_uint32 = 92 [packed = true];
560
+ repeated uint64 packed_uint64 = 93 [packed = true];
561
+ repeated sint32 packed_sint32 = 94 [packed = true];
562
+ repeated sint64 packed_sint64 = 95 [packed = true];
563
+ repeated fixed32 packed_fixed32 = 96 [packed = true];
564
+ repeated fixed64 packed_fixed64 = 97 [packed = true];
565
+ repeated sfixed32 packed_sfixed32 = 98 [packed = true];
566
+ repeated sfixed64 packed_sfixed64 = 99 [packed = true];
567
+ repeated float packed_float = 100 [packed = true];
568
+ repeated double packed_double = 101 [packed = true];
569
+ repeated bool packed_bool = 102 [packed = true];
570
+ repeated ForeignEnum packed_enum = 103 [packed = true];
571
+ }
572
+
573
+ // A message with the same fields as TestPackedTypes, but without packing. Used
574
+ // to test packed <-> unpacked wire compatibility.
575
+ message TestUnpackedTypes {
576
+ repeated int32 unpacked_int32 = 90 [packed = false];
577
+ repeated int64 unpacked_int64 = 91 [packed = false];
578
+ repeated uint32 unpacked_uint32 = 92 [packed = false];
579
+ repeated uint64 unpacked_uint64 = 93 [packed = false];
580
+ repeated sint32 unpacked_sint32 = 94 [packed = false];
581
+ repeated sint64 unpacked_sint64 = 95 [packed = false];
582
+ repeated fixed32 unpacked_fixed32 = 96 [packed = false];
583
+ repeated fixed64 unpacked_fixed64 = 97 [packed = false];
584
+ repeated sfixed32 unpacked_sfixed32 = 98 [packed = false];
585
+ repeated sfixed64 unpacked_sfixed64 = 99 [packed = false];
586
+ repeated float unpacked_float = 100 [packed = false];
587
+ repeated double unpacked_double = 101 [packed = false];
588
+ repeated bool unpacked_bool = 102 [packed = false];
589
+ repeated ForeignEnum unpacked_enum = 103 [packed = false];
590
+ }
591
+
592
+ message TestPackedExtensions {
593
+ extensions 1 to max;
594
+ }
595
+
596
+ extend TestPackedExtensions {
597
+ repeated int32 packed_int32_extension = 90 [packed = true];
598
+ repeated int64 packed_int64_extension = 91 [packed = true];
599
+ repeated uint32 packed_uint32_extension = 92 [packed = true];
600
+ repeated uint64 packed_uint64_extension = 93 [packed = true];
601
+ repeated sint32 packed_sint32_extension = 94 [packed = true];
602
+ repeated sint64 packed_sint64_extension = 95 [packed = true];
603
+ repeated fixed32 packed_fixed32_extension = 96 [packed = true];
604
+ repeated fixed64 packed_fixed64_extension = 97 [packed = true];
605
+ repeated sfixed32 packed_sfixed32_extension = 98 [packed = true];
606
+ repeated sfixed64 packed_sfixed64_extension = 99 [packed = true];
607
+ repeated float packed_float_extension = 100 [packed = true];
608
+ repeated double packed_double_extension = 101 [packed = true];
609
+ repeated bool packed_bool_extension = 102 [packed = true];
610
+ repeated ForeignEnum packed_enum_extension = 103 [packed = true];
611
+ }
612
+
613
+ // Used by ExtensionSetTest/DynamicExtensions. The test actually builds
614
+ // a set of extensions to TestAllExtensions dynamically, based on the fields
615
+ // of this message type.
616
+ message TestDynamicExtensions {
617
+ enum DynamicEnumType {
618
+ DYNAMIC_FOO = 2200;
619
+ DYNAMIC_BAR = 2201;
620
+ DYNAMIC_BAZ = 2202;
621
+ }
622
+ message DynamicMessageType {
623
+ optional int32 dynamic_field = 2100;
624
+ }
625
+
626
+ optional fixed32 scalar_extension = 2000;
627
+ optional ForeignEnum enum_extension = 2001;
628
+ optional DynamicEnumType dynamic_enum_extension = 2002;
629
+
630
+ optional ForeignMessage message_extension = 2003;
631
+ optional DynamicMessageType dynamic_message_extension = 2004;
632
+
633
+ repeated string repeated_extension = 2005;
634
+ repeated sint32 packed_extension = 2006 [packed = true];
635
+ }
636
+
637
+ message TestRepeatedScalarDifferentTagSizes {
638
+ // Parsing repeated fixed size values used to fail. This message needs to be
639
+ // used in order to get a tag of the right size; all of the repeated fields
640
+ // in TestAllTypes didn't trigger the check.
641
+ repeated fixed32 repeated_fixed32 = 12;
642
+ // Check for a varint type, just for good measure.
643
+ repeated int32 repeated_int32 = 13;
644
+
645
+ // These have two-byte tags.
646
+ repeated fixed64 repeated_fixed64 = 2046;
647
+ repeated int64 repeated_int64 = 2047;
648
+
649
+ // Three byte tags.
650
+ repeated float repeated_float = 262142;
651
+ repeated uint64 repeated_uint64 = 262143;
652
+ }
653
+
654
+ // Test that if an optional or required message/group field appears multiple
655
+ // times in the input, they need to be merged.
656
+ message TestParsingMerge {
657
+ // RepeatedFieldsGenerator defines matching field types as TestParsingMerge,
658
+ // except that all fields are repeated. In the tests, we will serialize the
659
+ // RepeatedFieldsGenerator to bytes, and parse the bytes to TestParsingMerge.
660
+ // Repeated fields in RepeatedFieldsGenerator are expected to be merged into
661
+ // the corresponding required/optional fields in TestParsingMerge.
662
+ message RepeatedFieldsGenerator {
663
+ repeated TestAllTypes field1 = 1;
664
+ repeated TestAllTypes field2 = 2;
665
+ 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
+ //}
673
+ repeated TestAllTypes ext1 = 1000;
674
+ repeated TestAllTypes ext2 = 1001;
675
+ }
676
+ required TestAllTypes required_all_types = 1;
677
+ optional TestAllTypes optional_all_types = 2;
678
+ 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
+ //}
686
+ extensions 1000 to max;
687
+ extend TestParsingMerge {
688
+ optional TestAllTypes optional_ext = 1000;
689
+ repeated TestAllTypes repeated_ext = 1001;
690
+ }
691
+ }
692
+
693
+ message TestCommentInjectionMessage {
694
+ // */ <- This should not close the generated doc comment
695
+ optional string a = 1 [default="*/ <- Neither should this."];
696
+ }
697
+
698
+
699
+ // Test that RPC services work.
700
+ message FooRequest {}
701
+ message FooResponse {}
702
+
703
+ message FooClientMessage {}
704
+ message FooServerMessage{}
705
+
706
+ service TestService {
707
+ rpc Foo(FooRequest) returns (FooResponse);
708
+ rpc Bar(BarRequest) returns (BarResponse);
709
+ }
710
+
711
+
712
+ message BarRequest {}
713
+ message BarResponse {}