test.proto 16 KB

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