unittest_custom_options_proto3.proto 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. extend google.protobuf.OneofOptions {
  60. int32 oneof_opt1 = 7740111;
  61. }
  62. extend google.protobuf.EnumOptions {
  63. sfixed32 enum_opt1 = 7753576;
  64. }
  65. extend google.protobuf.EnumValueOptions {
  66. int32 enum_value_opt1 = 1560678;
  67. }
  68. extend google.protobuf.ServiceOptions {
  69. sint64 service_opt1 = 7887650;
  70. }
  71. enum MethodOpt1 {
  72. METHODOPT1_UNSPECIFIED = 0;
  73. METHODOPT1_VAL1 = 1;
  74. METHODOPT1_VAL2 = 2;
  75. }
  76. extend google.protobuf.MethodOptions {
  77. MethodOpt1 method_opt1 = 7890860;
  78. }
  79. // A test message with custom options at all possible locations (and also some
  80. // regular options, to make sure they interact nicely).
  81. message TestMessageWithCustomOptions {
  82. option message_set_wire_format = false;
  83. option (message_opt1) = -56;
  84. string field1 = 1 [ctype=CORD,
  85. (field_opt1)=8765432109];
  86. oneof AnOneof {
  87. option (oneof_opt1) = -99;
  88. int32 oneof_field = 2;
  89. }
  90. enum AnEnum {
  91. option (enum_opt1) = -789;
  92. ANENUM_UNSPECIFIED = 0;
  93. ANENUM_VAL1 = 1;
  94. ANENUM_VAL2 = 2 [(enum_value_opt1) = 123];
  95. }
  96. }
  97. // A test RPC service with custom options at all possible locations (and also
  98. // some regular options, to make sure they interact nicely).
  99. message CustomOptionFooRequest {
  100. }
  101. message CustomOptionFooResponse {
  102. }
  103. message CustomOptionFooClientMessage {
  104. }
  105. message CustomOptionFooServerMessage {
  106. }
  107. service TestServiceWithCustomOptions {
  108. option (service_opt1) = -9876543210;
  109. rpc Foo(CustomOptionFooRequest) returns (CustomOptionFooResponse) {
  110. option (method_opt1) = METHODOPT1_VAL2;
  111. }
  112. }
  113. // Options of every possible field type, so we can test them all exhaustively.
  114. message DummyMessageContainingEnum {
  115. enum TestEnumType {
  116. TEST_OPTION_ENUM_UNSPECIFIED = 0;
  117. TEST_OPTION_ENUM_TYPE1 = 22;
  118. TEST_OPTION_ENUM_TYPE2 = -23;
  119. }
  120. }
  121. message DummyMessageInvalidAsOptionType {
  122. }
  123. extend google.protobuf.MessageOptions {
  124. bool bool_opt = 7706090;
  125. int32 int32_opt = 7705709;
  126. int64 int64_opt = 7705542;
  127. uint32 uint32_opt = 7704880;
  128. uint64 uint64_opt = 7702367;
  129. sint32 sint32_opt = 7701568;
  130. sint64 sint64_opt = 7700863;
  131. fixed32 fixed32_opt = 7700307;
  132. fixed64 fixed64_opt = 7700194;
  133. sfixed32 sfixed32_opt = 7698645;
  134. sfixed64 sfixed64_opt = 7685475;
  135. float float_opt = 7675390;
  136. double double_opt = 7673293;
  137. string string_opt = 7673285;
  138. bytes bytes_opt = 7673238;
  139. DummyMessageContainingEnum.TestEnumType enum_opt = 7673233;
  140. DummyMessageInvalidAsOptionType message_type_opt = 7665967;
  141. }
  142. message CustomOptionMinIntegerValues {
  143. option (bool_opt) = false;
  144. option (int32_opt) = -0x80000000;
  145. option (int64_opt) = -0x8000000000000000;
  146. option (uint32_opt) = 0;
  147. option (uint64_opt) = 0;
  148. option (sint32_opt) = -0x80000000;
  149. option (sint64_opt) = -0x8000000000000000;
  150. option (fixed32_opt) = 0;
  151. option (fixed64_opt) = 0;
  152. option (sfixed32_opt) = -0x80000000;
  153. option (sfixed64_opt) = -0x8000000000000000;
  154. }
  155. message CustomOptionMaxIntegerValues {
  156. option (bool_opt) = true;
  157. option (int32_opt) = 0x7FFFFFFF;
  158. option (int64_opt) = 0x7FFFFFFFFFFFFFFF;
  159. option (uint32_opt) = 0xFFFFFFFF;
  160. option (uint64_opt) = 0xFFFFFFFFFFFFFFFF;
  161. option (sint32_opt) = 0x7FFFFFFF;
  162. option (sint64_opt) = 0x7FFFFFFFFFFFFFFF;
  163. option (fixed32_opt) = 0xFFFFFFFF;
  164. option (fixed64_opt) = 0xFFFFFFFFFFFFFFFF;
  165. option (sfixed32_opt) = 0x7FFFFFFF;
  166. option (sfixed64_opt) = 0x7FFFFFFFFFFFFFFF;
  167. }
  168. message CustomOptionOtherValues {
  169. option (int32_opt) = -100; // To test sign-extension.
  170. option (float_opt) = 12.3456789;
  171. option (double_opt) = 1.234567890123456789;
  172. option (string_opt) = "Hello, \"World\"";
  173. option (bytes_opt) = "Hello\0World";
  174. option (enum_opt) = TEST_OPTION_ENUM_TYPE2;
  175. }
  176. message SettingRealsFromPositiveInts {
  177. option (float_opt) = 12;
  178. option (double_opt) = 154;
  179. }
  180. message SettingRealsFromNegativeInts {
  181. option (float_opt) = -12;
  182. option (double_opt) = -154;
  183. }
  184. // Options of complex message types, themselves combined and extended in
  185. // various ways.
  186. message ComplexOptionType1 {
  187. int32 foo = 1;
  188. int32 foo2 = 2;
  189. int32 foo3 = 3;
  190. repeated int32 foo4 = 4;
  191. }
  192. message ComplexOptionType2 {
  193. ComplexOptionType1 bar = 1;
  194. int32 baz = 2;
  195. message ComplexOptionType4 {
  196. int32 waldo = 1;
  197. extend google.protobuf.MessageOptions {
  198. ComplexOptionType4 complex_opt4 = 7633546;
  199. }
  200. }
  201. ComplexOptionType4 fred = 3;
  202. repeated ComplexOptionType4 barney = 4;
  203. }
  204. message ComplexOptionType3 {
  205. int32 qux = 1;
  206. }
  207. extend google.protobuf.MessageOptions {
  208. protobuf_unittest.ComplexOptionType1 complex_opt1 = 7646756;
  209. ComplexOptionType2 complex_opt2 = 7636949;
  210. ComplexOptionType3 complex_opt3 = 7636463;
  211. }
  212. // Note that we try various different ways of naming the same extension.
  213. message VariousComplexOptions {
  214. option (.protobuf_unittest.complex_opt1).foo = 42;
  215. option (protobuf_unittest.complex_opt1).foo4 = 99;
  216. option (protobuf_unittest.complex_opt1).foo4 = 88;
  217. option (complex_opt2).baz = 987;
  218. option (complex_opt2).bar.foo = 743;
  219. option (ComplexOptionType2.ComplexOptionType4.complex_opt4).waldo = 1971;
  220. option (complex_opt2).fred.waldo = 321;
  221. option (complex_opt2).barney = { waldo: 101 };
  222. option (complex_opt2).barney = { waldo: 212 };
  223. option (protobuf_unittest.complex_opt3).qux = 9;
  224. }
  225. // ------------------------------------------------------
  226. // Definitions for testing aggregate option parsing.
  227. // See descriptor_unittest.cc.
  228. // A helper type used to test aggregate option parsing
  229. message Aggregate {
  230. int32 i = 1;
  231. string s = 2;
  232. // A nested object
  233. Aggregate sub = 3;
  234. }
  235. // Allow Aggregate to be used as an option at all possible locations
  236. // in the .proto grammar.
  237. extend google.protobuf.FileOptions { Aggregate fileopt = 15478479; }
  238. extend google.protobuf.MessageOptions { Aggregate msgopt = 15480088; }
  239. extend google.protobuf.FieldOptions { Aggregate fieldopt = 15481374; }
  240. extend google.protobuf.EnumOptions { Aggregate enumopt = 15483218; }
  241. extend google.protobuf.EnumValueOptions { Aggregate enumvalopt = 15486921; }
  242. extend google.protobuf.ServiceOptions { Aggregate serviceopt = 15497145; }
  243. extend google.protobuf.MethodOptions { Aggregate methodopt = 15512713; }
  244. // Try using AggregateOption at different points in the proto grammar
  245. option (fileopt) = {
  246. s: 'FileAnnotation'
  247. // Also test the handling of comments
  248. /* of both types */ i: 100
  249. sub { s: 'NestedFileAnnotation' }
  250. };
  251. message AggregateMessage {
  252. option (msgopt) = { i:101 s:'MessageAnnotation' };
  253. int32 fieldname = 1 [(fieldopt) = { s:'FieldAnnotation' }];
  254. }
  255. service AggregateService {
  256. option (serviceopt) = { s:'ServiceAnnotation' };
  257. rpc Method (AggregateMessage) returns (AggregateMessage) {
  258. option (methodopt) = { s:'MethodAnnotation' };
  259. }
  260. }
  261. enum AggregateEnum {
  262. option (enumopt) = { s:'EnumAnnotation' };
  263. UNSPECIFIED = 0;
  264. VALUE = 1 [(enumvalopt) = { s:'EnumValueAnnotation' }];
  265. }
  266. // Test custom options for nested type.
  267. message NestedOptionType {
  268. message NestedMessage {
  269. option (message_opt1) = 1001;
  270. int32 nested_field = 1 [(field_opt1) = 1002];
  271. }
  272. enum NestedEnum {
  273. UNSPECIFIED = 0;
  274. option (enum_opt1) = 1003;
  275. NESTED_ENUM_VALUE = 1 [(enum_value_opt1) = 1004];
  276. }
  277. }