test.proto 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. // Copyright 2018 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. syntax = "proto2";
  5. package goproto.proto.test;
  6. import "test/test_import.proto";
  7. import public "test/test_public.proto";
  8. import weak "test/weak1/test_weak.proto";
  9. import weak "test/weak2/test_weak.proto";
  10. option go_package = "google.golang.org/protobuf/internal/testprotos/test";
  11. message TestAllTypes {
  12. message NestedMessage {
  13. optional int32 a = 1;
  14. optional TestAllTypes corecursive = 2;
  15. }
  16. enum NestedEnum {
  17. FOO = 0;
  18. BAR = 1;
  19. BAZ = 2;
  20. NEG = -1; // Intentionally negative.
  21. }
  22. optional int32 optional_int32 = 1;
  23. optional int64 optional_int64 = 2;
  24. optional uint32 optional_uint32 = 3;
  25. optional uint64 optional_uint64 = 4;
  26. optional sint32 optional_sint32 = 5;
  27. optional sint64 optional_sint64 = 6;
  28. optional fixed32 optional_fixed32 = 7;
  29. optional fixed64 optional_fixed64 = 8;
  30. optional sfixed32 optional_sfixed32 = 9;
  31. optional sfixed64 optional_sfixed64 = 10;
  32. optional float optional_float = 11;
  33. optional double optional_double = 12;
  34. optional bool optional_bool = 13;
  35. optional string optional_string = 14;
  36. optional bytes optional_bytes = 15;
  37. optional group OptionalGroup = 16 {
  38. optional int32 a = 17;
  39. }
  40. optional NestedMessage optional_nested_message = 18;
  41. optional ForeignMessage optional_foreign_message = 19;
  42. optional ImportMessage optional_import_message = 20;
  43. optional NestedEnum optional_nested_enum = 21;
  44. optional ForeignEnum optional_foreign_enum = 22;
  45. optional ImportEnum optional_import_enum = 23;
  46. repeated int32 repeated_int32 = 31;
  47. repeated int64 repeated_int64 = 32;
  48. repeated uint32 repeated_uint32 = 33;
  49. repeated uint64 repeated_uint64 = 34;
  50. repeated sint32 repeated_sint32 = 35;
  51. repeated sint64 repeated_sint64 = 36;
  52. repeated fixed32 repeated_fixed32 = 37;
  53. repeated fixed64 repeated_fixed64 = 38;
  54. repeated sfixed32 repeated_sfixed32 = 39;
  55. repeated sfixed64 repeated_sfixed64 = 40;
  56. repeated float repeated_float = 41;
  57. repeated double repeated_double = 42;
  58. repeated bool repeated_bool = 43;
  59. repeated string repeated_string = 44;
  60. repeated bytes repeated_bytes = 45;
  61. repeated group RepeatedGroup = 46 {
  62. optional int32 a = 47;
  63. }
  64. repeated NestedMessage repeated_nested_message = 48;
  65. repeated ForeignMessage repeated_foreign_message = 49;
  66. repeated ImportMessage repeated_importmessage = 50;
  67. repeated NestedEnum repeated_nested_enum = 51;
  68. repeated ForeignEnum repeated_foreign_enum = 52;
  69. repeated ImportEnum repeated_importenum = 53;
  70. map < int32, int32> map_int32_int32 = 56;
  71. map < int64, int64> map_int64_int64 = 57;
  72. map < uint32, uint32> map_uint32_uint32 = 58;
  73. map < uint64, uint64> map_uint64_uint64 = 59;
  74. map < sint32, sint32> map_sint32_sint32 = 60;
  75. map < sint64, sint64> map_sint64_sint64 = 61;
  76. map < fixed32, fixed32> map_fixed32_fixed32 = 62;
  77. map < fixed64, fixed64> map_fixed64_fixed64 = 63;
  78. map <sfixed32, sfixed32> map_sfixed32_sfixed32 = 64;
  79. map <sfixed64, sfixed64> map_sfixed64_sfixed64 = 65;
  80. map < int32, float> map_int32_float = 66;
  81. map < int32, double> map_int32_double = 67;
  82. map < bool, bool> map_bool_bool = 68;
  83. map < string, string> map_string_string = 69;
  84. map < string, bytes> map_string_bytes = 70;
  85. map < string, NestedMessage> map_string_nested_message = 71;
  86. map < string, NestedEnum> map_string_nested_enum = 73;
  87. // Singular with defaults
  88. optional int32 default_int32 = 81 [default = 81 ];
  89. optional int64 default_int64 = 82 [default = 82 ];
  90. optional uint32 default_uint32 = 83 [default = 83 ];
  91. optional uint64 default_uint64 = 84 [default = 84 ];
  92. optional sint32 default_sint32 = 85 [default = -85 ];
  93. optional sint64 default_sint64 = 86 [default = 86 ];
  94. optional fixed32 default_fixed32 = 87 [default = 87 ];
  95. optional fixed64 default_fixed64 = 88 [default = 88 ];
  96. optional sfixed32 default_sfixed32 = 89 [default = 89 ];
  97. optional sfixed64 default_sfixed64 = 80 [default = -90 ];
  98. optional float default_float = 91 [default = 91.5 ];
  99. optional double default_double = 92 [default = 92e3 ];
  100. optional bool default_bool = 93 [default = true ];
  101. optional string default_string = 94 [default = "hello"];
  102. optional bytes default_bytes = 95 [default = "world"];
  103. optional NestedEnum default_nested_enum = 96 [default = BAR ];
  104. optional ForeignEnum default_foreign_enum = 97 [default = FOREIGN_BAR];
  105. oneof oneof_field {
  106. uint32 oneof_uint32 = 111;
  107. NestedMessage oneof_nested_message = 112;
  108. string oneof_string = 113;
  109. bytes oneof_bytes = 114;
  110. bool oneof_bool = 115;
  111. uint64 oneof_uint64 = 116;
  112. float oneof_float = 117;
  113. double oneof_double = 118;
  114. NestedEnum oneof_enum = 119;
  115. }
  116. // A oneof with exactly one field.
  117. oneof oneof_optional {
  118. uint32 oneof_optional_uint32 = 120;
  119. }
  120. }
  121. message TestDeprecatedMessage {
  122. option deprecated = true;
  123. optional int32 deprecated_int32 = 1 [deprecated=true];
  124. enum DeprecatedEnum {
  125. option deprecated = true;
  126. DEPRECATED = 0 [deprecated=true];
  127. }
  128. oneof deprecated_oneof {
  129. int32 deprecated_oneof_field = 2 [deprecated = true];
  130. }
  131. }
  132. message ForeignMessage {
  133. optional int32 c = 1;
  134. optional int32 d = 2;
  135. }
  136. enum ForeignEnum {
  137. FOREIGN_FOO = 4;
  138. FOREIGN_BAR = 5;
  139. FOREIGN_BAZ = 6;
  140. }
  141. message TestReservedFields {
  142. reserved 2, 15, 9 to 11;
  143. reserved "bar", "baz";
  144. }
  145. enum TestReservedEnumFields {
  146. RESERVED_ENUM = 0;
  147. reserved 2, 15, 9 to 11;
  148. reserved "BAR", "BAZ";
  149. }
  150. message TestAllExtensions {
  151. extensions 1 to max;
  152. }
  153. extend TestAllExtensions {
  154. optional int32 optional_int32_extension = 1;
  155. optional int64 optional_int64_extension = 2;
  156. optional uint32 optional_uint32_extension = 3;
  157. optional uint64 optional_uint64_extension = 4;
  158. optional sint32 optional_sint32_extension = 5;
  159. optional sint64 optional_sint64_extension = 6;
  160. optional fixed32 optional_fixed32_extension = 7;
  161. optional fixed64 optional_fixed64_extension = 8;
  162. optional sfixed32 optional_sfixed32_extension = 9;
  163. optional sfixed64 optional_sfixed64_extension = 10;
  164. optional float optional_float_extension = 11;
  165. optional double optional_double_extension = 12;
  166. optional bool optional_bool_extension = 13;
  167. optional string optional_string_extension = 14;
  168. optional bytes optional_bytes_extension = 15;
  169. optional group OptionalGroup_extension = 16 {
  170. optional int32 a = 17;
  171. }
  172. optional TestAllTypes.NestedMessage optional_nested_message_extension = 18;
  173. optional TestAllTypes.NestedEnum optional_nested_enum_extension = 21;
  174. repeated int32 repeated_int32_extension = 31;
  175. repeated int64 repeated_int64_extension = 32;
  176. repeated uint32 repeated_uint32_extension = 33;
  177. repeated uint64 repeated_uint64_extension = 34;
  178. repeated sint32 repeated_sint32_extension = 35;
  179. repeated sint64 repeated_sint64_extension = 36;
  180. repeated fixed32 repeated_fixed32_extension = 37;
  181. repeated fixed64 repeated_fixed64_extension = 38;
  182. repeated sfixed32 repeated_sfixed32_extension = 39;
  183. repeated sfixed64 repeated_sfixed64_extension = 40;
  184. repeated float repeated_float_extension = 41;
  185. repeated double repeated_double_extension = 42;
  186. repeated bool repeated_bool_extension = 43;
  187. repeated string repeated_string_extension = 44;
  188. repeated bytes repeated_bytes_extension = 45;
  189. repeated group RepeatedGroup_extension = 46 {
  190. optional int32 a = 47;
  191. }
  192. repeated TestAllTypes.NestedMessage repeated_nested_message_extension = 48;
  193. repeated TestAllTypes.NestedEnum repeated_nested_enum_extension = 51;
  194. optional int32 default_int32_extension = 81 [default = 81 ];
  195. optional int64 default_int64_extension = 82 [default = 82 ];
  196. optional uint32 default_uint32_extension = 83 [default = 83 ];
  197. optional uint64 default_uint64_extension = 84 [default = 84 ];
  198. optional sint32 default_sint32_extension = 85 [default = -85 ];
  199. optional sint64 default_sint64_extension = 86 [default = 86 ];
  200. optional fixed32 default_fixed32_extension = 87 [default = 87 ];
  201. optional fixed64 default_fixed64_extension = 88 [default = 88 ];
  202. optional sfixed32 default_sfixed32_extension = 89 [default = 89 ];
  203. optional sfixed64 default_sfixed64_extension = 80 [default = -90 ];
  204. optional float default_float_extension = 91 [default = 91.5 ];
  205. optional double default_double_extension = 92 [default = 92e3 ];
  206. optional bool default_bool_extension = 93 [default = true ];
  207. optional string default_string_extension = 94 [default = "hello"];
  208. optional bytes default_bytes_extension = 95 [default = "world"];
  209. }
  210. message TestNestedExtension {
  211. extend TestAllExtensions {
  212. optional string nested_string_extension = 1003;
  213. }
  214. }
  215. message TestRequired {
  216. required int32 required_field = 1;
  217. extend TestAllExtensions {
  218. optional TestRequired single = 1000;
  219. repeated TestRequired multi = 1001;
  220. }
  221. }
  222. message TestRequiredForeign {
  223. optional TestRequired optional_message = 1;
  224. repeated TestRequired repeated_message = 2;
  225. map<int32, TestRequired> map_message = 3;
  226. oneof oneof_field {
  227. TestRequired oneof_message = 4;
  228. }
  229. }
  230. message TestRequiredGroupFields {
  231. optional group OptionalGroup = 1 {
  232. required int32 a = 2;
  233. }
  234. repeated group RepeatedGroup = 3 {
  235. required int32 a = 4;
  236. }
  237. }
  238. message TestWeak {
  239. optional goproto.proto.test.weak.WeakImportMessage1 weak_message1 = 1 [weak=true];
  240. optional goproto.proto.test.weak.WeakImportMessage2 weak_message2 = 2 [weak=true];
  241. }
  242. message TestPackedTypes {
  243. repeated int32 packed_int32 = 90 [packed = true];
  244. repeated int64 packed_int64 = 91 [packed = true];
  245. repeated uint32 packed_uint32 = 92 [packed = true];
  246. repeated uint64 packed_uint64 = 93 [packed = true];
  247. repeated sint32 packed_sint32 = 94 [packed = true];
  248. repeated sint64 packed_sint64 = 95 [packed = true];
  249. repeated fixed32 packed_fixed32 = 96 [packed = true];
  250. repeated fixed64 packed_fixed64 = 97 [packed = true];
  251. repeated sfixed32 packed_sfixed32 = 98 [packed = true];
  252. repeated sfixed64 packed_sfixed64 = 99 [packed = true];
  253. repeated float packed_float = 100 [packed = true];
  254. repeated double packed_double = 101 [packed = true];
  255. repeated bool packed_bool = 102 [packed = true];
  256. repeated ForeignEnum packed_enum = 103 [packed = true];
  257. }
  258. message TestUnpackedTypes {
  259. repeated int32 unpacked_int32 = 90 [packed = false];
  260. repeated int64 unpacked_int64 = 91 [packed = false];
  261. repeated uint32 unpacked_uint32 = 92 [packed = false];
  262. repeated uint64 unpacked_uint64 = 93 [packed = false];
  263. repeated sint32 unpacked_sint32 = 94 [packed = false];
  264. repeated sint64 unpacked_sint64 = 95 [packed = false];
  265. repeated fixed32 unpacked_fixed32 = 96 [packed = false];
  266. repeated fixed64 unpacked_fixed64 = 97 [packed = false];
  267. repeated sfixed32 unpacked_sfixed32 = 98 [packed = false];
  268. repeated sfixed64 unpacked_sfixed64 = 99 [packed = false];
  269. repeated float unpacked_float = 100 [packed = false];
  270. repeated double unpacked_double = 101 [packed = false];
  271. repeated bool unpacked_bool = 102 [packed = false];
  272. repeated ForeignEnum unpacked_enum = 103 [packed = false];
  273. }
  274. message TestPackedExtensions {
  275. extensions 1 to max;
  276. }
  277. extend TestPackedExtensions {
  278. repeated int32 packed_int32_extension = 90 [packed = true];
  279. repeated int64 packed_int64_extension = 91 [packed = true];
  280. repeated uint32 packed_uint32_extension = 92 [packed = true];
  281. repeated uint64 packed_uint64_extension = 93 [packed = true];
  282. repeated sint32 packed_sint32_extension = 94 [packed = true];
  283. repeated sint64 packed_sint64_extension = 95 [packed = true];
  284. repeated fixed32 packed_fixed32_extension = 96 [packed = true];
  285. repeated fixed64 packed_fixed64_extension = 97 [packed = true];
  286. repeated sfixed32 packed_sfixed32_extension = 98 [packed = true];
  287. repeated sfixed64 packed_sfixed64_extension = 99 [packed = true];
  288. repeated float packed_float_extension = 100 [packed = true];
  289. repeated double packed_double_extension = 101 [packed = true];
  290. repeated bool packed_bool_extension = 102 [packed = true];
  291. repeated ForeignEnum packed_enum_extension = 103 [packed = true];
  292. }
  293. message TestUnpackedExtensions {
  294. extensions 1 to max;
  295. }
  296. extend TestUnpackedExtensions {
  297. repeated int32 unpacked_int32_extension = 90 [packed = false];
  298. repeated int64 unpacked_int64_extension = 91 [packed = false];
  299. repeated uint32 unpacked_uint32_extension = 92 [packed = false];
  300. repeated uint64 unpacked_uint64_extension = 93 [packed = false];
  301. repeated sint32 unpacked_sint32_extension = 94 [packed = false];
  302. repeated sint64 unpacked_sint64_extension = 95 [packed = false];
  303. repeated fixed32 unpacked_fixed32_extension = 96 [packed = false];
  304. repeated fixed64 unpacked_fixed64_extension = 97 [packed = false];
  305. repeated sfixed32 unpacked_sfixed32_extension = 98 [packed = false];
  306. repeated sfixed64 unpacked_sfixed64_extension = 99 [packed = false];
  307. repeated float unpacked_float_extension = 100 [packed = false];
  308. repeated double unpacked_double_extension = 101 [packed = false];
  309. repeated bool unpacked_bool_extension = 102 [packed = false];
  310. repeated ForeignEnum unpacked_enum_extension = 103 [packed = false];
  311. }
  312. // Test that RPC services work.
  313. message FooRequest {}
  314. message FooResponse {}
  315. service TestService {
  316. rpc Foo(FooRequest) returns (FooResponse);
  317. rpc TestStream(stream FooRequest) returns (stream FooResponse);
  318. }
  319. service TestDeprecatedService {
  320. option deprecated = true;
  321. rpc Deprecated(TestDeprecatedMessage) returns (TestDeprecatedMessage) {
  322. option deprecated = true;
  323. }
  324. }
  325. message WeirdDefault {
  326. optional bytes weird_default = 1 [default = "hello, \"world!\"\ndead\xde\xad\xbe\xefbeef`"];
  327. }