Jakob Buchgraber | 2b49f67 | 2017-04-26 15:37:42 +0200 | [diff] [blame] | 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 | // This file is based on unittest_custom_options.proto in |
| 38 | // src/google/protobuf, but is modified for proto3. It could |
| 39 | // potentially be moved into src/google/protobuf, but currently C# |
| 40 | // is the only language that really needs it, as we don't support |
| 41 | // proto2 syntax. It's cut down significantly as proto3 only supports |
| 42 | // extensions for options. |
| 43 | |
| 44 | |
| 45 | syntax = "proto3"; |
| 46 | |
| 47 | // A custom file option (defined below). |
| 48 | option (file_opt1) = 9876543210; |
| 49 | |
| 50 | import "google/protobuf/descriptor.proto"; |
| 51 | |
| 52 | // We don't put this in a package within proto2 because we need to make sure |
| 53 | // that the generated code doesn't depend on being in the proto2 namespace. |
| 54 | package protobuf_unittest; |
| 55 | option csharp_namespace = "UnitTest.Issues.TestProtos"; |
| 56 | |
| 57 | // Some simple test custom options of various types. |
| 58 | |
| 59 | extend google.protobuf.FileOptions { |
| 60 | uint64 file_opt1 = 7736974; |
| 61 | } |
| 62 | |
| 63 | extend google.protobuf.MessageOptions { |
| 64 | int32 message_opt1 = 7739036; |
| 65 | } |
| 66 | |
| 67 | extend google.protobuf.FieldOptions { |
| 68 | fixed64 field_opt1 = 7740936; |
| 69 | } |
| 70 | |
| 71 | extend google.protobuf.OneofOptions { |
| 72 | int32 oneof_opt1 = 7740111; |
| 73 | } |
| 74 | |
| 75 | extend google.protobuf.EnumOptions { |
| 76 | sfixed32 enum_opt1 = 7753576; |
| 77 | } |
| 78 | |
| 79 | extend google.protobuf.EnumValueOptions { |
| 80 | int32 enum_value_opt1 = 1560678; |
| 81 | } |
| 82 | |
| 83 | extend google.protobuf.ServiceOptions { |
| 84 | sint64 service_opt1 = 7887650; |
| 85 | } |
| 86 | |
| 87 | enum MethodOpt1 { |
| 88 | METHODOPT1_UNSPECIFIED = 0; |
| 89 | METHODOPT1_VAL1 = 1; |
| 90 | METHODOPT1_VAL2 = 2; |
| 91 | } |
| 92 | |
| 93 | extend google.protobuf.MethodOptions { |
| 94 | MethodOpt1 method_opt1 = 7890860; |
| 95 | } |
| 96 | |
| 97 | // A test message with custom options at all possible locations (and also some |
| 98 | // regular options, to make sure they interact nicely). |
| 99 | message TestMessageWithCustomOptions { |
| 100 | option message_set_wire_format = false; |
| 101 | |
| 102 | option (message_opt1) = -56; |
| 103 | |
| 104 | string field1 = 1 [ctype=CORD, |
| 105 | (field_opt1)=8765432109]; |
| 106 | |
| 107 | oneof AnOneof { |
| 108 | option (oneof_opt1) = -99; |
| 109 | int32 oneof_field = 2; |
| 110 | } |
| 111 | |
| 112 | enum AnEnum { |
| 113 | option (enum_opt1) = -789; |
| 114 | ANENUM_UNSPECIFIED = 0; |
| 115 | ANENUM_VAL1 = 1; |
| 116 | ANENUM_VAL2 = 2 [(enum_value_opt1) = 123]; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | |
| 121 | // A test RPC service with custom options at all possible locations (and also |
| 122 | // some regular options, to make sure they interact nicely). |
| 123 | message CustomOptionFooRequest { |
| 124 | } |
| 125 | |
| 126 | message CustomOptionFooResponse { |
| 127 | } |
| 128 | |
| 129 | message CustomOptionFooClientMessage { |
| 130 | } |
| 131 | |
| 132 | message CustomOptionFooServerMessage { |
| 133 | } |
| 134 | |
| 135 | service TestServiceWithCustomOptions { |
| 136 | option (service_opt1) = -9876543210; |
| 137 | |
| 138 | rpc Foo(CustomOptionFooRequest) returns (CustomOptionFooResponse) { |
| 139 | option (method_opt1) = METHODOPT1_VAL2; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | |
| 144 | |
| 145 | // Options of every possible field type, so we can test them all exhaustively. |
| 146 | |
| 147 | message DummyMessageContainingEnum { |
| 148 | enum TestEnumType { |
| 149 | TEST_OPTION_ENUM_UNSPECIFIED = 0; |
| 150 | TEST_OPTION_ENUM_TYPE1 = 22; |
| 151 | TEST_OPTION_ENUM_TYPE2 = -23; |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | message DummyMessageInvalidAsOptionType { |
| 156 | } |
| 157 | |
| 158 | extend google.protobuf.MessageOptions { |
| 159 | bool bool_opt = 7706090; |
| 160 | int32 int32_opt = 7705709; |
| 161 | int64 int64_opt = 7705542; |
| 162 | uint32 uint32_opt = 7704880; |
| 163 | uint64 uint64_opt = 7702367; |
| 164 | sint32 sint32_opt = 7701568; |
| 165 | sint64 sint64_opt = 7700863; |
| 166 | fixed32 fixed32_opt = 7700307; |
| 167 | fixed64 fixed64_opt = 7700194; |
| 168 | sfixed32 sfixed32_opt = 7698645; |
| 169 | sfixed64 sfixed64_opt = 7685475; |
| 170 | float float_opt = 7675390; |
| 171 | double double_opt = 7673293; |
| 172 | string string_opt = 7673285; |
| 173 | bytes bytes_opt = 7673238; |
| 174 | DummyMessageContainingEnum.TestEnumType enum_opt = 7673233; |
| 175 | DummyMessageInvalidAsOptionType message_type_opt = 7665967; |
| 176 | } |
| 177 | |
| 178 | message CustomOptionMinIntegerValues { |
| 179 | option (bool_opt) = false; |
| 180 | option (int32_opt) = -0x80000000; |
| 181 | option (int64_opt) = -0x8000000000000000; |
| 182 | option (uint32_opt) = 0; |
| 183 | option (uint64_opt) = 0; |
| 184 | option (sint32_opt) = -0x80000000; |
| 185 | option (sint64_opt) = -0x8000000000000000; |
| 186 | option (fixed32_opt) = 0; |
| 187 | option (fixed64_opt) = 0; |
| 188 | option (sfixed32_opt) = -0x80000000; |
| 189 | option (sfixed64_opt) = -0x8000000000000000; |
| 190 | } |
| 191 | |
| 192 | message CustomOptionMaxIntegerValues { |
| 193 | option (bool_opt) = true; |
| 194 | option (int32_opt) = 0x7FFFFFFF; |
| 195 | option (int64_opt) = 0x7FFFFFFFFFFFFFFF; |
| 196 | option (uint32_opt) = 0xFFFFFFFF; |
| 197 | option (uint64_opt) = 0xFFFFFFFFFFFFFFFF; |
| 198 | option (sint32_opt) = 0x7FFFFFFF; |
| 199 | option (sint64_opt) = 0x7FFFFFFFFFFFFFFF; |
| 200 | option (fixed32_opt) = 0xFFFFFFFF; |
| 201 | option (fixed64_opt) = 0xFFFFFFFFFFFFFFFF; |
| 202 | option (sfixed32_opt) = 0x7FFFFFFF; |
| 203 | option (sfixed64_opt) = 0x7FFFFFFFFFFFFFFF; |
| 204 | } |
| 205 | |
| 206 | message CustomOptionOtherValues { |
| 207 | option (int32_opt) = -100; // To test sign-extension. |
| 208 | option (float_opt) = 12.3456789; |
| 209 | option (double_opt) = 1.234567890123456789; |
| 210 | option (string_opt) = "Hello, \"World\""; |
| 211 | option (bytes_opt) = "Hello\0World"; |
| 212 | option (enum_opt) = TEST_OPTION_ENUM_TYPE2; |
| 213 | } |
| 214 | |
| 215 | message SettingRealsFromPositiveInts { |
| 216 | option (float_opt) = 12; |
| 217 | option (double_opt) = 154; |
| 218 | } |
| 219 | |
| 220 | message SettingRealsFromNegativeInts { |
| 221 | option (float_opt) = -12; |
| 222 | option (double_opt) = -154; |
| 223 | } |
| 224 | |
| 225 | // Options of complex message types, themselves combined and extended in |
| 226 | // various ways. |
| 227 | |
| 228 | message ComplexOptionType1 { |
| 229 | int32 foo = 1; |
| 230 | int32 foo2 = 2; |
| 231 | int32 foo3 = 3; |
| 232 | repeated int32 foo4 = 4; |
| 233 | } |
| 234 | |
| 235 | message ComplexOptionType2 { |
| 236 | ComplexOptionType1 bar = 1; |
| 237 | int32 baz = 2; |
| 238 | |
| 239 | message ComplexOptionType4 { |
| 240 | int32 waldo = 1; |
| 241 | |
| 242 | extend google.protobuf.MessageOptions { |
| 243 | ComplexOptionType4 complex_opt4 = 7633546; |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | ComplexOptionType4 fred = 3; |
| 248 | repeated ComplexOptionType4 barney = 4; |
| 249 | } |
| 250 | |
| 251 | message ComplexOptionType3 { |
| 252 | int32 qux = 1; |
| 253 | } |
| 254 | |
| 255 | extend google.protobuf.MessageOptions { |
| 256 | protobuf_unittest.ComplexOptionType1 complex_opt1 = 7646756; |
| 257 | ComplexOptionType2 complex_opt2 = 7636949; |
| 258 | ComplexOptionType3 complex_opt3 = 7636463; |
| 259 | } |
| 260 | |
| 261 | // Note that we try various different ways of naming the same extension. |
| 262 | message VariousComplexOptions { |
| 263 | option (.protobuf_unittest.complex_opt1).foo = 42; |
| 264 | option (protobuf_unittest.complex_opt1).foo4 = 99; |
| 265 | option (protobuf_unittest.complex_opt1).foo4 = 88; |
| 266 | option (complex_opt2).baz = 987; |
| 267 | option (complex_opt2).bar.foo = 743; |
| 268 | option (ComplexOptionType2.ComplexOptionType4.complex_opt4).waldo = 1971; |
| 269 | option (complex_opt2).fred.waldo = 321; |
| 270 | option (complex_opt2).barney = { waldo: 101 }; |
| 271 | option (complex_opt2).barney = { waldo: 212 }; |
| 272 | option (protobuf_unittest.complex_opt3).qux = 9; |
| 273 | } |
| 274 | |
| 275 | // ------------------------------------------------------ |
| 276 | // Definitions for testing aggregate option parsing. |
| 277 | // See descriptor_unittest.cc. |
| 278 | |
| 279 | // A helper type used to test aggregate option parsing |
| 280 | message Aggregate { |
| 281 | int32 i = 1; |
| 282 | string s = 2; |
| 283 | |
| 284 | // A nested object |
| 285 | Aggregate sub = 3; |
| 286 | } |
| 287 | |
| 288 | // Allow Aggregate to be used as an option at all possible locations |
| 289 | // in the .proto grammer. |
| 290 | extend google.protobuf.FileOptions { Aggregate fileopt = 15478479; } |
| 291 | extend google.protobuf.MessageOptions { Aggregate msgopt = 15480088; } |
| 292 | extend google.protobuf.FieldOptions { Aggregate fieldopt = 15481374; } |
| 293 | extend google.protobuf.EnumOptions { Aggregate enumopt = 15483218; } |
| 294 | extend google.protobuf.EnumValueOptions { Aggregate enumvalopt = 15486921; } |
| 295 | extend google.protobuf.ServiceOptions { Aggregate serviceopt = 15497145; } |
| 296 | extend google.protobuf.MethodOptions { Aggregate methodopt = 15512713; } |
| 297 | |
| 298 | // Try using AggregateOption at different points in the proto grammar |
| 299 | option (fileopt) = { |
| 300 | s: 'FileAnnotation' |
| 301 | // Also test the handling of comments |
| 302 | /* of both types */ i: 100 |
| 303 | |
| 304 | sub { s: 'NestedFileAnnotation' } |
| 305 | }; |
| 306 | |
| 307 | message AggregateMessage { |
| 308 | option (msgopt) = { i:101 s:'MessageAnnotation' }; |
| 309 | int32 fieldname = 1 [(fieldopt) = { s:'FieldAnnotation' }]; |
| 310 | } |
| 311 | |
| 312 | service AggregateService { |
| 313 | option (serviceopt) = { s:'ServiceAnnotation' }; |
| 314 | rpc Method (AggregateMessage) returns (AggregateMessage) { |
| 315 | option (methodopt) = { s:'MethodAnnotation' }; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | enum AggregateEnum { |
| 320 | option (enumopt) = { s:'EnumAnnotation' }; |
| 321 | UNSPECIFIED = 0; |
| 322 | VALUE = 1 [(enumvalopt) = { s:'EnumValueAnnotation' }]; |
| 323 | } |
| 324 | |
| 325 | // Test custom options for nested type. |
| 326 | message NestedOptionType { |
| 327 | message NestedMessage { |
| 328 | option (message_opt1) = 1001; |
| 329 | int32 nested_field = 1 [(field_opt1) = 1002]; |
| 330 | } |
| 331 | enum NestedEnum { |
| 332 | UNSPECIFIED = 0; |
| 333 | option (enum_opt1) = 1003; |
| 334 | NESTED_ENUM_VALUE = 1 [(enum_value_opt1) = 1004]; |
| 335 | } |
| 336 | } |