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
// A custom file option (defined below).
39
option (file_opt1) = 9876543210;
41
import "google/protobuf/descriptor.proto";
43
// We don't put this in a package within proto2 because we need to make sure
44
// that the generated code doesn't depend on being in the proto2 namespace.
45
package protobuf_unittest;
48
// Some simple test custom options of various types.
50
extend google.protobuf.FileOptions {
51
optional uint64 file_opt1 = 7736974;
54
extend google.protobuf.MessageOptions {
55
optional int32 message_opt1 = 7739036;
58
extend google.protobuf.FieldOptions {
59
optional fixed64 field_opt1 = 7740936;
60
// This is useful for testing that we correctly register default values for
62
optional int32 field_opt2 = 7753913 [default=42];
65
extend google.protobuf.EnumOptions {
66
optional sfixed32 enum_opt1 = 7753576;
69
extend google.protobuf.EnumValueOptions {
70
optional int32 enum_value_opt1 = 1560678;
73
extend google.protobuf.ServiceOptions {
74
optional sint64 service_opt1 = 7887650;
82
extend google.protobuf.MethodOptions {
83
optional MethodOpt1 method_opt1 = 7890860;
86
// A test message with custom options at all possible locations (and also some
87
// regular options, to make sure they interact nicely).
88
message TestMessageWithCustomOptions {
89
option message_set_wire_format = false;
91
option (message_opt1) = -56;
93
optional string field1 = 1 [ctype=CORD,
94
(field_opt1)=8765432109];
97
option (enum_opt1) = -789;
100
ANENUM_VAL2 = 2 [(enum_value_opt1) = 123];
105
// A test RPC service with custom options at all possible locations (and also
106
// some regular options, to make sure they interact nicely).
107
message CustomOptionFooRequest {
110
message CustomOptionFooResponse {
113
service TestServiceWithCustomOptions {
114
option (service_opt1) = -9876543210;
116
rpc Foo(CustomOptionFooRequest) returns (CustomOptionFooResponse) {
117
option (method_opt1) = METHODOPT1_VAL2;
123
// Options of every possible field type, so we can test them all exhaustively.
125
message DummyMessageContainingEnum {
127
TEST_OPTION_ENUM_TYPE1 = 22;
128
TEST_OPTION_ENUM_TYPE2 = -23;
132
message DummyMessageInvalidAsOptionType {
135
extend google.protobuf.MessageOptions {
136
optional bool bool_opt = 7706090;
137
optional int32 int32_opt = 7705709;
138
optional int64 int64_opt = 7705542;
139
optional uint32 uint32_opt = 7704880;
140
optional uint64 uint64_opt = 7702367;
141
optional sint32 sint32_opt = 7701568;
142
optional sint64 sint64_opt = 7700863;
143
optional fixed32 fixed32_opt = 7700307;
144
optional fixed64 fixed64_opt = 7700194;
145
optional sfixed32 sfixed32_opt = 7698645;
146
optional sfixed64 sfixed64_opt = 7685475;
147
optional float float_opt = 7675390;
148
optional double double_opt = 7673293;
149
optional string string_opt = 7673285;
150
optional bytes bytes_opt = 7673238;
151
optional DummyMessageContainingEnum.TestEnumType enum_opt = 7673233;
152
optional DummyMessageInvalidAsOptionType message_type_opt = 7665967;
155
message CustomOptionMinIntegerValues {
156
option (bool_opt) = false;
157
option (int32_opt) = -0x80000000;
158
option (int64_opt) = -0x8000000000000000;
159
option (uint32_opt) = 0;
160
option (uint64_opt) = 0;
161
option (sint32_opt) = -0x80000000;
162
option (sint64_opt) = -0x8000000000000000;
163
option (fixed32_opt) = 0;
164
option (fixed64_opt) = 0;
165
option (sfixed32_opt) = -0x80000000;
166
option (sfixed64_opt) = -0x8000000000000000;
169
message CustomOptionMaxIntegerValues {
170
option (bool_opt) = true;
171
option (int32_opt) = 0x7FFFFFFF;
172
option (int64_opt) = 0x7FFFFFFFFFFFFFFF;
173
option (uint32_opt) = 0xFFFFFFFF;
174
option (uint64_opt) = 0xFFFFFFFFFFFFFFFF;
175
option (sint32_opt) = 0x7FFFFFFF;
176
option (sint64_opt) = 0x7FFFFFFFFFFFFFFF;
177
option (fixed32_opt) = 0xFFFFFFFF;
178
option (fixed64_opt) = 0xFFFFFFFFFFFFFFFF;
179
option (sfixed32_opt) = 0x7FFFFFFF;
180
option (sfixed64_opt) = 0x7FFFFFFFFFFFFFFF;
183
message CustomOptionOtherValues {
184
option (int32_opt) = -100; // To test sign-extension.
185
option (float_opt) = 12.3456789;
186
option (double_opt) = 1.234567890123456789;
187
option (string_opt) = "Hello, \"World\"";
188
option (bytes_opt) = "Hello\0World";
189
option (enum_opt) = TEST_OPTION_ENUM_TYPE2;
192
message SettingRealsFromPositiveInts {
193
option (float_opt) = 12;
194
option (double_opt) = 154;
197
message SettingRealsFromNegativeInts {
198
option (float_opt) = -12;
199
option (double_opt) = -154;
202
// Options of complex message types, themselves combined and extended in
205
message ComplexOptionType1 {
206
optional int32 foo = 1;
208
extensions 100 to max;
211
message ComplexOptionType2 {
212
optional ComplexOptionType1 bar = 1;
213
optional int32 baz = 2;
215
message ComplexOptionType4 {
216
optional int32 waldo = 1;
218
extend google.protobuf.MessageOptions {
219
optional ComplexOptionType4 complex_opt4 = 7633546;
223
optional ComplexOptionType4 fred = 3;
225
extensions 100 to max;
228
message ComplexOptionType3 {
229
optional int32 qux = 1;
231
optional group ComplexOptionType5 = 2 {
232
optional int32 plugh = 3;
236
extend ComplexOptionType1 {
237
optional int32 quux = 7663707;
238
optional ComplexOptionType3 corge = 7663442;
241
extend ComplexOptionType2 {
242
optional int32 grault = 7650927;
243
optional ComplexOptionType1 garply = 7649992;
246
extend google.protobuf.MessageOptions {
247
optional protobuf_unittest.ComplexOptionType1 complex_opt1 = 7646756;
248
optional ComplexOptionType2 complex_opt2 = 7636949;
249
optional ComplexOptionType3 complex_opt3 = 7636463;
250
optional group ComplexOpt6 = 7595468 {
251
optional int32 xyzzy = 7593951;
255
// Note that we try various different ways of naming the same extension.
256
message VariousComplexOptions {
257
option (.protobuf_unittest.complex_opt1).foo = 42;
258
option (protobuf_unittest.complex_opt1).(.protobuf_unittest.quux) = 324;
259
option (.protobuf_unittest.complex_opt1).(protobuf_unittest.corge).qux = 876;
260
option (complex_opt2).baz = 987;
261
option (complex_opt2).(grault) = 654;
262
option (complex_opt2).bar.foo = 743;
263
option (complex_opt2).bar.(quux) = 1999;
264
option (complex_opt2).bar.(protobuf_unittest.corge).qux = 2008;
265
option (complex_opt2).(garply).foo = 741;
266
option (complex_opt2).(garply).(.protobuf_unittest.quux) = 1998;
267
option (complex_opt2).(protobuf_unittest.garply).(corge).qux = 2121;
268
option (ComplexOptionType2.ComplexOptionType4.complex_opt4).waldo = 1971;
269
option (complex_opt2).fred.waldo = 321;
270
option (protobuf_unittest.complex_opt3).qux = 9;
271
option (complex_opt3).complexoptiontype5.plugh = 22;
272
option (complexopt6).xyzzy = 24;