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