protobuf 3.7.0.pre2 → 3.7.0.pre3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -1
- data/.rubocop_todo.yml +7 -1
- data/.travis.yml +8 -1
- data/CHANGES.md +25 -1
- data/bin/protoc-gen-ruby +2 -2
- data/lib/protobuf/cli.rb +29 -17
- data/lib/protobuf/code_generator.rb +49 -1
- data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +9 -1
- data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +14 -1
- data/lib/protobuf/encoder.rb +2 -2
- data/lib/protobuf/enum.rb +3 -3
- data/lib/protobuf/field/base_field.rb +27 -19
- data/lib/protobuf/field/bool_field.rb +10 -8
- data/lib/protobuf/field/bytes_field.rb +14 -6
- data/lib/protobuf/field/float_field.rb +2 -0
- data/lib/protobuf/field/string_field.rb +10 -0
- data/lib/protobuf/field/varint_field.rb +12 -2
- data/lib/protobuf/generators/base.rb +29 -14
- data/lib/protobuf/generators/enum_generator.rb +4 -7
- data/lib/protobuf/generators/field_generator.rb +17 -4
- data/lib/protobuf/generators/file_generator.rb +121 -10
- data/lib/protobuf/generators/group_generator.rb +9 -3
- data/lib/protobuf/generators/message_generator.rb +8 -2
- data/lib/protobuf/generators/option_generator.rb +17 -0
- data/lib/protobuf/generators/printable.rb +2 -2
- data/lib/protobuf/generators/service_generator.rb +27 -3
- data/lib/protobuf/lifecycle.rb +1 -1
- data/lib/protobuf/message/fields.rb +13 -15
- data/lib/protobuf/message/serialization.rb +9 -9
- data/lib/protobuf/message.rb +23 -29
- data/lib/protobuf/optionable.rb +10 -10
- data/lib/protobuf/rpc/buffer.rb +7 -6
- data/lib/protobuf/rpc/client.rb +2 -30
- data/lib/protobuf/rpc/connectors/base.rb +168 -6
- data/lib/protobuf/rpc/connectors/ping.rb +2 -2
- data/lib/protobuf/rpc/connectors/socket.rb +6 -1
- data/lib/protobuf/rpc/connectors/zmq.rb +1 -2
- data/lib/protobuf/rpc/dynamic_discovery.pb.rb +2 -1
- data/lib/protobuf/rpc/error.rb +2 -2
- data/lib/protobuf/rpc/middleware/exception_handler.rb +4 -0
- data/lib/protobuf/rpc/middleware/logger.rb +4 -0
- data/lib/protobuf/rpc/middleware/request_decoder.rb +11 -16
- data/lib/protobuf/rpc/middleware/response_encoder.rb +18 -23
- data/lib/protobuf/rpc/rpc.pb.rb +2 -1
- data/lib/protobuf/rpc/rpc_method.rb +16 -0
- data/lib/protobuf/rpc/servers/socket/server.rb +4 -4
- data/lib/protobuf/rpc/servers/socket_runner.rb +8 -0
- data/lib/protobuf/rpc/servers/zmq/broker.rb +7 -6
- data/lib/protobuf/rpc/servers/zmq/server.rb +8 -7
- data/lib/protobuf/rpc/servers/zmq/util.rb +6 -6
- data/lib/protobuf/rpc/servers/zmq/worker.rb +7 -6
- data/lib/protobuf/rpc/servers/zmq_runner.rb +8 -0
- data/lib/protobuf/rpc/service.rb +6 -15
- data/lib/protobuf/rpc/service_directory.rb +1 -1
- data/lib/protobuf/rpc/service_dispatcher.rb +5 -6
- data/lib/protobuf/rpc/service_filters.rb +8 -30
- data/lib/protobuf/socket.rb +2 -2
- data/lib/protobuf/version.rb +1 -1
- data/lib/protobuf/zmq.rb +2 -2
- data/lib/protobuf.rb +12 -27
- data/protobuf.gemspec +5 -3
- data/spec/benchmark/tasks.rb +1 -0
- data/spec/functional/code_generator_spec.rb +38 -0
- data/spec/lib/protobuf/cli_spec.rb +19 -10
- data/spec/lib/protobuf/code_generator_spec.rb +28 -0
- data/spec/lib/protobuf/enum_spec.rb +6 -2
- data/spec/lib/protobuf/field/bool_field_spec.rb +4 -0
- data/spec/lib/protobuf/field/double_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/fixed32_field_spec.rb +7 -0
- data/spec/lib/protobuf/field/fixed64_field_spec.rb +7 -0
- data/spec/lib/protobuf/field/float_field_spec.rb +5 -1
- data/spec/lib/protobuf/field/int64_field_spec.rb +7 -0
- data/spec/lib/protobuf/field/message_field_spec.rb +53 -0
- data/spec/lib/protobuf/field/sfixed32_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/sfixed64_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/sint32_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/sint64_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/uint32_field_spec.rb +7 -0
- data/spec/lib/protobuf/field/uint64_field_spec.rb +7 -0
- data/spec/lib/protobuf/generators/base_spec.rb +69 -1
- data/spec/lib/protobuf/generators/enum_generator_spec.rb +1 -1
- data/spec/lib/protobuf/generators/field_generator_spec.rb +58 -0
- data/spec/lib/protobuf/generators/file_generator_spec.rb +47 -0
- data/spec/lib/protobuf/generators/service_generator_spec.rb +58 -14
- data/spec/lib/protobuf/message_spec.rb +2 -2
- data/spec/lib/protobuf/optionable_spec.rb +96 -0
- data/spec/lib/protobuf/rpc/connectors/base_spec.rb +151 -0
- data/spec/lib/protobuf/rpc/connectors/ping_spec.rb +3 -3
- data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +0 -2
- data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +2 -2
- data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +4 -4
- data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +2 -2
- data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +1 -18
- data/spec/lib/protobuf/rpc/service_filters_spec.rb +2 -2
- data/spec/lib/protobuf/varint_spec.rb +1 -1
- data/spec/lib/protobuf_spec.rb +13 -16
- data/spec/support/packed_field.rb +3 -2
- data/spec/support/protos/enum.pb.rb +2 -1
- data/spec/support/protos/enum.proto +1 -0
- data/spec/support/protos/google_unittest.pb.rb +69 -58
- data/spec/support/protos/google_unittest_custom_options.bin +0 -0
- data/spec/support/protos/google_unittest_custom_options.pb.rb +361 -0
- data/spec/support/protos/google_unittest_custom_options.proto +424 -0
- data/spec/support/protos/google_unittest_import.pb.rb +8 -0
- data/spec/support/protos/google_unittest_import_public.pb.rb +6 -0
- data/spec/support/protos/resource.pb.rb +54 -2
- data/spec/support/protos/resource.proto +42 -2
- data/spec/support/server.rb +1 -1
- metadata +39 -16
- data/lib/protobuf/rpc/connector.rb +0 -19
- data/lib/protobuf/rpc/connectors/common.rb +0 -176
- data/spec/lib/protobuf/rpc/connector_spec.rb +0 -26
- data/spec/lib/protobuf/rpc/connectors/common_spec.rb +0 -170
@@ -0,0 +1,424 @@
|
|
1
|
+
// Protocol Buffers - Google's data interchange format
|
2
|
+
// Copyright 2008 Google Inc. All rights reserved.
|
3
|
+
// https://developers.google.com/protocol-buffers/
|
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: benjy@google.com (Benjy Weinberger)
|
32
|
+
// Based on original Protocol Buffers design by
|
33
|
+
// Sanjay Ghemawat, Jeff Dean, and others.
|
34
|
+
//
|
35
|
+
// A proto file used to test the "custom options" feature of google.protobuf.
|
36
|
+
|
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;
|
44
|
+
|
45
|
+
// A custom file option (defined below).
|
46
|
+
option (file_opt1) = 9876543210;
|
47
|
+
|
48
|
+
import "google/protobuf/descriptor.proto";
|
49
|
+
|
50
|
+
// We don't put this in a package within proto2 because we need to make sure
|
51
|
+
// that the generated code doesn't depend on being in the proto2 namespace.
|
52
|
+
package protobuf_unittest;
|
53
|
+
|
54
|
+
|
55
|
+
// Some simple test custom options of various types.
|
56
|
+
|
57
|
+
extend google.protobuf.FileOptions {
|
58
|
+
optional uint64 file_opt1 = 7736974;
|
59
|
+
}
|
60
|
+
|
61
|
+
extend google.protobuf.MessageOptions {
|
62
|
+
optional int32 message_opt1 = 7739036;
|
63
|
+
}
|
64
|
+
|
65
|
+
extend google.protobuf.FieldOptions {
|
66
|
+
optional fixed64 field_opt1 = 7740936;
|
67
|
+
// This is useful for testing that we correctly register default values for
|
68
|
+
// extension options.
|
69
|
+
optional int32 field_opt2 = 7753913 [default=42];
|
70
|
+
}
|
71
|
+
|
72
|
+
extend google.protobuf.EnumOptions {
|
73
|
+
optional sfixed32 enum_opt1 = 7753576;
|
74
|
+
}
|
75
|
+
|
76
|
+
extend google.protobuf.EnumValueOptions {
|
77
|
+
optional int32 enum_value_opt1 = 1560678;
|
78
|
+
}
|
79
|
+
|
80
|
+
extend google.protobuf.ServiceOptions {
|
81
|
+
optional sint64 service_opt1 = 7887650;
|
82
|
+
}
|
83
|
+
|
84
|
+
enum MethodOpt1 {
|
85
|
+
METHODOPT1_VAL1 = 1;
|
86
|
+
METHODOPT1_VAL2 = 2;
|
87
|
+
}
|
88
|
+
|
89
|
+
extend google.protobuf.MethodOptions {
|
90
|
+
optional MethodOpt1 method_opt1 = 7890860;
|
91
|
+
}
|
92
|
+
|
93
|
+
// A test message with custom options at all possible locations (and also some
|
94
|
+
// regular options, to make sure they interact nicely).
|
95
|
+
message TestMessageWithCustomOptions {
|
96
|
+
option message_set_wire_format = false;
|
97
|
+
|
98
|
+
option (message_opt1) = -56;
|
99
|
+
|
100
|
+
optional string field1 = 1 [ctype=CORD,
|
101
|
+
(field_opt1)=8765432109];
|
102
|
+
|
103
|
+
enum AnEnum {
|
104
|
+
option (enum_opt1) = -789;
|
105
|
+
|
106
|
+
ANENUM_VAL1 = 1;
|
107
|
+
ANENUM_VAL2 = 2 [(enum_value_opt1) = 123];
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
|
112
|
+
// A test RPC service with custom options at all possible locations (and also
|
113
|
+
// some regular options, to make sure they interact nicely).
|
114
|
+
message CustomOptionFooRequest {
|
115
|
+
}
|
116
|
+
|
117
|
+
message CustomOptionFooResponse {
|
118
|
+
}
|
119
|
+
|
120
|
+
message CustomOptionFooClientMessage {
|
121
|
+
}
|
122
|
+
|
123
|
+
message CustomOptionFooServerMessage {
|
124
|
+
}
|
125
|
+
|
126
|
+
service TestServiceWithCustomOptions {
|
127
|
+
option (service_opt1) = -9876543210;
|
128
|
+
|
129
|
+
rpc Foo(CustomOptionFooRequest) returns (CustomOptionFooResponse) {
|
130
|
+
option (method_opt1) = METHODOPT1_VAL2;
|
131
|
+
}
|
132
|
+
}
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
// Options of every possible field type, so we can test them all exhaustively.
|
137
|
+
|
138
|
+
message DummyMessageContainingEnum {
|
139
|
+
enum TestEnumType {
|
140
|
+
TEST_OPTION_ENUM_TYPE1 = 22;
|
141
|
+
TEST_OPTION_ENUM_TYPE2 = -23;
|
142
|
+
}
|
143
|
+
}
|
144
|
+
|
145
|
+
message DummyMessageInvalidAsOptionType {
|
146
|
+
}
|
147
|
+
|
148
|
+
extend google.protobuf.MessageOptions {
|
149
|
+
optional bool bool_opt = 7706090;
|
150
|
+
optional int32 int32_opt = 7705709;
|
151
|
+
optional int64 int64_opt = 7705542;
|
152
|
+
optional uint32 uint32_opt = 7704880;
|
153
|
+
optional uint64 uint64_opt = 7702367;
|
154
|
+
optional sint32 sint32_opt = 7701568;
|
155
|
+
optional sint64 sint64_opt = 7700863;
|
156
|
+
optional fixed32 fixed32_opt = 7700307;
|
157
|
+
optional fixed64 fixed64_opt = 7700194;
|
158
|
+
optional sfixed32 sfixed32_opt = 7698645;
|
159
|
+
optional sfixed64 sfixed64_opt = 7685475;
|
160
|
+
optional float float_opt = 7675390;
|
161
|
+
optional double double_opt = 7673293;
|
162
|
+
optional string string_opt = 7673285;
|
163
|
+
optional bytes bytes_opt = 7673238;
|
164
|
+
optional DummyMessageContainingEnum.TestEnumType enum_opt = 7673233;
|
165
|
+
optional DummyMessageInvalidAsOptionType message_type_opt = 7665967;
|
166
|
+
}
|
167
|
+
|
168
|
+
message CustomOptionMinIntegerValues {
|
169
|
+
option (bool_opt) = false;
|
170
|
+
option (int32_opt) = -0x80000000;
|
171
|
+
option (int64_opt) = -0x8000000000000000;
|
172
|
+
option (uint32_opt) = 0;
|
173
|
+
option (uint64_opt) = 0;
|
174
|
+
option (sint32_opt) = -0x80000000;
|
175
|
+
option (sint64_opt) = -0x8000000000000000;
|
176
|
+
option (fixed32_opt) = 0;
|
177
|
+
option (fixed64_opt) = 0;
|
178
|
+
option (sfixed32_opt) = -0x80000000;
|
179
|
+
option (sfixed64_opt) = -0x8000000000000000;
|
180
|
+
}
|
181
|
+
|
182
|
+
message CustomOptionMaxIntegerValues {
|
183
|
+
option (bool_opt) = true;
|
184
|
+
option (int32_opt) = 0x7FFFFFFF;
|
185
|
+
option (int64_opt) = 0x7FFFFFFFFFFFFFFF;
|
186
|
+
option (uint32_opt) = 0xFFFFFFFF;
|
187
|
+
option (uint64_opt) = 0xFFFFFFFFFFFFFFFF;
|
188
|
+
option (sint32_opt) = 0x7FFFFFFF;
|
189
|
+
option (sint64_opt) = 0x7FFFFFFFFFFFFFFF;
|
190
|
+
option (fixed32_opt) = 0xFFFFFFFF;
|
191
|
+
option (fixed64_opt) = 0xFFFFFFFFFFFFFFFF;
|
192
|
+
option (sfixed32_opt) = 0x7FFFFFFF;
|
193
|
+
option (sfixed64_opt) = 0x7FFFFFFFFFFFFFFF;
|
194
|
+
}
|
195
|
+
|
196
|
+
message CustomOptionOtherValues {
|
197
|
+
option (int32_opt) = -100; // To test sign-extension.
|
198
|
+
option (float_opt) = 12.3456789;
|
199
|
+
option (double_opt) = 1.234567890123456789;
|
200
|
+
option (string_opt) = "Hello, \"World\"";
|
201
|
+
option (bytes_opt) = "Hello\0World";
|
202
|
+
option (enum_opt) = TEST_OPTION_ENUM_TYPE2;
|
203
|
+
}
|
204
|
+
|
205
|
+
message SettingRealsFromPositiveInts {
|
206
|
+
option (float_opt) = 12;
|
207
|
+
option (double_opt) = 154;
|
208
|
+
}
|
209
|
+
|
210
|
+
message SettingRealsFromNegativeInts {
|
211
|
+
option (float_opt) = -12;
|
212
|
+
option (double_opt) = -154;
|
213
|
+
}
|
214
|
+
|
215
|
+
// Options of complex message types, themselves combined and extended in
|
216
|
+
// various ways.
|
217
|
+
|
218
|
+
// TODO: do we want to support packed ints?
|
219
|
+
// e.g.: repeated int32 foo4 = 4 [packed = true];
|
220
|
+
message ComplexOptionType1 {
|
221
|
+
optional int32 foo = 1;
|
222
|
+
optional int32 foo2 = 2;
|
223
|
+
optional int32 foo3 = 3;
|
224
|
+
repeated int32 foo4 = 4;
|
225
|
+
|
226
|
+
extensions 100 to max;
|
227
|
+
}
|
228
|
+
|
229
|
+
message ComplexOptionType2 {
|
230
|
+
optional ComplexOptionType1 bar = 1;
|
231
|
+
optional int32 baz = 2;
|
232
|
+
|
233
|
+
message ComplexOptionType4 {
|
234
|
+
optional int32 waldo = 1;
|
235
|
+
|
236
|
+
extend google.protobuf.MessageOptions {
|
237
|
+
optional ComplexOptionType4 complex_opt4 = 7633546;
|
238
|
+
}
|
239
|
+
}
|
240
|
+
|
241
|
+
optional ComplexOptionType4 fred = 3;
|
242
|
+
repeated ComplexOptionType4 barney = 4;
|
243
|
+
|
244
|
+
extensions 100 to max;
|
245
|
+
}
|
246
|
+
|
247
|
+
message ComplexOptionType3 {
|
248
|
+
optional int32 qux = 1;
|
249
|
+
}
|
250
|
+
|
251
|
+
extend ComplexOptionType1 {
|
252
|
+
optional int32 quux = 7663707;
|
253
|
+
optional ComplexOptionType3 corge = 7663442;
|
254
|
+
}
|
255
|
+
|
256
|
+
extend ComplexOptionType2 {
|
257
|
+
optional int32 grault = 7650927;
|
258
|
+
optional ComplexOptionType1 garply = 7649992;
|
259
|
+
}
|
260
|
+
|
261
|
+
extend google.protobuf.MessageOptions {
|
262
|
+
optional protobuf_unittest.ComplexOptionType1 complex_opt1 = 7646756;
|
263
|
+
optional ComplexOptionType2 complex_opt2 = 7636949;
|
264
|
+
optional ComplexOptionType3 complex_opt3 = 7636463;
|
265
|
+
repeated int32 repeated_opt1 = 7636464;
|
266
|
+
repeated protobuf_unittest.ComplexOptionType3 repeated_opt2 = 7636465;
|
267
|
+
}
|
268
|
+
|
269
|
+
// Note that we try various different ways of naming the same extension.
|
270
|
+
message VariousComplexOptions {
|
271
|
+
option (.protobuf_unittest.complex_opt1).foo = 42;
|
272
|
+
option (protobuf_unittest.complex_opt1).(.protobuf_unittest.quux) = 324;
|
273
|
+
option (.protobuf_unittest.complex_opt1).(protobuf_unittest.corge).qux = 876;
|
274
|
+
option (protobuf_unittest.complex_opt1).foo4 = 99;
|
275
|
+
option (protobuf_unittest.complex_opt1).foo4 = 88;
|
276
|
+
option (complex_opt2).baz = 987;
|
277
|
+
option (complex_opt2).(grault) = 654;
|
278
|
+
option (complex_opt2).bar.foo = 743;
|
279
|
+
option (complex_opt2).bar.(quux) = 1999;
|
280
|
+
option (complex_opt2).bar.(protobuf_unittest.corge).qux = 2008;
|
281
|
+
option (complex_opt2).(garply).foo = 741;
|
282
|
+
option (complex_opt2).(garply).(.protobuf_unittest.quux) = 1998;
|
283
|
+
option (complex_opt2).(protobuf_unittest.garply).(corge).qux = 2121;
|
284
|
+
option (ComplexOptionType2.ComplexOptionType4.complex_opt4).waldo = 1971;
|
285
|
+
option (complex_opt2).fred.waldo = 321;
|
286
|
+
option (complex_opt2).barney = { waldo: 101 };
|
287
|
+
option (complex_opt2).barney = { waldo: 212 };
|
288
|
+
option (protobuf_unittest.complex_opt3).qux = 9;
|
289
|
+
option (repeated_opt1) = 1;
|
290
|
+
option (repeated_opt1) = 2;
|
291
|
+
option (repeated_opt2) = { qux: 3 };
|
292
|
+
option (repeated_opt2) = { qux: 4 };
|
293
|
+
/*option (complex_opt3).complexoptiontype5.plugh = 22;*/
|
294
|
+
/*option (complexopt6).xyzzy = 24;*/
|
295
|
+
}
|
296
|
+
|
297
|
+
// ------------------------------------------------------
|
298
|
+
// Definitions for testing aggregate option parsing.
|
299
|
+
// See descriptor_unittest.cc.
|
300
|
+
|
301
|
+
message AggregateMessageSet {
|
302
|
+
option message_set_wire_format = false;
|
303
|
+
extensions 4 to max;
|
304
|
+
}
|
305
|
+
|
306
|
+
message AggregateMessageSetElement {
|
307
|
+
extend AggregateMessageSet {
|
308
|
+
optional AggregateMessageSetElement message_set_extension = 15447542;
|
309
|
+
}
|
310
|
+
optional string s = 1;
|
311
|
+
}
|
312
|
+
|
313
|
+
// A helper type used to test aggregate option parsing
|
314
|
+
message Aggregate {
|
315
|
+
optional int32 i = 1;
|
316
|
+
optional string s = 2;
|
317
|
+
|
318
|
+
// A nested object
|
319
|
+
optional Aggregate sub = 3;
|
320
|
+
|
321
|
+
// To test the parsing of extensions inside aggregate values
|
322
|
+
optional google.protobuf.FileOptions file = 4;
|
323
|
+
extend google.protobuf.FileOptions {
|
324
|
+
optional Aggregate nested = 15476903;
|
325
|
+
}
|
326
|
+
|
327
|
+
// An embedded message set
|
328
|
+
optional AggregateMessageSet mset = 5;
|
329
|
+
}
|
330
|
+
|
331
|
+
// Allow Aggregate to be used as an option at all possible locations
|
332
|
+
// in the .proto grammer.
|
333
|
+
extend google.protobuf.FileOptions { optional Aggregate fileopt = 15478479; }
|
334
|
+
extend google.protobuf.MessageOptions { optional Aggregate msgopt = 15480088; }
|
335
|
+
extend google.protobuf.FieldOptions { optional Aggregate fieldopt = 15481374; }
|
336
|
+
extend google.protobuf.EnumOptions { optional Aggregate enumopt = 15483218; }
|
337
|
+
extend google.protobuf.EnumValueOptions { optional Aggregate enumvalopt = 15486921; }
|
338
|
+
extend google.protobuf.ServiceOptions { optional Aggregate serviceopt = 15497145; }
|
339
|
+
extend google.protobuf.MethodOptions { optional Aggregate methodopt = 15512713; }
|
340
|
+
|
341
|
+
// Try using AggregateOption at different points in the proto grammar
|
342
|
+
option (fileopt) = {
|
343
|
+
s: 'FileAnnotation'
|
344
|
+
// Also test the handling of comments
|
345
|
+
/* of both types */ i: 100
|
346
|
+
|
347
|
+
sub { s: 'NestedFileAnnotation' }
|
348
|
+
|
349
|
+
// Include a google.protobuf.FileOptions and recursively extend it with
|
350
|
+
// another fileopt.
|
351
|
+
file {
|
352
|
+
[protobuf_unittest.fileopt] {
|
353
|
+
s:'FileExtensionAnnotation'
|
354
|
+
}
|
355
|
+
}
|
356
|
+
|
357
|
+
// A message set inside an option value
|
358
|
+
mset {
|
359
|
+
[protobuf_unittest.AggregateMessageSetElement.message_set_extension] {
|
360
|
+
s: 'EmbeddedMessageSetElement'
|
361
|
+
}
|
362
|
+
}
|
363
|
+
};
|
364
|
+
|
365
|
+
message AggregateMessage {
|
366
|
+
option (msgopt) = { i:101 s:'MessageAnnotation' };
|
367
|
+
optional int32 fieldname = 1 [(fieldopt) = { s:'FieldAnnotation' }];
|
368
|
+
}
|
369
|
+
|
370
|
+
service AggregateService {
|
371
|
+
option (serviceopt) = { s:'ServiceAnnotation' };
|
372
|
+
rpc Method (AggregateMessage) returns (AggregateMessage) {
|
373
|
+
option (methodopt) = { s:'MethodAnnotation' };
|
374
|
+
}
|
375
|
+
}
|
376
|
+
|
377
|
+
enum AggregateEnum {
|
378
|
+
option (enumopt) = { s:'EnumAnnotation' };
|
379
|
+
// TODO: support enum value options
|
380
|
+
VALUE = 1 [(enumvalopt) = { s:'EnumValueAnnotation' }];
|
381
|
+
}
|
382
|
+
|
383
|
+
// Test custom options for nested type.
|
384
|
+
message NestedOptionType {
|
385
|
+
message NestedMessage {
|
386
|
+
option (message_opt1) = 1001;
|
387
|
+
optional int32 nested_field = 1 [(field_opt1) = 1002];
|
388
|
+
}
|
389
|
+
enum NestedEnum {
|
390
|
+
option (enum_opt1) = 1003;
|
391
|
+
// TODO: support enum value options
|
392
|
+
NESTED_ENUM_VALUE = 1 [(enum_value_opt1) = 1004];
|
393
|
+
}
|
394
|
+
extend google.protobuf.FileOptions {
|
395
|
+
optional int32 nested_extension = 7912573 [(field_opt2) = 1005];
|
396
|
+
}
|
397
|
+
}
|
398
|
+
|
399
|
+
// Custom message option that has a required enum field.
|
400
|
+
// WARNING: this is strongly discouraged!
|
401
|
+
message OldOptionType {
|
402
|
+
enum TestEnum {
|
403
|
+
OLD_VALUE = 0;
|
404
|
+
}
|
405
|
+
required TestEnum value = 1;
|
406
|
+
}
|
407
|
+
|
408
|
+
// Updated version of the custom option above.
|
409
|
+
message NewOptionType {
|
410
|
+
enum TestEnum {
|
411
|
+
OLD_VALUE = 0;
|
412
|
+
NEW_VALUE = 1;
|
413
|
+
}
|
414
|
+
required TestEnum value = 1;
|
415
|
+
}
|
416
|
+
|
417
|
+
extend google.protobuf.MessageOptions {
|
418
|
+
optional OldOptionType required_enum_opt = 106161807;
|
419
|
+
}
|
420
|
+
|
421
|
+
// Test message using the "required_enum_opt" option defined above.
|
422
|
+
message TestMessageWithRequiredEnumOption {
|
423
|
+
option (required_enum_opt) = { value: OLD_VALUE };
|
424
|
+
}
|
@@ -36,6 +36,14 @@ module Protobuf_unittest_import
|
|
36
36
|
class ImportMessage < ::Protobuf::Message; end
|
37
37
|
|
38
38
|
|
39
|
+
##
|
40
|
+
# File Options
|
41
|
+
#
|
42
|
+
set_option :java_package, "com.google.protobuf.test"
|
43
|
+
set_option :optimize_for, ::Google::Protobuf::FileOptions::OptimizeMode::SPEED
|
44
|
+
set_option :cc_enable_arenas, true
|
45
|
+
|
46
|
+
|
39
47
|
##
|
40
48
|
# Message Fields
|
41
49
|
#
|
@@ -6,6 +6,12 @@
|
|
6
6
|
require 'protobuf'
|
7
7
|
require 'protobuf/rpc/service'
|
8
8
|
|
9
|
+
|
10
|
+
##
|
11
|
+
# Imports
|
12
|
+
#
|
13
|
+
require 'google/protobuf/descriptor.pb'
|
14
|
+
|
9
15
|
module Test
|
10
16
|
::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions }
|
11
17
|
|
@@ -13,10 +19,14 @@ module Test
|
|
13
19
|
# Enum Classes
|
14
20
|
#
|
15
21
|
class StatusType < ::Protobuf::Enum
|
22
|
+
set_option :allow_alias, true
|
23
|
+
set_option :".test.enum_option", -789
|
24
|
+
|
16
25
|
define :PENDING, 0
|
17
26
|
define :ENABLED, 1
|
18
27
|
define :DISABLED, 2
|
19
28
|
define :DELETED, 3
|
29
|
+
define :ALIASED, 3
|
20
30
|
end
|
21
31
|
|
22
32
|
|
@@ -47,6 +57,13 @@ module Test
|
|
47
57
|
|
48
58
|
|
49
59
|
|
60
|
+
##
|
61
|
+
# File Options
|
62
|
+
#
|
63
|
+
set_option :cc_generic_services, true
|
64
|
+
set_option :".test.file_option", 9876543210
|
65
|
+
|
66
|
+
|
50
67
|
##
|
51
68
|
# Message Fields
|
52
69
|
#
|
@@ -62,7 +79,11 @@ module Test
|
|
62
79
|
end
|
63
80
|
|
64
81
|
class Resource
|
65
|
-
|
82
|
+
# Message Options
|
83
|
+
set_option :map_entry, false
|
84
|
+
set_option :".test.message_option", -56
|
85
|
+
|
86
|
+
required :string, :name, 1, :ctype => ::Google::Protobuf::FieldOptions::CType::CORD, :".test.field_option" => 8765432109
|
66
87
|
optional :int64, :date_created, 2
|
67
88
|
optional ::Test::StatusType, :status, 3
|
68
89
|
repeated ::Test::StatusType, :repeated_enum, 4
|
@@ -106,11 +127,42 @@ module Test
|
|
106
127
|
end
|
107
128
|
|
108
129
|
|
130
|
+
##
|
131
|
+
# Extended Message Fields
|
132
|
+
#
|
133
|
+
class ::Google::Protobuf::FileOptions < ::Protobuf::Message
|
134
|
+
optional :uint64, :".test.file_option", 9585869, :extension => true
|
135
|
+
end
|
136
|
+
|
137
|
+
class ::Google::Protobuf::FieldOptions < ::Protobuf::Message
|
138
|
+
optional :uint64, :".test.field_option", 858769, :extension => true
|
139
|
+
end
|
140
|
+
|
141
|
+
class ::Google::Protobuf::EnumOptions < ::Protobuf::Message
|
142
|
+
optional :int64, :".test.enum_option", 590284, :extension => true
|
143
|
+
end
|
144
|
+
|
145
|
+
class ::Google::Protobuf::MessageOptions < ::Protobuf::Message
|
146
|
+
optional :int64, :".test.message_option", 485969, :extension => true
|
147
|
+
end
|
148
|
+
|
149
|
+
class ::Google::Protobuf::ServiceOptions < ::Protobuf::Message
|
150
|
+
optional :int64, :".test.service_option", 5869607, :extension => true
|
151
|
+
end
|
152
|
+
|
153
|
+
class ::Google::Protobuf::MethodOptions < ::Protobuf::Message
|
154
|
+
optional :int64, :".test.method_option", 7893233, :extension => true
|
155
|
+
end
|
156
|
+
|
157
|
+
|
109
158
|
##
|
110
159
|
# Service Classes
|
111
160
|
#
|
112
161
|
class ResourceService < ::Protobuf::Rpc::Service
|
113
|
-
|
162
|
+
set_option :".test.service_option", -9876543210
|
163
|
+
rpc :find, ::Test::ResourceFindRequest, ::Test::Resource do
|
164
|
+
set_option :".test.method_option", 2
|
165
|
+
end
|
114
166
|
rpc :find_with_rpc_failed, ::Test::ResourceFindRequest, ::Test::Resource
|
115
167
|
rpc :find_with_sleep, ::Test::ResourceSleepRequest, ::Test::Resource
|
116
168
|
rpc :find_not_implemented, ::Test::ResourceFindRequest, ::Test::Resource
|
@@ -1,12 +1,45 @@
|
|
1
1
|
syntax = "proto2";
|
2
2
|
|
3
|
+
import "google/protobuf/descriptor.proto";
|
4
|
+
|
3
5
|
package test;
|
4
6
|
|
7
|
+
option cc_generic_services = true;
|
8
|
+
option (file_option) = 9876543210;
|
9
|
+
|
10
|
+
extend google.protobuf.FileOptions {
|
11
|
+
optional uint64 file_option = 9585869;
|
12
|
+
}
|
13
|
+
|
14
|
+
extend google.protobuf.FieldOptions {
|
15
|
+
optional uint64 field_option = 858769;
|
16
|
+
}
|
17
|
+
|
18
|
+
extend google.protobuf.EnumOptions {
|
19
|
+
optional int64 enum_option = 590284;
|
20
|
+
}
|
21
|
+
|
22
|
+
extend google.protobuf.MessageOptions {
|
23
|
+
optional int64 message_option = 485969;
|
24
|
+
}
|
25
|
+
|
26
|
+
extend google.protobuf.ServiceOptions {
|
27
|
+
optional int64 service_option = 5869607;
|
28
|
+
}
|
29
|
+
|
30
|
+
extend google.protobuf.MethodOptions {
|
31
|
+
optional int64 method_option = 7893233;
|
32
|
+
}
|
33
|
+
|
5
34
|
enum StatusType {
|
35
|
+
option allow_alias = true;
|
36
|
+
option (enum_option) = -789;
|
37
|
+
|
6
38
|
PENDING = 0;
|
7
39
|
ENABLED = 1;
|
8
40
|
DISABLED = 2;
|
9
41
|
DELETED = 3;
|
42
|
+
ALIASED = 3;
|
10
43
|
}
|
11
44
|
|
12
45
|
message ResourceFindRequest {
|
@@ -21,9 +54,12 @@ message ResourceSleepRequest {
|
|
21
54
|
}
|
22
55
|
|
23
56
|
message Resource {
|
57
|
+
option map_entry = false;
|
58
|
+
option (message_option) = -56;
|
59
|
+
|
24
60
|
extensions 100 to max;
|
25
61
|
|
26
|
-
required string name = 1;
|
62
|
+
required string name = 1 [(field_option) = 8765432109, ctype = CORD];
|
27
63
|
optional int64 date_created = 2;
|
28
64
|
optional StatusType status = 3;
|
29
65
|
repeated StatusType repeated_enum = 4;
|
@@ -89,7 +125,11 @@ extend Nested.NestedLevelOne {
|
|
89
125
|
}
|
90
126
|
|
91
127
|
service ResourceService {
|
92
|
-
|
128
|
+
option (service_option) = -9876543210;
|
129
|
+
|
130
|
+
rpc Find (ResourceFindRequest) returns (Resource) {
|
131
|
+
option (method_option) = 2;
|
132
|
+
}
|
93
133
|
rpc FindWithRpcFailed (ResourceFindRequest) returns (Resource);
|
94
134
|
rpc FindWithSleep (ResourceSleepRequest) returns (Resource);
|
95
135
|
rpc FindNotImplemented (ResourceFindRequest) returns (Resource);
|