unittest_custom_options_proto3.proto 10 KB

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