test.proto 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. // Go support for Protocol Buffers - Google's data interchange format
  2. //
  3. // Copyright 2010 The Go Authors. All rights reserved.
  4. // https://github.com/golang/protobuf
  5. //
  6. // Redistribution and use in source and binary forms, with or without
  7. // modification, are permitted provided that the following conditions are
  8. // met:
  9. //
  10. // * Redistributions of source code must retain the above copyright
  11. // notice, this list of conditions and the following disclaimer.
  12. // * Redistributions in binary form must reproduce the above
  13. // copyright notice, this list of conditions and the following disclaimer
  14. // in the documentation and/or other materials provided with the
  15. // distribution.
  16. // * Neither the name of Google Inc. nor the names of its
  17. // contributors may be used to endorse or promote products derived from
  18. // this software without specific prior written permission.
  19. //
  20. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. // A feature-rich test file for the protocol compiler and libraries.
  32. syntax = "proto2";
  33. package testdata;
  34. enum FOO { FOO1 = 1; };
  35. message GoEnum {
  36. required FOO foo = 1;
  37. }
  38. message GoTestField {
  39. required string Label = 1;
  40. required string Type = 2;
  41. }
  42. message GoTest {
  43. // An enum, for completeness.
  44. enum KIND {
  45. VOID = 0;
  46. // Basic types
  47. BOOL = 1;
  48. BYTES = 2;
  49. FINGERPRINT = 3;
  50. FLOAT = 4;
  51. INT = 5;
  52. STRING = 6;
  53. TIME = 7;
  54. // Groupings
  55. TUPLE = 8;
  56. ARRAY = 9;
  57. MAP = 10;
  58. // Table types
  59. TABLE = 11;
  60. // Functions
  61. FUNCTION = 12; // last tag
  62. };
  63. // Some typical parameters
  64. required KIND Kind = 1;
  65. optional string Table = 2;
  66. optional int32 Param = 3;
  67. // Required, repeated and optional foreign fields.
  68. required GoTestField RequiredField = 4;
  69. repeated GoTestField RepeatedField = 5;
  70. optional GoTestField OptionalField = 6;
  71. // Required fields of all basic types
  72. required bool F_Bool_required = 10;
  73. required int32 F_Int32_required = 11;
  74. required int64 F_Int64_required = 12;
  75. required fixed32 F_Fixed32_required = 13;
  76. required fixed64 F_Fixed64_required = 14;
  77. required uint32 F_Uint32_required = 15;
  78. required uint64 F_Uint64_required = 16;
  79. required float F_Float_required = 17;
  80. required double F_Double_required = 18;
  81. required string F_String_required = 19;
  82. required bytes F_Bytes_required = 101;
  83. required sint32 F_Sint32_required = 102;
  84. required sint64 F_Sint64_required = 103;
  85. // Repeated fields of all basic types
  86. repeated bool F_Bool_repeated = 20;
  87. repeated int32 F_Int32_repeated = 21;
  88. repeated int64 F_Int64_repeated = 22;
  89. repeated fixed32 F_Fixed32_repeated = 23;
  90. repeated fixed64 F_Fixed64_repeated = 24;
  91. repeated uint32 F_Uint32_repeated = 25;
  92. repeated uint64 F_Uint64_repeated = 26;
  93. repeated float F_Float_repeated = 27;
  94. repeated double F_Double_repeated = 28;
  95. repeated string F_String_repeated = 29;
  96. repeated bytes F_Bytes_repeated = 201;
  97. repeated sint32 F_Sint32_repeated = 202;
  98. repeated sint64 F_Sint64_repeated = 203;
  99. // Optional fields of all basic types
  100. optional bool F_Bool_optional = 30;
  101. optional int32 F_Int32_optional = 31;
  102. optional int64 F_Int64_optional = 32;
  103. optional fixed32 F_Fixed32_optional = 33;
  104. optional fixed64 F_Fixed64_optional = 34;
  105. optional uint32 F_Uint32_optional = 35;
  106. optional uint64 F_Uint64_optional = 36;
  107. optional float F_Float_optional = 37;
  108. optional double F_Double_optional = 38;
  109. optional string F_String_optional = 39;
  110. optional bytes F_Bytes_optional = 301;
  111. optional sint32 F_Sint32_optional = 302;
  112. optional sint64 F_Sint64_optional = 303;
  113. // Default-valued fields of all basic types
  114. optional bool F_Bool_defaulted = 40 [default=true];
  115. optional int32 F_Int32_defaulted = 41 [default=32];
  116. optional int64 F_Int64_defaulted = 42 [default=64];
  117. optional fixed32 F_Fixed32_defaulted = 43 [default=320];
  118. optional fixed64 F_Fixed64_defaulted = 44 [default=640];
  119. optional uint32 F_Uint32_defaulted = 45 [default=3200];
  120. optional uint64 F_Uint64_defaulted = 46 [default=6400];
  121. optional float F_Float_defaulted = 47 [default=314159.];
  122. optional double F_Double_defaulted = 48 [default=271828.];
  123. optional string F_String_defaulted = 49 [default="hello, \"world!\"\n"];
  124. optional bytes F_Bytes_defaulted = 401 [default="Bignose"];
  125. optional sint32 F_Sint32_defaulted = 402 [default = -32];
  126. optional sint64 F_Sint64_defaulted = 403 [default = -64];
  127. // Packed repeated fields (no string or bytes).
  128. repeated bool F_Bool_repeated_packed = 50 [packed=true];
  129. repeated int32 F_Int32_repeated_packed = 51 [packed=true];
  130. repeated int64 F_Int64_repeated_packed = 52 [packed=true];
  131. repeated fixed32 F_Fixed32_repeated_packed = 53 [packed=true];
  132. repeated fixed64 F_Fixed64_repeated_packed = 54 [packed=true];
  133. repeated uint32 F_Uint32_repeated_packed = 55 [packed=true];
  134. repeated uint64 F_Uint64_repeated_packed = 56 [packed=true];
  135. repeated float F_Float_repeated_packed = 57 [packed=true];
  136. repeated double F_Double_repeated_packed = 58 [packed=true];
  137. repeated sint32 F_Sint32_repeated_packed = 502 [packed=true];
  138. repeated sint64 F_Sint64_repeated_packed = 503 [packed=true];
  139. // Required, repeated, and optional groups.
  140. required group RequiredGroup = 70 {
  141. required string RequiredField = 71;
  142. };
  143. repeated group RepeatedGroup = 80 {
  144. required string RequiredField = 81;
  145. };
  146. optional group OptionalGroup = 90 {
  147. required string RequiredField = 91;
  148. };
  149. }
  150. // For testing a group containing a required field.
  151. message GoTestRequiredGroupField {
  152. required group Group = 1 {
  153. required int32 Field = 2;
  154. };
  155. }
  156. // For testing skipping of unrecognized fields.
  157. // Numbers are all big, larger than tag numbers in GoTestField,
  158. // the message used in the corresponding test.
  159. message GoSkipTest {
  160. required int32 skip_int32 = 11;
  161. required fixed32 skip_fixed32 = 12;
  162. required fixed64 skip_fixed64 = 13;
  163. required string skip_string = 14;
  164. required group SkipGroup = 15 {
  165. required int32 group_int32 = 16;
  166. required string group_string = 17;
  167. }
  168. }
  169. // For testing packed/non-packed decoder switching.
  170. // A serialized instance of one should be deserializable as the other.
  171. message NonPackedTest {
  172. repeated int32 a = 1;
  173. }
  174. message PackedTest {
  175. repeated int32 b = 1 [packed=true];
  176. }
  177. message MaxTag {
  178. // Maximum possible tag number.
  179. optional string last_field = 536870911;
  180. }
  181. message OldMessage {
  182. message Nested {
  183. optional string name = 1;
  184. }
  185. optional Nested nested = 1;
  186. optional int32 num = 2;
  187. }
  188. // NewMessage is wire compatible with OldMessage;
  189. // imagine it as a future version.
  190. message NewMessage {
  191. message Nested {
  192. optional string name = 1;
  193. optional string food_group = 2;
  194. }
  195. optional Nested nested = 1;
  196. // This is an int32 in OldMessage.
  197. optional int64 num = 2;
  198. }
  199. // Smaller tests for ASCII formatting.
  200. message InnerMessage {
  201. required string host = 1;
  202. optional int32 port = 2 [default=4000];
  203. optional bool connected = 3;
  204. }
  205. message OtherMessage {
  206. optional int64 key = 1;
  207. optional bytes value = 2;
  208. optional float weight = 3;
  209. optional InnerMessage inner = 4;
  210. extensions 100 to max;
  211. }
  212. message RequiredInnerMessage {
  213. required InnerMessage leo_finally_won_an_oscar = 1;
  214. }
  215. message MyMessage {
  216. required int32 count = 1;
  217. optional string name = 2;
  218. optional string quote = 3;
  219. repeated string pet = 4;
  220. optional InnerMessage inner = 5;
  221. repeated OtherMessage others = 6;
  222. optional RequiredInnerMessage we_must_go_deeper = 13;
  223. repeated InnerMessage rep_inner = 12;
  224. enum Color {
  225. RED = 0;
  226. GREEN = 1;
  227. BLUE = 2;
  228. };
  229. optional Color bikeshed = 7;
  230. optional group SomeGroup = 8 {
  231. optional int32 group_field = 9;
  232. }
  233. // This field becomes [][]byte in the generated code.
  234. repeated bytes rep_bytes = 10;
  235. optional double bigfloat = 11;
  236. extensions 100 to max;
  237. }
  238. message Ext {
  239. extend MyMessage {
  240. optional Ext more = 103;
  241. optional string text = 104;
  242. optional int32 number = 105;
  243. }
  244. optional string data = 1;
  245. }
  246. extend MyMessage {
  247. repeated string greeting = 106;
  248. }
  249. message ComplexExtension {
  250. optional int32 first = 1;
  251. optional int32 second = 2;
  252. repeated int32 third = 3;
  253. }
  254. extend OtherMessage {
  255. optional ComplexExtension complex = 200;
  256. repeated ComplexExtension r_complex = 201;
  257. }
  258. message DefaultsMessage {
  259. enum DefaultsEnum {
  260. ZERO = 0;
  261. ONE = 1;
  262. TWO = 2;
  263. };
  264. extensions 100 to max;
  265. }
  266. extend DefaultsMessage {
  267. optional double no_default_double = 101;
  268. optional float no_default_float = 102;
  269. optional int32 no_default_int32 = 103;
  270. optional int64 no_default_int64 = 104;
  271. optional uint32 no_default_uint32 = 105;
  272. optional uint64 no_default_uint64 = 106;
  273. optional sint32 no_default_sint32 = 107;
  274. optional sint64 no_default_sint64 = 108;
  275. optional fixed32 no_default_fixed32 = 109;
  276. optional fixed64 no_default_fixed64 = 110;
  277. optional sfixed32 no_default_sfixed32 = 111;
  278. optional sfixed64 no_default_sfixed64 = 112;
  279. optional bool no_default_bool = 113;
  280. optional string no_default_string = 114;
  281. optional bytes no_default_bytes = 115;
  282. optional DefaultsMessage.DefaultsEnum no_default_enum = 116;
  283. optional double default_double = 201 [default = 3.1415];
  284. optional float default_float = 202 [default = 3.14];
  285. optional int32 default_int32 = 203 [default = 42];
  286. optional int64 default_int64 = 204 [default = 43];
  287. optional uint32 default_uint32 = 205 [default = 44];
  288. optional uint64 default_uint64 = 206 [default = 45];
  289. optional sint32 default_sint32 = 207 [default = 46];
  290. optional sint64 default_sint64 = 208 [default = 47];
  291. optional fixed32 default_fixed32 = 209 [default = 48];
  292. optional fixed64 default_fixed64 = 210 [default = 49];
  293. optional sfixed32 default_sfixed32 = 211 [default = 50];
  294. optional sfixed64 default_sfixed64 = 212 [default = 51];
  295. optional bool default_bool = 213 [default = true];
  296. optional string default_string = 214 [default = "Hello, string"];
  297. optional bytes default_bytes = 215 [default = "Hello, bytes"];
  298. optional DefaultsMessage.DefaultsEnum default_enum = 216 [default = ONE];
  299. }
  300. message MyMessageSet {
  301. option message_set_wire_format = true;
  302. extensions 100 to max;
  303. }
  304. message Empty {
  305. }
  306. extend MyMessageSet {
  307. optional Empty x201 = 201;
  308. optional Empty x202 = 202;
  309. optional Empty x203 = 203;
  310. optional Empty x204 = 204;
  311. optional Empty x205 = 205;
  312. optional Empty x206 = 206;
  313. optional Empty x207 = 207;
  314. optional Empty x208 = 208;
  315. optional Empty x209 = 209;
  316. optional Empty x210 = 210;
  317. optional Empty x211 = 211;
  318. optional Empty x212 = 212;
  319. optional Empty x213 = 213;
  320. optional Empty x214 = 214;
  321. optional Empty x215 = 215;
  322. optional Empty x216 = 216;
  323. optional Empty x217 = 217;
  324. optional Empty x218 = 218;
  325. optional Empty x219 = 219;
  326. optional Empty x220 = 220;
  327. optional Empty x221 = 221;
  328. optional Empty x222 = 222;
  329. optional Empty x223 = 223;
  330. optional Empty x224 = 224;
  331. optional Empty x225 = 225;
  332. optional Empty x226 = 226;
  333. optional Empty x227 = 227;
  334. optional Empty x228 = 228;
  335. optional Empty x229 = 229;
  336. optional Empty x230 = 230;
  337. optional Empty x231 = 231;
  338. optional Empty x232 = 232;
  339. optional Empty x233 = 233;
  340. optional Empty x234 = 234;
  341. optional Empty x235 = 235;
  342. optional Empty x236 = 236;
  343. optional Empty x237 = 237;
  344. optional Empty x238 = 238;
  345. optional Empty x239 = 239;
  346. optional Empty x240 = 240;
  347. optional Empty x241 = 241;
  348. optional Empty x242 = 242;
  349. optional Empty x243 = 243;
  350. optional Empty x244 = 244;
  351. optional Empty x245 = 245;
  352. optional Empty x246 = 246;
  353. optional Empty x247 = 247;
  354. optional Empty x248 = 248;
  355. optional Empty x249 = 249;
  356. optional Empty x250 = 250;
  357. }
  358. message MessageList {
  359. repeated group Message = 1 {
  360. required string name = 2;
  361. required int32 count = 3;
  362. }
  363. }
  364. message Strings {
  365. optional string string_field = 1;
  366. optional bytes bytes_field = 2;
  367. }
  368. message Defaults {
  369. enum Color {
  370. RED = 0;
  371. GREEN = 1;
  372. BLUE = 2;
  373. }
  374. // Default-valued fields of all basic types.
  375. // Same as GoTest, but copied here to make testing easier.
  376. optional bool F_Bool = 1 [default=true];
  377. optional int32 F_Int32 = 2 [default=32];
  378. optional int64 F_Int64 = 3 [default=64];
  379. optional fixed32 F_Fixed32 = 4 [default=320];
  380. optional fixed64 F_Fixed64 = 5 [default=640];
  381. optional uint32 F_Uint32 = 6 [default=3200];
  382. optional uint64 F_Uint64 = 7 [default=6400];
  383. optional float F_Float = 8 [default=314159.];
  384. optional double F_Double = 9 [default=271828.];
  385. optional string F_String = 10 [default="hello, \"world!\"\n"];
  386. optional bytes F_Bytes = 11 [default="Bignose"];
  387. optional sint32 F_Sint32 = 12 [default=-32];
  388. optional sint64 F_Sint64 = 13 [default=-64];
  389. optional Color F_Enum = 14 [default=GREEN];
  390. // More fields with crazy defaults.
  391. optional float F_Pinf = 15 [default=inf];
  392. optional float F_Ninf = 16 [default=-inf];
  393. optional float F_Nan = 17 [default=nan];
  394. // Sub-message.
  395. optional SubDefaults sub = 18;
  396. // Redundant but explicit defaults.
  397. optional string str_zero = 19 [default=""];
  398. }
  399. message SubDefaults {
  400. optional int64 n = 1 [default=7];
  401. }
  402. message RepeatedEnum {
  403. enum Color {
  404. RED = 1;
  405. }
  406. repeated Color color = 1;
  407. }
  408. message MoreRepeated {
  409. repeated bool bools = 1;
  410. repeated bool bools_packed = 2 [packed=true];
  411. repeated int32 ints = 3;
  412. repeated int32 ints_packed = 4 [packed=true];
  413. repeated int64 int64s_packed = 7 [packed=true];
  414. repeated string strings = 5;
  415. repeated fixed32 fixeds = 6;
  416. }
  417. // GroupOld and GroupNew have the same wire format.
  418. // GroupNew has a new field inside a group.
  419. message GroupOld {
  420. optional group G = 101 {
  421. optional int32 x = 2;
  422. }
  423. }
  424. message GroupNew {
  425. optional group G = 101 {
  426. optional int32 x = 2;
  427. optional int32 y = 3;
  428. }
  429. }
  430. message FloatingPoint {
  431. required double f = 1;
  432. optional bool exact = 2;
  433. }
  434. message MessageWithMap {
  435. map<int32, string> name_mapping = 1;
  436. map<sint64, FloatingPoint> msg_mapping = 2;
  437. map<bool, bytes> byte_mapping = 3;
  438. map<string, string> str_to_str = 4;
  439. }
  440. message Oneof {
  441. oneof union {
  442. bool F_Bool = 1;
  443. int32 F_Int32 = 2;
  444. int64 F_Int64 = 3;
  445. fixed32 F_Fixed32 = 4;
  446. fixed64 F_Fixed64 = 5;
  447. uint32 F_Uint32 = 6;
  448. uint64 F_Uint64 = 7;
  449. float F_Float = 8;
  450. double F_Double = 9;
  451. string F_String = 10;
  452. bytes F_Bytes = 11;
  453. sint32 F_Sint32 = 12;
  454. sint64 F_Sint64 = 13;
  455. MyMessage.Color F_Enum = 14;
  456. GoTestField F_Message = 15;
  457. group F_Group = 16 {
  458. optional int32 x = 17;
  459. }
  460. int32 F_Largest_Tag = 536870911;
  461. }
  462. oneof tormato {
  463. int32 value = 100;
  464. }
  465. }
  466. message Communique {
  467. optional bool make_me_cry = 1;
  468. // This is a oneof, called "union".
  469. oneof union {
  470. int32 number = 5;
  471. string name = 6;
  472. bytes data = 7;
  473. double temp_c = 8;
  474. MyMessage.Color col = 9;
  475. Strings msg = 10;
  476. }
  477. }