/testdata/test_corpus/protobuf_unittest/unittest_custom_options.proto

https://github.com/Morgul/idea-plugin-protobuf · Protocol Buffers · 238 lines · 177 code · 47 blank · 14 comment · 0 complexity · 8e9c889c5a0a4db1723cddfec104be2d MD5 · raw file

  1. // A custom file option (defined below).
  2. option (file_opt1) = 9876543210;
  3. import "src/google/protobuf/descriptor.proto";
  4. // We don't put this in a package within proto2 because we need to make sure
  5. // that the generated code doesn't depend on being in the proto2 namespace.
  6. package protobuf_unittest;
  7. // Some simple test custom options of various types.
  8. extend google.protobuf.FileOptions {
  9. optional uint64 file_opt1 = 7736974;
  10. }
  11. extend google.protobuf.MessageOptions {
  12. optional int32 message_opt1 = 7739036;
  13. }
  14. extend google.protobuf.FieldOptions {
  15. optional fixed64 field_opt1 = 7740936;
  16. // This is useful for testing that we correctly register default values for
  17. // extension options.
  18. optional int32 field_opt2 = 7753913 [default=42];
  19. }
  20. extend google.protobuf.EnumOptions {
  21. optional sfixed32 enum_opt1 = 7753576;
  22. }
  23. extend google.protobuf.EnumValueOptions {
  24. optional int32 enum_value_opt1 = 1560678;
  25. }
  26. extend google.protobuf.ServiceOptions {
  27. optional sint64 service_opt1 = 7887650;
  28. }
  29. enum MethodOpt1 {
  30. METHODOPT1_VAL1 = 1;
  31. METHODOPT1_VAL2 = 2;
  32. }
  33. extend google.protobuf.MethodOptions {
  34. optional MethodOpt1 method_opt1 = 7890860;
  35. }
  36. // A test message with custom options at all possible locations (and also some
  37. // regular options, to make sure they interact nicely).
  38. message TestMessageWithCustomOptions {
  39. option message_set_wire_format = false;
  40. option (message_opt1) = -56;
  41. optional string field1 = 1 [ctype=CORD,
  42. (field_opt1)=8765432109];
  43. enum AnEnum {
  44. option (enum_opt1) = -789;
  45. ANENUM_VAL1 = 1;
  46. ANENUM_VAL2 = 2 [(enum_value_opt1) = 123];
  47. }
  48. }
  49. // A test RPC service with custom options at all possible locations (and also
  50. // some regular options, to make sure they interact nicely).
  51. message CustomOptionFooRequest {
  52. }
  53. message CustomOptionFooResponse {
  54. }
  55. service TestServiceWithCustomOptions {
  56. option (service_opt1) = -9876543210;
  57. rpc Foo(CustomOptionFooRequest) returns (CustomOptionFooResponse) {
  58. option (method_opt1) = METHODOPT1_VAL2;
  59. }
  60. }
  61. // Options of every possible field type, so we can test them all exhaustively.
  62. message DummyMessageContainingEnum {
  63. enum TestEnumType {
  64. TEST_OPTION_ENUM_TYPE1 = 22;
  65. TEST_OPTION_ENUM_TYPE2 = -23;
  66. }
  67. }
  68. message DummyMessageInvalidAsOptionType {
  69. }
  70. extend google.protobuf.MessageOptions {
  71. optional bool bool_opt = 7706090;
  72. optional int32 int32_opt = 7705709;
  73. optional int64 int64_opt = 7705542;
  74. optional uint32 uint32_opt = 7704880;
  75. optional uint64 uint64_opt = 7702367;
  76. optional sint32 sint32_opt = 7701568;
  77. optional sint64 sint64_opt = 7700863;
  78. optional fixed32 fixed32_opt = 7700307;
  79. optional fixed64 fixed64_opt = 7700194;
  80. optional sfixed32 sfixed32_opt = 7698645;
  81. optional sfixed64 sfixed64_opt = 7685475;
  82. optional float float_opt = 7675390;
  83. optional double double_opt = 7673293;
  84. optional string string_opt = 7673285;
  85. optional bytes bytes_opt = 7673238;
  86. optional DummyMessageContainingEnum.TestEnumType enum_opt = 7673233;
  87. optional DummyMessageInvalidAsOptionType message_type_opt = 7665967;
  88. }
  89. message CustomOptionMinIntegerValues {
  90. option (bool_opt) = false;
  91. option (int32_opt) = -0x80000000;
  92. option (int64_opt) = -0x8000000000000000;
  93. option (uint32_opt) = 0;
  94. option (uint64_opt) = 0;
  95. option (sint32_opt) = -0x80000000;
  96. option (sint64_opt) = -0x8000000000000000;
  97. option (fixed32_opt) = 0;
  98. option (fixed64_opt) = 0;
  99. option (sfixed32_opt) = -0x80000000;
  100. option (sfixed64_opt) = -0x8000000000000000;
  101. }
  102. message CustomOptionMaxIntegerValues {
  103. option (bool_opt) = true;
  104. option (int32_opt) = 0x7FFFFFFF;
  105. option (int64_opt) = 0x7FFFFFFFFFFFFFFF;
  106. option (uint32_opt) = 0xFFFFFFFF;
  107. option (uint64_opt) = 0xFFFFFFFFFFFFFFFF;
  108. option (sint32_opt) = 0x7FFFFFFF;
  109. option (sint64_opt) = 0x7FFFFFFFFFFFFFFF;
  110. option (fixed32_opt) = 0xFFFFFFFF;
  111. option (fixed64_opt) = 0xFFFFFFFFFFFFFFFF;
  112. option (sfixed32_opt) = 0x7FFFFFFF;
  113. option (sfixed64_opt) = 0x7FFFFFFFFFFFFFFF;
  114. }
  115. message CustomOptionOtherValues {
  116. option (int32_opt) = -100; // To test sign-extension.
  117. option (float_opt) = 12.3456789;
  118. option (double_opt) = 1.234567890123456789;
  119. option (string_opt) = "Hello, \"World\"";
  120. option (bytes_opt) = "Hello\0World";
  121. option (enum_opt) = TEST_OPTION_ENUM_TYPE2;
  122. }
  123. message SettingRealsFromPositiveInts {
  124. option (float_opt) = 12;
  125. option (double_opt) = 154;
  126. }
  127. message SettingRealsFromNegativeInts {
  128. option (float_opt) = -12;
  129. option (double_opt) = -154;
  130. }
  131. // Options of complex message types, themselves combined and extended in
  132. // various ways.
  133. message ComplexOptionType1 {
  134. optional int32 foo = 1;
  135. optional int32 foo2 = 2;
  136. optional int32 foo3 = 3;
  137. extensions 100 to max;
  138. }
  139. message ComplexOptionType2 {
  140. optional ComplexOptionType1 bar = 1;
  141. optional int32 baz = 2;
  142. message ComplexOptionType4 {
  143. optional int32 waldo = 1;
  144. extend google.protobuf.MessageOptions {
  145. optional ComplexOptionType4 complex_opt4 = 7633546;
  146. }
  147. }
  148. optional ComplexOptionType4 fred = 3;
  149. extensions 100 to max;
  150. }
  151. message ComplexOptionType3 {
  152. optional int32 qux = 1;
  153. optional group ComplexOptionType5 = 2 {
  154. optional int32 plugh = 3;
  155. }
  156. }
  157. extend ComplexOptionType1 {
  158. optional int32 quux = 7663707;
  159. optional ComplexOptionType3 corge = 7663442;
  160. }
  161. extend ComplexOptionType2 {
  162. optional int32 grault = 7650927;
  163. optional ComplexOptionType1 garply = 7649992;
  164. }
  165. extend google.protobuf.MessageOptions {
  166. optional protobuf_unittest.ComplexOptionType1 complex_opt1 = 7646756;
  167. optional ComplexOptionType2 complex_opt2 = 7636949;
  168. optional ComplexOptionType3 complex_opt3 = 7636463;
  169. optional group ComplexOpt6 = 7595468 {
  170. optional int32 xyzzy = 7593951;
  171. }
  172. }
  173. // Note that we try various different ways of naming the same extension.
  174. message VariousComplexOptions {
  175. option (.protobuf_unittest.complex_opt1).foo = 42;
  176. option (protobuf_unittest.complex_opt1).(.protobuf_unittest.quux) = 324;
  177. option (.protobuf_unittest.complex_opt1).(protobuf_unittest.corge).qux = 876;
  178. option (complex_opt2).baz = 987;
  179. option (complex_opt2).(grault) = 654;
  180. option (complex_opt2).bar.foo = 743;
  181. option (complex_opt2).bar.(quux) = 1999;
  182. option (complex_opt2).bar.(protobuf_unittest.corge).qux = 2008;
  183. option (complex_opt2).(garply).foo = 741;
  184. option (complex_opt2).(garply).(.protobuf_unittest.quux) = 1998;
  185. option (complex_opt2).(protobuf_unittest.garply).(corge).qux = 2121;
  186. option (ComplexOptionType2.ComplexOptionType4.complex_opt4).waldo = 1971;
  187. option (complex_opt2).fred.waldo = 321;
  188. option (protobuf_unittest.complex_opt3).qux = 9;
  189. option (complex_opt3).complexoptiontype5.plugh = 22;
  190. option (complexopt6).xyzzy = 24;
  191. }