unittest_custom_options.proto 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. // Additional options required for C# generation. File from copyright
  2. // line onwards is as per original distribution.
  3. import "google/protobuf/csharp_options.proto";
  4. option (google.protobuf.csharp_file_options).namespace = "Google.ProtocolBuffers.TestProtos";
  5. option (google.protobuf.csharp_file_options).umbrella_classname = "UnitTestCustomOptionsProtoFile";
  6. // Protocol Buffers - Google's data interchange format
  7. // Copyright 2008 Google Inc. All rights reserved.
  8. // http://code.google.com/p/protobuf/
  9. //
  10. // Redistribution and use in source and binary forms, with or without
  11. // modification, are permitted provided that the following conditions are
  12. // met:
  13. //
  14. // * Redistributions of source code must retain the above copyright
  15. // notice, this list of conditions and the following disclaimer.
  16. // * Redistributions in binary form must reproduce the above
  17. // copyright notice, this list of conditions and the following disclaimer
  18. // in the documentation and/or other materials provided with the
  19. // distribution.
  20. // * Neither the name of Google Inc. nor the names of its
  21. // contributors may be used to endorse or promote products derived from
  22. // this software without specific prior written permission.
  23. //
  24. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  27. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  28. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  31. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  32. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. // Author: benjy@google.com (Benjy Weinberger)
  36. // Based on original Protocol Buffers design by
  37. // Sanjay Ghemawat, Jeff Dean, and others.
  38. //
  39. // A proto file used to test the "custom options" feature of proto2.
  40. // Some generic_services option(s) added automatically.
  41. // See: http://go/proto2-generic-services-default
  42. option cc_generic_services = true; // auto-added
  43. option java_generic_services = true; // auto-added
  44. option py_generic_services = true;
  45. // A custom file option (defined below).
  46. option (file_opt1) = 9876543210;
  47. import "google/protobuf/descriptor.proto";
  48. // We don't put this in a package within proto2 because we need to make sure
  49. // that the generated code doesn't depend on being in the proto2 namespace.
  50. package protobuf_unittest;
  51. // Some simple test custom options of various types.
  52. extend google.protobuf.FileOptions {
  53. optional uint64 file_opt1 = 7736974;
  54. }
  55. extend google.protobuf.MessageOptions {
  56. optional int32 message_opt1 = 7739036;
  57. }
  58. extend google.protobuf.FieldOptions {
  59. optional fixed64 field_opt1 = 7740936;
  60. // This is useful for testing that we correctly register default values for
  61. // extension options.
  62. optional int32 field_opt2 = 7753913 [default=42];
  63. }
  64. extend google.protobuf.EnumOptions {
  65. optional sfixed32 enum_opt1 = 7753576;
  66. }
  67. extend google.protobuf.EnumValueOptions {
  68. optional int32 enum_value_opt1 = 1560678;
  69. }
  70. extend google.protobuf.ServiceOptions {
  71. optional sint64 service_opt1 = 7887650;
  72. }
  73. enum MethodOpt1 {
  74. METHODOPT1_VAL1 = 1;
  75. METHODOPT1_VAL2 = 2;
  76. }
  77. extend google.protobuf.MethodOptions {
  78. optional MethodOpt1 method_opt1 = 7890860;
  79. }
  80. // A test message with custom options at all possible locations (and also some
  81. // regular options, to make sure they interact nicely).
  82. message TestMessageWithCustomOptions {
  83. option message_set_wire_format = false;
  84. option (message_opt1) = -56;
  85. optional string field1 = 1 [ctype=CORD,
  86. (field_opt1)=8765432109];
  87. enum AnEnum {
  88. option (enum_opt1) = -789;
  89. ANENUM_VAL1 = 1;
  90. ANENUM_VAL2 = 2 [(enum_value_opt1) = 123];
  91. }
  92. }
  93. // A test RPC service with custom options at all possible locations (and also
  94. // some regular options, to make sure they interact nicely).
  95. message CustomOptionFooRequest {
  96. }
  97. message CustomOptionFooResponse {
  98. }
  99. service TestServiceWithCustomOptions {
  100. option (service_opt1) = -9876543210;
  101. rpc Foo(CustomOptionFooRequest) returns (CustomOptionFooResponse) {
  102. option (method_opt1) = METHODOPT1_VAL2;
  103. }
  104. }
  105. // Options of every possible field type, so we can test them all exhaustively.
  106. message DummyMessageContainingEnum {
  107. enum TestEnumType {
  108. TEST_OPTION_ENUM_TYPE1 = 22;
  109. TEST_OPTION_ENUM_TYPE2 = -23;
  110. }
  111. }
  112. message DummyMessageInvalidAsOptionType {
  113. }
  114. extend google.protobuf.MessageOptions {
  115. optional bool bool_opt = 7706090;
  116. optional int32 int32_opt = 7705709;
  117. optional int64 int64_opt = 7705542;
  118. optional uint32 uint32_opt = 7704880;
  119. optional uint64 uint64_opt = 7702367;
  120. optional sint32 sint32_opt = 7701568;
  121. optional sint64 sint64_opt = 7700863;
  122. optional fixed32 fixed32_opt = 7700307;
  123. optional fixed64 fixed64_opt = 7700194;
  124. optional sfixed32 sfixed32_opt = 7698645;
  125. optional sfixed64 sfixed64_opt = 7685475;
  126. optional float float_opt = 7675390;
  127. optional double double_opt = 7673293;
  128. optional string string_opt = 7673285;
  129. optional bytes bytes_opt = 7673238;
  130. optional DummyMessageContainingEnum.TestEnumType enum_opt = 7673233;
  131. optional DummyMessageInvalidAsOptionType message_type_opt = 7665967;
  132. }
  133. message CustomOptionMinIntegerValues {
  134. option (bool_opt) = false;
  135. option (int32_opt) = -0x80000000;
  136. option (int64_opt) = -0x8000000000000000;
  137. option (uint32_opt) = 0;
  138. option (uint64_opt) = 0;
  139. option (sint32_opt) = -0x80000000;
  140. option (sint64_opt) = -0x8000000000000000;
  141. option (fixed32_opt) = 0;
  142. option (fixed64_opt) = 0;
  143. option (sfixed32_opt) = -0x80000000;
  144. option (sfixed64_opt) = -0x8000000000000000;
  145. }
  146. message CustomOptionMaxIntegerValues {
  147. option (bool_opt) = true;
  148. option (int32_opt) = 0x7FFFFFFF;
  149. option (int64_opt) = 0x7FFFFFFFFFFFFFFF;
  150. option (uint32_opt) = 0xFFFFFFFF;
  151. option (uint64_opt) = 0xFFFFFFFFFFFFFFFF;
  152. option (sint32_opt) = 0x7FFFFFFF;
  153. option (sint64_opt) = 0x7FFFFFFFFFFFFFFF;
  154. option (fixed32_opt) = 0xFFFFFFFF;
  155. option (fixed64_opt) = 0xFFFFFFFFFFFFFFFF;
  156. option (sfixed32_opt) = 0x7FFFFFFF;
  157. option (sfixed64_opt) = 0x7FFFFFFFFFFFFFFF;
  158. }
  159. message CustomOptionOtherValues {
  160. option (int32_opt) = -100; // To test sign-extension.
  161. option (float_opt) = 12.3456789;
  162. option (double_opt) = 1.234567890123456789;
  163. option (string_opt) = "Hello, \"World\"";
  164. option (bytes_opt) = "Hello\0World";
  165. option (enum_opt) = TEST_OPTION_ENUM_TYPE2;
  166. }
  167. message SettingRealsFromPositiveInts {
  168. option (float_opt) = 12;
  169. option (double_opt) = 154;
  170. }
  171. message SettingRealsFromNegativeInts {
  172. option (float_opt) = -12;
  173. option (double_opt) = -154;
  174. }
  175. // Options of complex message types, themselves combined and extended in
  176. // various ways.
  177. message ComplexOptionType1 {
  178. optional int32 foo = 1;
  179. optional int32 foo2 = 2;
  180. optional int32 foo3 = 3;
  181. extensions 100 to max;
  182. }
  183. message ComplexOptionType2 {
  184. optional ComplexOptionType1 bar = 1;
  185. optional int32 baz = 2;
  186. message ComplexOptionType4 {
  187. optional int32 waldo = 1;
  188. extend google.protobuf.MessageOptions {
  189. optional ComplexOptionType4 complex_opt4 = 7633546;
  190. }
  191. }
  192. optional ComplexOptionType4 fred = 3;
  193. extensions 100 to max;
  194. }
  195. message ComplexOptionType3 {
  196. optional int32 qux = 1;
  197. optional group ComplexOptionType5 = 2 {
  198. optional int32 plugh = 3;
  199. }
  200. }
  201. extend ComplexOptionType1 {
  202. optional int32 quux = 7663707;
  203. optional ComplexOptionType3 corge = 7663442;
  204. }
  205. extend ComplexOptionType2 {
  206. optional int32 grault = 7650927;
  207. optional ComplexOptionType1 garply = 7649992;
  208. }
  209. extend google.protobuf.MessageOptions {
  210. optional protobuf_unittest.ComplexOptionType1 complex_opt1 = 7646756;
  211. optional ComplexOptionType2 complex_opt2 = 7636949;
  212. optional ComplexOptionType3 complex_opt3 = 7636463;
  213. optional group ComplexOpt6 = 7595468 {
  214. optional int32 xyzzy = 7593951;
  215. }
  216. }
  217. // Note that we try various different ways of naming the same extension.
  218. message VariousComplexOptions {
  219. option (.protobuf_unittest.complex_opt1).foo = 42;
  220. option (protobuf_unittest.complex_opt1).(.protobuf_unittest.quux) = 324;
  221. option (.protobuf_unittest.complex_opt1).(protobuf_unittest.corge).qux = 876;
  222. option (complex_opt2).baz = 987;
  223. option (complex_opt2).(grault) = 654;
  224. option (complex_opt2).bar.foo = 743;
  225. option (complex_opt2).bar.(quux) = 1999;
  226. option (complex_opt2).bar.(protobuf_unittest.corge).qux = 2008;
  227. option (complex_opt2).(garply).foo = 741;
  228. option (complex_opt2).(garply).(.protobuf_unittest.quux) = 1998;
  229. option (complex_opt2).(protobuf_unittest.garply).(corge).qux = 2121;
  230. option (ComplexOptionType2.ComplexOptionType4.complex_opt4).waldo = 1971;
  231. option (complex_opt2).fred.waldo = 321;
  232. option (protobuf_unittest.complex_opt3).qux = 9;
  233. option (complex_opt3).complexoptiontype5.plugh = 22;
  234. option (complexopt6).xyzzy = 24;
  235. }
  236. // ------------------------------------------------------
  237. // Definitions for testing aggregate option parsing.
  238. // See descriptor_unittest.cc.
  239. message AggregateMessageSet {
  240. option message_set_wire_format = true;
  241. extensions 4 to max;
  242. }
  243. message AggregateMessageSetElement {
  244. extend AggregateMessageSet {
  245. optional AggregateMessageSetElement message_set_extension = 15447542;
  246. }
  247. optional string s = 1;
  248. }
  249. // A helper type used to test aggregate option parsing
  250. message Aggregate {
  251. optional int32 i = 1;
  252. optional string s = 2;
  253. // A nested object
  254. optional Aggregate sub = 3;
  255. // To test the parsing of extensions inside aggregate values
  256. optional google.protobuf.FileOptions file = 4;
  257. extend google.protobuf.FileOptions {
  258. optional Aggregate nested = 15476903;
  259. }
  260. // An embedded message set
  261. optional AggregateMessageSet mset = 5;
  262. }
  263. // Allow Aggregate to be used as an option at all possible locations
  264. // in the .proto grammer.
  265. extend google.protobuf.FileOptions { optional Aggregate fileopt = 15478479; }
  266. extend google.protobuf.MessageOptions { optional Aggregate msgopt = 15480088; }
  267. extend google.protobuf.FieldOptions { optional Aggregate fieldopt = 15481374; }
  268. extend google.protobuf.EnumOptions { optional Aggregate enumopt_renamed = 15483218; }
  269. extend google.protobuf.EnumValueOptions { optional Aggregate enumvalopt = 15486921; }
  270. extend google.protobuf.ServiceOptions { optional Aggregate serviceopt = 15497145; }
  271. extend google.protobuf.MethodOptions { optional Aggregate methodopt = 15512713; }
  272. // Try using AggregateOption at different points in the proto grammar
  273. option (fileopt) = {
  274. s: 'FileAnnotation'
  275. // Also test the handling of comments
  276. /* of both types */ i: 100
  277. sub { s: 'NestedFileAnnotation' }
  278. // Include a google.protobuf.FileOptions and recursively extend it with
  279. // another fileopt.
  280. file {
  281. [protobuf_unittest.fileopt] {
  282. s:'FileExtensionAnnotation'
  283. }
  284. }
  285. // A message set inside an option value
  286. mset {
  287. [protobuf_unittest.AggregateMessageSetElement.message_set_extension] {
  288. s: 'EmbeddedMessageSetElement'
  289. }
  290. }
  291. };
  292. message AggregateMessage {
  293. option (msgopt) = { i:101 s:'MessageAnnotation' };
  294. optional int32 fieldname = 1 [(fieldopt) = { s:'FieldAnnotation' }];
  295. }
  296. service AggregateService {
  297. option (serviceopt) = { s:'ServiceAnnotation' };
  298. rpc Method (AggregateMessage) returns (AggregateMessage) {
  299. option (methodopt) = { s:'MethodAnnotation' };
  300. }
  301. }
  302. enum AggregateEnum {
  303. option (enumopt_renamed) = { s:'EnumAnnotation' };
  304. VALUE = 1 [(enumvalopt) = { s:'EnumValueAnnotation' }];
  305. }