1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // http://code.google.com/p/protobuf/
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
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
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.
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.
31 // Author: benjy@google.com (Benjy Weinberger)
32 // Based on original Protocol Buffers design by
33 // Sanjay Ghemawat, Jeff Dean, and others.
35 // A proto file used to test the "custom options" feature of proto2.
38 // Some generic_services option(s) added automatically.
39 // See: http://go/proto2-generic-services-default
40 option cc_generic_services = true; // auto-added
41 option java_generic_services = true; // auto-added
42 option py_generic_services = true;
44 // A custom file option (defined below).
45 option (file_opt1) = 9876543210;
47 import "google/protobuf/descriptor.proto";
49 // We don't put this in a package within proto2 because we need to make sure
50 // that the generated code doesn't depend on being in the proto2 namespace.
51 package protobuf_unittest;
54 // Some simple test custom options of various types.
56 extend google.protobuf.FileOptions {
57 optional uint64 file_opt1 = 7736974;
60 extend google.protobuf.MessageOptions {
61 optional int32 message_opt1 = 7739036;
64 extend google.protobuf.FieldOptions {
65 optional fixed64 field_opt1 = 7740936;
66 // This is useful for testing that we correctly register default values for
68 optional int32 field_opt2 = 7753913 [default=42];
71 extend google.protobuf.EnumOptions {
72 optional sfixed32 enum_opt1 = 7753576;
75 extend google.protobuf.EnumValueOptions {
76 optional int32 enum_value_opt1 = 1560678;
79 extend google.protobuf.ServiceOptions {
80 optional sint64 service_opt1 = 7887650;
88 extend google.protobuf.MethodOptions {
89 optional MethodOpt1 method_opt1 = 7890860;
92 // A test message with custom options at all possible locations (and also some
93 // regular options, to make sure they interact nicely).
94 message TestMessageWithCustomOptions {
95 option message_set_wire_format = false;
97 option (message_opt1) = -56;
99 optional string field1 = 1 [ctype=CORD,
100 (field_opt1)=8765432109];
103 option (enum_opt1) = -789;
106 ANENUM_VAL2 = 2 [(enum_value_opt1) = 123];
111 // A test RPC service with custom options at all possible locations (and also
112 // some regular options, to make sure they interact nicely).
113 message CustomOptionFooRequest {
116 message CustomOptionFooResponse {
119 message CustomOptionFooClientMessage {
122 message CustomOptionFooServerMessage {
125 service TestServiceWithCustomOptions {
126 option (service_opt1) = -9876543210;
128 rpc Foo(CustomOptionFooRequest) returns (CustomOptionFooResponse) {
129 option (method_opt1) = METHODOPT1_VAL2;
135 // Options of every possible field type, so we can test them all exhaustively.
137 message DummyMessageContainingEnum {
139 TEST_OPTION_ENUM_TYPE1 = 22;
140 TEST_OPTION_ENUM_TYPE2 = -23;
144 message DummyMessageInvalidAsOptionType {
147 extend google.protobuf.MessageOptions {
148 optional bool bool_opt = 7706090;
149 optional int32 int32_opt = 7705709;
150 optional int64 int64_opt = 7705542;
151 optional uint32 uint32_opt = 7704880;
152 optional uint64 uint64_opt = 7702367;
153 optional sint32 sint32_opt = 7701568;
154 optional sint64 sint64_opt = 7700863;
155 optional fixed32 fixed32_opt = 7700307;
156 optional fixed64 fixed64_opt = 7700194;
157 optional sfixed32 sfixed32_opt = 7698645;
158 optional sfixed64 sfixed64_opt = 7685475;
159 optional float float_opt = 7675390;
160 optional double double_opt = 7673293;
161 optional string string_opt = 7673285;
162 optional bytes bytes_opt = 7673238;
163 optional DummyMessageContainingEnum.TestEnumType enum_opt = 7673233;
164 optional DummyMessageInvalidAsOptionType message_type_opt = 7665967;
167 message CustomOptionMinIntegerValues {
168 option (bool_opt) = false;
169 option (int32_opt) = -0x80000000;
170 option (int64_opt) = -0x8000000000000000;
171 option (uint32_opt) = 0;
172 option (uint64_opt) = 0;
173 option (sint32_opt) = -0x80000000;
174 option (sint64_opt) = -0x8000000000000000;
175 option (fixed32_opt) = 0;
176 option (fixed64_opt) = 0;
177 option (sfixed32_opt) = -0x80000000;
178 option (sfixed64_opt) = -0x8000000000000000;
181 message CustomOptionMaxIntegerValues {
182 option (bool_opt) = true;
183 option (int32_opt) = 0x7FFFFFFF;
184 option (int64_opt) = 0x7FFFFFFFFFFFFFFF;
185 option (uint32_opt) = 0xFFFFFFFF;
186 option (uint64_opt) = 0xFFFFFFFFFFFFFFFF;
187 option (sint32_opt) = 0x7FFFFFFF;
188 option (sint64_opt) = 0x7FFFFFFFFFFFFFFF;
189 option (fixed32_opt) = 0xFFFFFFFF;
190 option (fixed64_opt) = 0xFFFFFFFFFFFFFFFF;
191 option (sfixed32_opt) = 0x7FFFFFFF;
192 option (sfixed64_opt) = 0x7FFFFFFFFFFFFFFF;
195 message CustomOptionOtherValues {
196 option (int32_opt) = -100; // To test sign-extension.
197 option (float_opt) = 12.3456789;
198 option (double_opt) = 1.234567890123456789;
199 option (string_opt) = "Hello, \"World\"";
200 option (bytes_opt) = "Hello\0World";
201 option (enum_opt) = TEST_OPTION_ENUM_TYPE2;
204 message SettingRealsFromPositiveInts {
205 option (float_opt) = 12;
206 option (double_opt) = 154;
209 message SettingRealsFromNegativeInts {
210 option (float_opt) = -12;
211 option (double_opt) = -154;
214 // Options of complex message types, themselves combined and extended in
217 message ComplexOptionType1 {
218 optional int32 foo = 1;
219 optional int32 foo2 = 2;
220 optional int32 foo3 = 3;
222 extensions 100 to max;
225 message ComplexOptionType2 {
226 optional ComplexOptionType1 bar = 1;
227 optional int32 baz = 2;
229 message ComplexOptionType4 {
230 optional int32 waldo = 1;
232 extend google.protobuf.MessageOptions {
233 optional ComplexOptionType4 complex_opt4 = 7633546;
237 optional ComplexOptionType4 fred = 3;
239 extensions 100 to max;
242 message ComplexOptionType3 {
243 optional int32 qux = 1;
245 optional group ComplexOptionType5 = 2 {
246 optional int32 plugh = 3;
250 extend ComplexOptionType1 {
251 optional int32 quux = 7663707;
252 optional ComplexOptionType3 corge = 7663442;
255 extend ComplexOptionType2 {
256 optional int32 grault = 7650927;
257 optional ComplexOptionType1 garply = 7649992;
260 extend google.protobuf.MessageOptions {
261 optional protobuf_unittest.ComplexOptionType1 complex_opt1 = 7646756;
262 optional ComplexOptionType2 complex_opt2 = 7636949;
263 optional ComplexOptionType3 complex_opt3 = 7636463;
264 optional group ComplexOpt6 = 7595468 {
265 optional int32 xyzzy = 7593951;
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 (complex_opt2).baz = 987;
275 option (complex_opt2).(grault) = 654;
276 option (complex_opt2).bar.foo = 743;
277 option (complex_opt2).bar.(quux) = 1999;
278 option (complex_opt2).bar.(protobuf_unittest.corge).qux = 2008;
279 option (complex_opt2).(garply).foo = 741;
280 option (complex_opt2).(garply).(.protobuf_unittest.quux) = 1998;
281 option (complex_opt2).(protobuf_unittest.garply).(corge).qux = 2121;
282 option (ComplexOptionType2.ComplexOptionType4.complex_opt4).waldo = 1971;
283 option (complex_opt2).fred.waldo = 321;
284 option (protobuf_unittest.complex_opt3).qux = 9;
285 option (complex_opt3).complexoptiontype5.plugh = 22;
286 option (complexopt6).xyzzy = 24;
289 // ------------------------------------------------------
290 // Definitions for testing aggregate option parsing.
291 // See descriptor_unittest.cc.
293 message AggregateMessageSet {
294 option message_set_wire_format = true;
298 message AggregateMessageSetElement {
299 extend AggregateMessageSet {
300 optional AggregateMessageSetElement message_set_extension = 15447542;
302 optional string s = 1;
305 // A helper type used to test aggregate option parsing
307 optional int32 i = 1;
308 optional string s = 2;
311 optional Aggregate sub = 3;
313 // To test the parsing of extensions inside aggregate values
314 optional google.protobuf.FileOptions file = 4;
315 extend google.protobuf.FileOptions {
316 optional Aggregate nested = 15476903;
319 // An embedded message set
320 optional AggregateMessageSet mset = 5;
323 // Allow Aggregate to be used as an option at all possible locations
324 // in the .proto grammer.
325 extend google.protobuf.FileOptions { optional Aggregate fileopt = 15478479; }
326 extend google.protobuf.MessageOptions { optional Aggregate msgopt = 15480088; }
327 extend google.protobuf.FieldOptions { optional Aggregate fieldopt = 15481374; }
328 extend google.protobuf.EnumOptions { optional Aggregate enumopt = 15483218; }
329 extend google.protobuf.EnumValueOptions { optional Aggregate enumvalopt = 15486921; }
330 extend google.protobuf.ServiceOptions { optional Aggregate serviceopt = 15497145; }
331 extend google.protobuf.MethodOptions { optional Aggregate methodopt = 15512713; }
333 // Try using AggregateOption at different points in the proto grammar
336 // Also test the handling of comments
337 /* of both types */ i: 100
339 sub { s: 'NestedFileAnnotation' }
341 // Include a google.protobuf.FileOptions and recursively extend it with
344 [protobuf_unittest.fileopt] {
345 s:'FileExtensionAnnotation'
349 // A message set inside an option value
351 [protobuf_unittest.AggregateMessageSetElement.message_set_extension] {
352 s: 'EmbeddedMessageSetElement'
357 message AggregateMessage {
358 option (msgopt) = { i:101 s:'MessageAnnotation' };
359 optional int32 fieldname = 1 [(fieldopt) = { s:'FieldAnnotation' }];
362 service AggregateService {
363 option (serviceopt) = { s:'ServiceAnnotation' };
364 rpc Method (AggregateMessage) returns (AggregateMessage) {
365 option (methodopt) = { s:'MethodAnnotation' };
370 option (enumopt) = { s:'EnumAnnotation' };
371 VALUE = 1 [(enumvalopt) = { s:'EnumValueAnnotation' }];
374 // Test custom options for nested type.
375 message NestedOptionType {
376 message NestedMessage {
377 option (message_opt1) = 1001;
378 optional int32 nested_field = 1 [(field_opt1) = 1002];
381 option (enum_opt1) = 1003;
382 NESTED_ENUM_VALUE = 1 [(enum_value_opt1) = 1004];
384 extend google.protobuf.FileOptions {
385 optional int32 nested_extension = 7912573 [(field_opt2) = 1005];