unittest.proto 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614
  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: kenton@google.com (Kenton Varda)
  31. // Based on original Protocol Buffers design by
  32. // Sanjay Ghemawat, Jeff Dean, and others.
  33. //
  34. // A proto file we will use for unit testing.
  35. //
  36. // LINT: ALLOW_GROUPS, LEGACY_NAMES
  37. syntax = "proto2";
  38. // Some generic_services option(s) added automatically.
  39. // See: http://go/proto2-generic-services-default
  40. option cc_generic_services = true; // auto-added
  41. option java_generic_services = true; // auto-added
  42. option py_generic_services = true; // auto-added
  43. option cc_enable_arenas = true;
  44. import "google/protobuf/unittest_import.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. // In test_util.h we do "using namespace unittest = protobuf_unittest".
  48. package protobuf_unittest;
  49. // Protos optimized for SPEED use a strict superset of the generated code
  50. // of equivalent ones optimized for CODE_SIZE, so we should optimize all our
  51. // tests for speed unless explicitly testing code size optimization.
  52. option optimize_for = SPEED;
  53. option java_outer_classname = "UnittestProto";
  54. // This proto includes every type of field in both singular and repeated
  55. // forms.
  56. message TestAllTypes {
  57. message NestedMessage {
  58. // The field name "b" fails to compile in proto1 because it conflicts with
  59. // a local variable named "b" in one of the generated methods. Doh.
  60. // This file needs to compile in proto1 to test backwards-compatibility.
  61. optional int32 bb = 1;
  62. }
  63. enum NestedEnum {
  64. FOO = 1;
  65. BAR = 2;
  66. BAZ = 3;
  67. NEG = -1; // Intentionally negative.
  68. }
  69. // Singular
  70. optional int32 optional_int32 = 1;
  71. optional int64 optional_int64 = 2;
  72. optional uint32 optional_uint32 = 3;
  73. optional uint64 optional_uint64 = 4;
  74. optional sint32 optional_sint32 = 5;
  75. optional sint64 optional_sint64 = 6;
  76. optional fixed32 optional_fixed32 = 7;
  77. optional fixed64 optional_fixed64 = 8;
  78. optional sfixed32 optional_sfixed32 = 9;
  79. optional sfixed64 optional_sfixed64 = 10;
  80. optional float optional_float = 11;
  81. optional double optional_double = 12;
  82. optional bool optional_bool = 13;
  83. optional string optional_string = 14;
  84. optional bytes optional_bytes = 15;
  85. optional group OptionalGroup = 16 {
  86. optional int32 a = 17;
  87. }
  88. optional NestedMessage optional_nested_message = 18;
  89. optional ForeignMessage optional_foreign_message = 19;
  90. optional protobuf_unittest_import.ImportMessage optional_import_message = 20;
  91. optional NestedEnum optional_nested_enum = 21;
  92. optional ForeignEnum optional_foreign_enum = 22;
  93. optional protobuf_unittest_import.ImportEnum optional_import_enum = 23;
  94. optional string optional_string_piece = 24 [ctype=STRING_PIECE];
  95. optional string optional_cord = 25 [ctype=CORD];
  96. // Defined in unittest_import_public.proto
  97. optional protobuf_unittest_import.PublicImportMessage
  98. optional_public_import_message = 26;
  99. optional NestedMessage optional_lazy_message = 27 [lazy=true];
  100. optional NestedMessage optional_unverified_lazy_message = 28 [unverified_lazy=true];
  101. // Repeated
  102. repeated int32 repeated_int32 = 31;
  103. repeated int64 repeated_int64 = 32;
  104. repeated uint32 repeated_uint32 = 33;
  105. repeated uint64 repeated_uint64 = 34;
  106. repeated sint32 repeated_sint32 = 35;
  107. repeated sint64 repeated_sint64 = 36;
  108. repeated fixed32 repeated_fixed32 = 37;
  109. repeated fixed64 repeated_fixed64 = 38;
  110. repeated sfixed32 repeated_sfixed32 = 39;
  111. repeated sfixed64 repeated_sfixed64 = 40;
  112. repeated float repeated_float = 41;
  113. repeated double repeated_double = 42;
  114. repeated bool repeated_bool = 43;
  115. repeated string repeated_string = 44;
  116. repeated bytes repeated_bytes = 45;
  117. repeated group RepeatedGroup = 46 {
  118. optional int32 a = 47;
  119. }
  120. repeated NestedMessage repeated_nested_message = 48;
  121. repeated ForeignMessage repeated_foreign_message = 49;
  122. repeated protobuf_unittest_import.ImportMessage repeated_import_message = 50;
  123. repeated NestedEnum repeated_nested_enum = 51;
  124. repeated ForeignEnum repeated_foreign_enum = 52;
  125. repeated protobuf_unittest_import.ImportEnum repeated_import_enum = 53;
  126. repeated string repeated_string_piece = 54 [ctype=STRING_PIECE];
  127. repeated string repeated_cord = 55 [ctype=CORD];
  128. repeated NestedMessage repeated_lazy_message = 57 [lazy=true];
  129. // Singular with defaults
  130. optional int32 default_int32 = 61 [default = 41 ];
  131. optional int64 default_int64 = 62 [default = 42 ];
  132. optional uint32 default_uint32 = 63 [default = 43 ];
  133. optional uint64 default_uint64 = 64 [default = 44 ];
  134. optional sint32 default_sint32 = 65 [default = -45 ];
  135. optional sint64 default_sint64 = 66 [default = 46 ];
  136. optional fixed32 default_fixed32 = 67 [default = 47 ];
  137. optional fixed64 default_fixed64 = 68 [default = 48 ];
  138. optional sfixed32 default_sfixed32 = 69 [default = 49 ];
  139. optional sfixed64 default_sfixed64 = 70 [default = -50 ];
  140. optional float default_float = 71 [default = 51.5 ];
  141. optional double default_double = 72 [default = 52e3 ];
  142. optional bool default_bool = 73 [default = true ];
  143. optional string default_string = 74 [default = "hello"];
  144. optional bytes default_bytes = 75 [default = "world"];
  145. optional NestedEnum default_nested_enum = 81 [default = BAR ];
  146. optional ForeignEnum default_foreign_enum = 82 [default = FOREIGN_BAR];
  147. optional protobuf_unittest_import.ImportEnum
  148. default_import_enum = 83 [default = IMPORT_BAR];
  149. optional string default_string_piece = 84 [ctype=STRING_PIECE,default="abc"];
  150. optional string default_cord = 85 [ctype=CORD,default="123"];
  151. // For oneof test
  152. oneof oneof_field {
  153. uint32 oneof_uint32 = 111;
  154. NestedMessage oneof_nested_message = 112;
  155. string oneof_string = 113;
  156. bytes oneof_bytes = 114;
  157. }
  158. }
  159. // This proto includes a recursively nested message.
  160. message NestedTestAllTypes {
  161. optional NestedTestAllTypes child = 1;
  162. optional TestAllTypes payload = 2;
  163. repeated NestedTestAllTypes repeated_child = 3;
  164. optional NestedTestAllTypes lazy_child = 4 [lazy=true];
  165. optional TestAllTypes eager_child = 5 [lazy=false];
  166. }
  167. message TestDeprecatedFields {
  168. optional int32 deprecated_int32 = 1 [deprecated=true];
  169. repeated string deprecated_repeated_string = 4 [deprecated=true];
  170. optional TestAllTypes.NestedMessage deprecated_message = 3 [deprecated=true];
  171. oneof oneof_fields {
  172. int32 deprecated_int32_in_oneof = 2 [deprecated=true];
  173. }
  174. optional TestDeprecatedFields nested = 5;
  175. }
  176. message TestDeprecatedMessage {
  177. option deprecated = true;
  178. }
  179. // Define these after TestAllTypes to make sure the compiler can handle
  180. // that.
  181. message ForeignMessage {
  182. optional int32 c = 1;
  183. optional int32 d = 2;
  184. }
  185. enum ForeignEnum {
  186. FOREIGN_FOO = 4;
  187. FOREIGN_BAR = 5;
  188. FOREIGN_BAZ = 6;
  189. }
  190. message TestReservedFields {
  191. reserved 2, 15, 9 to 11;
  192. reserved "bar", "baz";
  193. }
  194. enum TestReservedEnumFields {
  195. UNKNOWN = 0;
  196. reserved 2, 15, 9 to 11;
  197. reserved "bar", "baz";
  198. }
  199. message TestAllExtensions {
  200. extensions 1 to max;
  201. }
  202. extend TestAllExtensions {
  203. // Singular
  204. optional int32 optional_int32_extension = 1;
  205. optional int64 optional_int64_extension = 2;
  206. optional uint32 optional_uint32_extension = 3;
  207. optional uint64 optional_uint64_extension = 4;
  208. optional sint32 optional_sint32_extension = 5;
  209. optional sint64 optional_sint64_extension = 6;
  210. optional fixed32 optional_fixed32_extension = 7;
  211. optional fixed64 optional_fixed64_extension = 8;
  212. optional sfixed32 optional_sfixed32_extension = 9;
  213. optional sfixed64 optional_sfixed64_extension = 10;
  214. optional float optional_float_extension = 11;
  215. optional double optional_double_extension = 12;
  216. optional bool optional_bool_extension = 13;
  217. optional string optional_string_extension = 14;
  218. optional bytes optional_bytes_extension = 15;
  219. optional group OptionalGroup_extension = 16 {
  220. optional int32 a = 17;
  221. }
  222. optional TestAllTypes.NestedMessage optional_nested_message_extension = 18;
  223. optional ForeignMessage optional_foreign_message_extension = 19;
  224. optional protobuf_unittest_import.ImportMessage
  225. optional_import_message_extension = 20;
  226. optional TestAllTypes.NestedEnum optional_nested_enum_extension = 21;
  227. optional ForeignEnum optional_foreign_enum_extension = 22;
  228. optional protobuf_unittest_import.ImportEnum
  229. optional_import_enum_extension = 23;
  230. optional string optional_string_piece_extension = 24 [ctype=STRING_PIECE];
  231. optional string optional_cord_extension = 25 [ctype=CORD];
  232. optional protobuf_unittest_import.PublicImportMessage
  233. optional_public_import_message_extension = 26;
  234. optional TestAllTypes.NestedMessage
  235. optional_lazy_message_extension = 27 [lazy=true];
  236. optional TestAllTypes.NestedMessage
  237. optional_unverified_lazy_message_extension = 28 [unverified_lazy=true];
  238. // Repeated
  239. repeated int32 repeated_int32_extension = 31;
  240. repeated int64 repeated_int64_extension = 32;
  241. repeated uint32 repeated_uint32_extension = 33;
  242. repeated uint64 repeated_uint64_extension = 34;
  243. repeated sint32 repeated_sint32_extension = 35;
  244. repeated sint64 repeated_sint64_extension = 36;
  245. repeated fixed32 repeated_fixed32_extension = 37;
  246. repeated fixed64 repeated_fixed64_extension = 38;
  247. repeated sfixed32 repeated_sfixed32_extension = 39;
  248. repeated sfixed64 repeated_sfixed64_extension = 40;
  249. repeated float repeated_float_extension = 41;
  250. repeated double repeated_double_extension = 42;
  251. repeated bool repeated_bool_extension = 43;
  252. repeated string repeated_string_extension = 44;
  253. repeated bytes repeated_bytes_extension = 45;
  254. repeated group RepeatedGroup_extension = 46 {
  255. optional int32 a = 47;
  256. }
  257. repeated TestAllTypes.NestedMessage repeated_nested_message_extension = 48;
  258. repeated ForeignMessage repeated_foreign_message_extension = 49;
  259. repeated protobuf_unittest_import.ImportMessage
  260. repeated_import_message_extension = 50;
  261. repeated TestAllTypes.NestedEnum repeated_nested_enum_extension = 51;
  262. repeated ForeignEnum repeated_foreign_enum_extension = 52;
  263. repeated protobuf_unittest_import.ImportEnum
  264. repeated_import_enum_extension = 53;
  265. repeated string repeated_string_piece_extension = 54 [ctype=STRING_PIECE];
  266. repeated string repeated_cord_extension = 55 [ctype=CORD];
  267. repeated TestAllTypes.NestedMessage
  268. repeated_lazy_message_extension = 57 [lazy=true];
  269. // Singular with defaults
  270. optional int32 default_int32_extension = 61 [default = 41 ];
  271. optional int64 default_int64_extension = 62 [default = 42 ];
  272. optional uint32 default_uint32_extension = 63 [default = 43 ];
  273. optional uint64 default_uint64_extension = 64 [default = 44 ];
  274. optional sint32 default_sint32_extension = 65 [default = -45 ];
  275. optional sint64 default_sint64_extension = 66 [default = 46 ];
  276. optional fixed32 default_fixed32_extension = 67 [default = 47 ];
  277. optional fixed64 default_fixed64_extension = 68 [default = 48 ];
  278. optional sfixed32 default_sfixed32_extension = 69 [default = 49 ];
  279. optional sfixed64 default_sfixed64_extension = 70 [default = -50 ];
  280. optional float default_float_extension = 71 [default = 51.5 ];
  281. optional double default_double_extension = 72 [default = 52e3 ];
  282. optional bool default_bool_extension = 73 [default = true ];
  283. optional string default_string_extension = 74 [default = "hello"];
  284. optional bytes default_bytes_extension = 75 [default = "world"];
  285. optional TestAllTypes.NestedEnum
  286. default_nested_enum_extension = 81 [default = BAR];
  287. optional ForeignEnum
  288. default_foreign_enum_extension = 82 [default = FOREIGN_BAR];
  289. optional protobuf_unittest_import.ImportEnum
  290. default_import_enum_extension = 83 [default = IMPORT_BAR];
  291. optional string default_string_piece_extension = 84 [ctype=STRING_PIECE,
  292. default="abc"];
  293. optional string default_cord_extension = 85 [ctype=CORD, default="123"];
  294. // For oneof test
  295. optional uint32 oneof_uint32_extension = 111;
  296. optional TestAllTypes.NestedMessage oneof_nested_message_extension = 112;
  297. optional string oneof_string_extension = 113;
  298. optional bytes oneof_bytes_extension = 114;
  299. }
  300. message TestMixedFieldsAndExtensions {
  301. optional int32 a = 1;
  302. repeated fixed32 b = 3;
  303. extensions 2, 4;
  304. extend TestMixedFieldsAndExtensions {
  305. optional int32 c = 2;
  306. repeated fixed32 d = 4;
  307. }
  308. }
  309. message TestGroup {
  310. optional group OptionalGroup = 16 {
  311. optional int32 a = 17;
  312. optional int32 zz = 89; // fast table size must be at least 16, for this
  313. // field to be parsed by the fast parser, since
  314. // 89 - 17 = 72 is a multiple of 8.
  315. }
  316. optional ForeignEnum optional_foreign_enum = 22;
  317. }
  318. message TestGroupExtension {
  319. extensions 1 to max;
  320. }
  321. message TestNestedExtension {
  322. extend TestAllExtensions {
  323. // Check for bug where string extensions declared in tested scope did not
  324. // compile.
  325. optional string test = 1002 [default="test"];
  326. // Used to test if generated extension name is correct when there are
  327. // underscores.
  328. optional string nested_string_extension = 1003;
  329. }
  330. extend TestGroupExtension {
  331. optional group OptionalGroup_extension = 16 {
  332. optional int32 a = 17;
  333. }
  334. optional ForeignEnum optional_foreign_enum_extension = 22;
  335. }
  336. }
  337. message TestChildExtension {
  338. optional string a = 1;
  339. optional string b = 2;
  340. optional TestAllExtensions optional_extension = 3;
  341. }
  342. // Emulates wireformat data of TestChildExtension with dynamic extension
  343. // (DynamicExtension).
  344. message TestChildExtensionData {
  345. message NestedTestAllExtensionsData {
  346. message NestedDynamicExtensions {
  347. optional int32 a = 1;
  348. optional int32 b = 2;
  349. }
  350. optional NestedDynamicExtensions dynamic = 409707008;
  351. }
  352. optional string a = 1;
  353. optional string b = 2;
  354. optional NestedTestAllExtensionsData optional_extension = 3;
  355. }
  356. message TestNestedChildExtension {
  357. optional int32 a = 1;
  358. optional TestChildExtension child = 2;
  359. }
  360. // Emulates wireformat data of TestNestedChildExtension with dynamic extension
  361. // (DynamicExtension).
  362. message TestNestedChildExtensionData {
  363. optional int32 a = 1;
  364. optional TestChildExtensionData child = 2;
  365. }
  366. // We have separate messages for testing required fields because it's
  367. // annoying to have to fill in required fields in TestProto in order to
  368. // do anything with it. Note that we don't need to test every type of
  369. // required filed because the code output is basically identical to
  370. // optional fields for all types.
  371. message TestRequired {
  372. required int32 a = 1;
  373. optional int32 dummy2 = 2;
  374. required int32 b = 3;
  375. extend TestAllExtensions {
  376. optional TestRequired single = 1000;
  377. repeated TestRequired multi = 1001;
  378. }
  379. // Pad the field count to 32 so that we can test that IsInitialized()
  380. // properly checks multiple elements of has_bits_.
  381. optional int32 dummy4 = 4;
  382. optional int32 dummy5 = 5;
  383. optional int32 dummy6 = 6;
  384. optional int32 dummy7 = 7;
  385. optional int32 dummy8 = 8;
  386. optional int32 dummy9 = 9;
  387. optional int32 dummy10 = 10;
  388. optional int32 dummy11 = 11;
  389. optional int32 dummy12 = 12;
  390. optional int32 dummy13 = 13;
  391. optional int32 dummy14 = 14;
  392. optional int32 dummy15 = 15;
  393. optional int32 dummy16 = 16;
  394. optional int32 dummy17 = 17;
  395. optional int32 dummy18 = 18;
  396. optional int32 dummy19 = 19;
  397. optional int32 dummy20 = 20;
  398. optional int32 dummy21 = 21;
  399. optional int32 dummy22 = 22;
  400. optional int32 dummy23 = 23;
  401. optional int32 dummy24 = 24;
  402. optional int32 dummy25 = 25;
  403. optional int32 dummy26 = 26;
  404. optional int32 dummy27 = 27;
  405. optional int32 dummy28 = 28;
  406. optional int32 dummy29 = 29;
  407. optional int32 dummy30 = 30;
  408. optional int32 dummy31 = 31;
  409. optional int32 dummy32 = 32;
  410. required int32 c = 33;
  411. // Add an optional child message to make this non-trivial for go/pdlazy.
  412. optional ForeignMessage optional_foreign = 34;
  413. }
  414. message TestRequiredForeign {
  415. optional TestRequired optional_message = 1;
  416. repeated TestRequired repeated_message = 2;
  417. optional int32 dummy = 3;
  418. // Missing required fields must not affect verification of child messages.
  419. optional NestedTestAllTypes optional_lazy_message = 4 [lazy = true];
  420. }
  421. message TestRequiredMessage {
  422. optional TestRequired optional_message = 1;
  423. repeated TestRequired repeated_message = 2;
  424. required TestRequired required_message = 3;
  425. }
  426. message TestNestedRequiredForeign {
  427. optional TestNestedRequiredForeign child = 1;
  428. optional TestRequiredForeign payload = 2;
  429. optional int32 dummy = 3;
  430. }
  431. // Test that we can use NestedMessage from outside TestAllTypes.
  432. message TestForeignNested {
  433. optional TestAllTypes.NestedMessage foreign_nested = 1;
  434. }
  435. // TestEmptyMessage is used to test unknown field support.
  436. message TestEmptyMessage {
  437. }
  438. // Like above, but declare all field numbers as potential extensions. No
  439. // actual extensions should ever be defined for this type.
  440. message TestEmptyMessageWithExtensions {
  441. extensions 1 to max;
  442. }
  443. // Needed for a Python test.
  444. message TestPickleNestedMessage {
  445. message NestedMessage {
  446. optional int32 bb = 1;
  447. message NestedNestedMessage {
  448. optional int32 cc = 1;
  449. }
  450. }
  451. }
  452. message TestMultipleExtensionRanges {
  453. extensions 42;
  454. extensions 4143 to 4243;
  455. extensions 65536 to max;
  456. }
  457. // Test that really large tag numbers don't break anything.
  458. message TestReallyLargeTagNumber {
  459. // The largest possible tag number is 2^28 - 1, since the wire format uses
  460. // three bits to communicate wire type.
  461. optional int32 a = 1;
  462. optional int32 bb = 268435455;
  463. }
  464. message TestRecursiveMessage {
  465. optional TestRecursiveMessage a = 1;
  466. optional int32 i = 2;
  467. }
  468. // Test that mutual recursion works.
  469. message TestMutualRecursionA {
  470. message SubMessage {
  471. optional TestMutualRecursionB b = 1;
  472. }
  473. optional TestMutualRecursionB bb = 1;
  474. optional group SubGroup = 2 {
  475. optional SubMessage sub_message = 3; // Needed because of bug in javatest
  476. optional TestAllTypes not_in_this_scc = 4;
  477. }
  478. }
  479. message TestMutualRecursionB {
  480. optional TestMutualRecursionA a = 1;
  481. optional int32 optional_int32 = 2;
  482. }
  483. message TestIsInitialized {
  484. message SubMessage {
  485. optional group SubGroup = 1 {
  486. required int32 i = 2;
  487. }
  488. }
  489. optional SubMessage sub_message = 1;
  490. }
  491. // Test that groups have disjoint field numbers from their siblings and
  492. // parents. This is NOT possible in proto1; only google.protobuf. When attempting
  493. // to compile with proto1, this will emit an error; so we only include it
  494. // in protobuf_unittest_proto.
  495. message TestDupFieldNumber { // NO_PROTO1
  496. optional int32 a = 1; // NO_PROTO1
  497. optional group Foo = 2 { optional int32 a = 1; } // NO_PROTO1
  498. optional group Bar = 3 { optional int32 a = 1; } // NO_PROTO1
  499. } // NO_PROTO1
  500. // Additional messages for testing lazy fields.
  501. message TestEagerMessage {
  502. optional TestAllTypes sub_message = 1 [lazy=false];
  503. }
  504. message TestLazyMessage {
  505. optional TestAllTypes sub_message = 1 [lazy=true];
  506. }
  507. message TestEagerMaybeLazy {
  508. message NestedMessage {
  509. optional TestPackedTypes packed = 1;
  510. }
  511. optional TestAllTypes message_foo = 1;
  512. optional TestAllTypes message_bar = 2;
  513. optional NestedMessage message_baz = 3;
  514. }
  515. // Needed for a Python test.
  516. message TestNestedMessageHasBits {
  517. message NestedMessage {
  518. repeated int32 nestedmessage_repeated_int32 = 1;
  519. repeated ForeignMessage nestedmessage_repeated_foreignmessage = 2;
  520. }
  521. optional NestedMessage optional_nested_message = 1;
  522. }
  523. // Test an enum that has multiple values with the same number.
  524. enum TestEnumWithDupValue {
  525. option allow_alias = true;
  526. FOO1 = 1;
  527. BAR1 = 2;
  528. BAZ = 3;
  529. FOO2 = 1;
  530. BAR2 = 2;
  531. }
  532. // Test an enum with large, unordered values.
  533. enum TestSparseEnum {
  534. SPARSE_A = 123;
  535. SPARSE_B = 62374;
  536. SPARSE_C = 12589234;
  537. SPARSE_D = -15;
  538. SPARSE_E = -53452;
  539. SPARSE_F = 0;
  540. SPARSE_G = 2;
  541. }
  542. // Test message with CamelCase field names. This violates Protocol Buffer
  543. // standard style.
  544. message TestCamelCaseFieldNames {
  545. optional int32 PrimitiveField = 1;
  546. optional string StringField = 2;
  547. optional ForeignEnum EnumField = 3;
  548. optional ForeignMessage MessageField = 4;
  549. optional string StringPieceField = 5 [ctype=STRING_PIECE];
  550. optional string CordField = 6 [ctype=CORD];
  551. repeated int32 RepeatedPrimitiveField = 7;
  552. repeated string RepeatedStringField = 8;
  553. repeated ForeignEnum RepeatedEnumField = 9;
  554. repeated ForeignMessage RepeatedMessageField = 10;
  555. repeated string RepeatedStringPieceField = 11 [ctype=STRING_PIECE];
  556. repeated string RepeatedCordField = 12 [ctype=CORD];
  557. }
  558. // We list fields out of order, to ensure that we're using field number and not
  559. // field index to determine serialization order.
  560. message TestFieldOrderings {
  561. optional string my_string = 11;
  562. extensions 2 to 10;
  563. optional int64 my_int = 1;
  564. extensions 12 to 100;
  565. optional float my_float = 101;
  566. message NestedMessage {
  567. optional int64 oo = 2;
  568. // The field name "b" fails to compile in proto1 because it conflicts with
  569. // a local variable named "b" in one of the generated methods. Doh.
  570. // This file needs to compile in proto1 to test backwards-compatibility.
  571. optional int32 bb = 1;
  572. }
  573. optional NestedMessage optional_nested_message = 200;
  574. }
  575. extend TestFieldOrderings {
  576. optional string my_extension_string = 50;
  577. optional int32 my_extension_int = 5;
  578. }
  579. message TestExtensionOrderings1 {
  580. extend TestFieldOrderings {
  581. optional TestExtensionOrderings1 test_ext_orderings1 = 13;
  582. }
  583. optional string my_string = 1;
  584. }
  585. message TestExtensionOrderings2 {
  586. extend TestFieldOrderings {
  587. optional TestExtensionOrderings2 test_ext_orderings2 = 12;
  588. }
  589. message TestExtensionOrderings3 {
  590. extend TestFieldOrderings {
  591. optional TestExtensionOrderings3 test_ext_orderings3 = 14;
  592. }
  593. optional string my_string = 1;
  594. }
  595. optional string my_string = 1;
  596. }
  597. message TestExtremeDefaultValues {
  598. optional bytes escaped_bytes = 1 [default = "\0\001\a\b\f\n\r\t\v\\\'\"\xfe"];
  599. optional uint32 large_uint32 = 2 [default = 0xFFFFFFFF];
  600. optional uint64 large_uint64 = 3 [default = 0xFFFFFFFFFFFFFFFF];
  601. optional int32 small_int32 = 4 [default = -0x7FFFFFFF];
  602. optional int64 small_int64 = 5 [default = -0x7FFFFFFFFFFFFFFF];
  603. optional int32 really_small_int32 = 21 [default = -0x80000000];
  604. optional int64 really_small_int64 = 22 [default = -0x8000000000000000];
  605. // The default value here is UTF-8 for "\u1234". (We could also just type
  606. // the UTF-8 text directly into this text file rather than escape it, but
  607. // lots of people use editors that would be confused by this.)
  608. optional string utf8_string = 6 [default = "\341\210\264"];
  609. // Tests for single-precision floating-point values.
  610. optional float zero_float = 7 [default = 0];
  611. optional float one_float = 8 [default = 1];
  612. optional float small_float = 9 [default = 1.5];
  613. optional float negative_one_float = 10 [default = -1];
  614. optional float negative_float = 11 [default = -1.5];
  615. // Using exponents
  616. optional float large_float = 12 [default = 2E8];
  617. optional float small_negative_float = 13 [default = -8e-28];
  618. // Text for nonfinite floating-point values.
  619. optional double inf_double = 14 [default = inf];
  620. optional double neg_inf_double = 15 [default = -inf];
  621. optional double nan_double = 16 [default = nan];
  622. optional float inf_float = 17 [default = inf];
  623. optional float neg_inf_float = 18 [default = -inf];
  624. optional float nan_float = 19 [default = nan];
  625. // Tests for C++ trigraphs.
  626. // Trigraphs should be escaped in C++ generated files, but they should not be
  627. // escaped for other languages.
  628. // Note that in .proto file, "\?" is a valid way to escape ? in string
  629. // literals.
  630. optional string cpp_trigraph = 20 [default = "? \? ?? \?? \??? ??/ ?\?-"];
  631. // String defaults containing the character '\000'
  632. optional string string_with_zero = 23 [default = "hel\000lo"];
  633. optional bytes bytes_with_zero = 24 [default = "wor\000ld"];
  634. optional string string_piece_with_zero = 25 [ctype=STRING_PIECE,
  635. default="ab\000c"];
  636. optional string cord_with_zero = 26 [ctype=CORD,
  637. default="12\0003"];
  638. optional string replacement_string = 27 [default="${unknown}"];
  639. }
  640. message SparseEnumMessage {
  641. optional TestSparseEnum sparse_enum = 1;
  642. }
  643. // Test String and Bytes: string is for valid UTF-8 strings
  644. message OneString {
  645. optional string data = 1;
  646. }
  647. message MoreString {
  648. repeated string data = 1;
  649. }
  650. message OneBytes {
  651. optional bytes data = 1;
  652. }
  653. message MoreBytes {
  654. repeated bytes data = 1;
  655. }
  656. message ManyOptionalString {
  657. optional string str1 = 1;
  658. optional string str2 = 2;
  659. optional string str3 = 3;
  660. optional string str4 = 4;
  661. optional string str5 = 5;
  662. optional string str6 = 6;
  663. optional string str7 = 7;
  664. optional string str8 = 8;
  665. optional string str9 = 9;
  666. optional string str10 = 10;
  667. optional string str11 = 11;
  668. optional string str12 = 12;
  669. optional string str13 = 13;
  670. optional string str14 = 14;
  671. optional string str15 = 15;
  672. optional string str16 = 16;
  673. optional string str17 = 17;
  674. optional string str18 = 18;
  675. optional string str19 = 19;
  676. optional string str20 = 20;
  677. optional string str21 = 21;
  678. optional string str22 = 22;
  679. optional string str23 = 23;
  680. optional string str24 = 24;
  681. optional string str25 = 25;
  682. optional string str26 = 26;
  683. optional string str27 = 27;
  684. optional string str28 = 28;
  685. optional string str29 = 29;
  686. optional string str30 = 30;
  687. optional string str31 = 31;
  688. optional string str32 = 32;
  689. }
  690. // Test int32, uint32, int64, uint64, and bool are all compatible
  691. message Int32Message {
  692. optional int32 data = 1;
  693. }
  694. message Uint32Message {
  695. optional uint32 data = 1;
  696. }
  697. message Int64Message {
  698. optional int64 data = 1;
  699. }
  700. message Uint64Message {
  701. optional uint64 data = 1;
  702. }
  703. message BoolMessage {
  704. optional bool data = 1;
  705. }
  706. // Test oneofs.
  707. message TestOneof {
  708. oneof foo {
  709. int32 foo_int = 1;
  710. string foo_string = 2;
  711. TestAllTypes foo_message = 3;
  712. group FooGroup = 4 {
  713. optional int32 a = 5;
  714. optional string b = 6;
  715. }
  716. }
  717. }
  718. message TestOneofBackwardsCompatible {
  719. optional int32 foo_int = 1;
  720. optional string foo_string = 2;
  721. optional TestAllTypes foo_message = 3;
  722. optional group FooGroup = 4 {
  723. optional int32 a = 5;
  724. optional string b = 6;
  725. }
  726. }
  727. message TestOneof2 {
  728. oneof foo {
  729. int32 foo_int = 1;
  730. string foo_string = 2;
  731. string foo_cord = 3 [ctype=CORD];
  732. string foo_string_piece = 4 [ctype=STRING_PIECE];
  733. bytes foo_bytes = 5;
  734. NestedEnum foo_enum = 6;
  735. NestedMessage foo_message = 7;
  736. group FooGroup = 8 {
  737. optional int32 a = 9;
  738. optional string b = 10;
  739. }
  740. NestedMessage foo_lazy_message = 11 [lazy=true];
  741. }
  742. oneof bar {
  743. int32 bar_int = 12 [default = 5];
  744. string bar_string = 13 [default = "STRING"];
  745. string bar_cord = 14 [ctype=CORD, default = "CORD"];
  746. string bar_string_piece = 15 [ctype=STRING_PIECE, default = "SPIECE"];
  747. bytes bar_bytes = 16 [default = "BYTES"];
  748. NestedEnum bar_enum = 17 [default = BAR];
  749. string bar_string_with_empty_default = 20 [default = ""];
  750. string bar_cord_with_empty_default = 21 [ctype=CORD, default = ""];
  751. string bar_string_piece_with_empty_default = 22 [ctype=STRING_PIECE, default = ""];
  752. bytes bar_bytes_with_empty_default = 23 [default = ""];
  753. }
  754. optional int32 baz_int = 18;
  755. optional string baz_string = 19 [default = "BAZ"];
  756. message NestedMessage {
  757. optional int64 moo_int = 1;
  758. repeated int32 corge_int = 2;
  759. }
  760. enum NestedEnum {
  761. FOO = 1;
  762. BAR = 2;
  763. BAZ = 3;
  764. }
  765. }
  766. message TestRequiredOneof {
  767. oneof foo {
  768. int32 foo_int = 1;
  769. string foo_string = 2;
  770. NestedMessage foo_message = 3;
  771. NestedMessage foo_lazy_message = 4 [lazy = true];
  772. }
  773. message NestedMessage {
  774. required double required_double = 1;
  775. }
  776. }
  777. // Test messages for packed fields
  778. message TestPackedTypes {
  779. repeated int32 packed_int32 = 90 [packed = true];
  780. repeated int64 packed_int64 = 91 [packed = true];
  781. repeated uint32 packed_uint32 = 92 [packed = true];
  782. repeated uint64 packed_uint64 = 93 [packed = true];
  783. repeated sint32 packed_sint32 = 94 [packed = true];
  784. repeated sint64 packed_sint64 = 95 [packed = true];
  785. repeated fixed32 packed_fixed32 = 96 [packed = true];
  786. repeated fixed64 packed_fixed64 = 97 [packed = true];
  787. repeated sfixed32 packed_sfixed32 = 98 [packed = true];
  788. repeated sfixed64 packed_sfixed64 = 99 [packed = true];
  789. repeated float packed_float = 100 [packed = true];
  790. repeated double packed_double = 101 [packed = true];
  791. repeated bool packed_bool = 102 [packed = true];
  792. repeated ForeignEnum packed_enum = 103 [packed = true];
  793. }
  794. // A message with the same fields as TestPackedTypes, but without packing. Used
  795. // to test packed <-> unpacked wire compatibility.
  796. message TestUnpackedTypes {
  797. repeated int32 unpacked_int32 = 90 [packed = false];
  798. repeated int64 unpacked_int64 = 91 [packed = false];
  799. repeated uint32 unpacked_uint32 = 92 [packed = false];
  800. repeated uint64 unpacked_uint64 = 93 [packed = false];
  801. repeated sint32 unpacked_sint32 = 94 [packed = false];
  802. repeated sint64 unpacked_sint64 = 95 [packed = false];
  803. repeated fixed32 unpacked_fixed32 = 96 [packed = false];
  804. repeated fixed64 unpacked_fixed64 = 97 [packed = false];
  805. repeated sfixed32 unpacked_sfixed32 = 98 [packed = false];
  806. repeated sfixed64 unpacked_sfixed64 = 99 [packed = false];
  807. repeated float unpacked_float = 100 [packed = false];
  808. repeated double unpacked_double = 101 [packed = false];
  809. repeated bool unpacked_bool = 102 [packed = false];
  810. repeated ForeignEnum unpacked_enum = 103 [packed = false];
  811. }
  812. message TestPackedExtensions {
  813. extensions 1 to max;
  814. }
  815. extend TestPackedExtensions {
  816. repeated int32 packed_int32_extension = 90 [packed = true];
  817. repeated int64 packed_int64_extension = 91 [packed = true];
  818. repeated uint32 packed_uint32_extension = 92 [packed = true];
  819. repeated uint64 packed_uint64_extension = 93 [packed = true];
  820. repeated sint32 packed_sint32_extension = 94 [packed = true];
  821. repeated sint64 packed_sint64_extension = 95 [packed = true];
  822. repeated fixed32 packed_fixed32_extension = 96 [packed = true];
  823. repeated fixed64 packed_fixed64_extension = 97 [packed = true];
  824. repeated sfixed32 packed_sfixed32_extension = 98 [packed = true];
  825. repeated sfixed64 packed_sfixed64_extension = 99 [packed = true];
  826. repeated float packed_float_extension = 100 [packed = true];
  827. repeated double packed_double_extension = 101 [packed = true];
  828. repeated bool packed_bool_extension = 102 [packed = true];
  829. repeated ForeignEnum packed_enum_extension = 103 [packed = true];
  830. }
  831. message TestUnpackedExtensions {
  832. extensions 1 to max;
  833. }
  834. extend TestUnpackedExtensions {
  835. repeated int32 unpacked_int32_extension = 90 [packed = false];
  836. repeated int64 unpacked_int64_extension = 91 [packed = false];
  837. repeated uint32 unpacked_uint32_extension = 92 [packed = false];
  838. repeated uint64 unpacked_uint64_extension = 93 [packed = false];
  839. repeated sint32 unpacked_sint32_extension = 94 [packed = false];
  840. repeated sint64 unpacked_sint64_extension = 95 [packed = false];
  841. repeated fixed32 unpacked_fixed32_extension = 96 [packed = false];
  842. repeated fixed64 unpacked_fixed64_extension = 97 [packed = false];
  843. repeated sfixed32 unpacked_sfixed32_extension = 98 [packed = false];
  844. repeated sfixed64 unpacked_sfixed64_extension = 99 [packed = false];
  845. repeated float unpacked_float_extension = 100 [packed = false];
  846. repeated double unpacked_double_extension = 101 [packed = false];
  847. repeated bool unpacked_bool_extension = 102 [packed = false];
  848. repeated ForeignEnum unpacked_enum_extension = 103 [packed = false];
  849. }
  850. // Used by ExtensionSetTest/DynamicExtensions. The test actually builds
  851. // a set of extensions to TestAllExtensions dynamically, based on the fields
  852. // of this message type.
  853. message TestDynamicExtensions {
  854. enum DynamicEnumType {
  855. DYNAMIC_FOO = 2200;
  856. DYNAMIC_BAR = 2201;
  857. DYNAMIC_BAZ = 2202;
  858. }
  859. message DynamicMessageType {
  860. optional int32 dynamic_field = 2100;
  861. }
  862. optional fixed32 scalar_extension = 2000;
  863. optional ForeignEnum enum_extension = 2001;
  864. optional DynamicEnumType dynamic_enum_extension = 2002;
  865. optional ForeignMessage message_extension = 2003;
  866. optional DynamicMessageType dynamic_message_extension = 2004;
  867. repeated string repeated_extension = 2005;
  868. repeated sint32 packed_extension = 2006 [packed = true];
  869. }
  870. message TestRepeatedString {
  871. repeated string repeated_string1 = 1;
  872. repeated string repeated_string2 = 2;
  873. repeated bytes repeated_bytes11 = 11;
  874. repeated bytes repeated_bytes12 = 12;
  875. }
  876. message TestRepeatedScalarDifferentTagSizes {
  877. // Parsing repeated fixed size values used to fail. This message needs to be
  878. // used in order to get a tag of the right size; all of the repeated fields
  879. // in TestAllTypes didn't trigger the check.
  880. repeated fixed32 repeated_fixed32 = 12;
  881. // Check for a varint type, just for good measure.
  882. repeated int32 repeated_int32 = 13;
  883. // These have two-byte tags.
  884. repeated fixed64 repeated_fixed64 = 2046;
  885. repeated int64 repeated_int64 = 2047;
  886. // Three byte tags.
  887. repeated float repeated_float = 262142;
  888. repeated uint64 repeated_uint64 = 262143;
  889. }
  890. // Test that if an optional or required message/group field appears multiple
  891. // times in the input, they need to be merged.
  892. message TestParsingMerge {
  893. // RepeatedFieldsGenerator defines matching field types as TestParsingMerge,
  894. // except that all fields are repeated. In the tests, we will serialize the
  895. // RepeatedFieldsGenerator to bytes, and parse the bytes to TestParsingMerge.
  896. // Repeated fields in RepeatedFieldsGenerator are expected to be merged into
  897. // the corresponding required/optional fields in TestParsingMerge.
  898. message RepeatedFieldsGenerator {
  899. repeated TestAllTypes field1 = 1;
  900. repeated TestAllTypes field2 = 2;
  901. repeated TestAllTypes field3 = 3;
  902. repeated group Group1 = 10 {
  903. optional TestAllTypes field1 = 11;
  904. }
  905. repeated group Group2 = 20 {
  906. optional TestAllTypes field1 = 21;
  907. }
  908. repeated TestAllTypes ext1 = 1000;
  909. repeated TestAllTypes ext2 = 1001;
  910. }
  911. required TestAllTypes required_all_types = 1;
  912. optional TestAllTypes optional_all_types = 2;
  913. repeated TestAllTypes repeated_all_types = 3;
  914. optional group OptionalGroup = 10 {
  915. optional TestAllTypes optional_group_all_types = 11;
  916. }
  917. repeated group RepeatedGroup = 20 {
  918. optional TestAllTypes repeated_group_all_types = 21;
  919. }
  920. extensions 1000 to max;
  921. extend TestParsingMerge {
  922. optional TestAllTypes optional_ext = 1000;
  923. repeated TestAllTypes repeated_ext = 1001;
  924. }
  925. }
  926. // Test that the correct exception is thrown by parseFrom in a corner case
  927. // involving merging, extensions, and required fields.
  928. message TestMergeException {
  929. optional TestAllExtensions all_extensions = 1;
  930. }
  931. message TestCommentInjectionMessage {
  932. // */ <- This should not close the generated doc comment
  933. optional string a = 1 [default="*/ <- Neither should this."];
  934. }
  935. // Used to check that the c++ code generator re-orders messages to reduce
  936. // padding.
  937. message TestMessageSize {
  938. optional bool m1 = 1;
  939. optional int64 m2 = 2;
  940. optional bool m3 = 3;
  941. optional string m4 = 4;
  942. optional int32 m5 = 5;
  943. optional int64 m6 = 6;
  944. }
  945. // Test that RPC services work.
  946. message FooRequest {}
  947. message FooResponse {}
  948. message FooClientMessage {}
  949. message FooServerMessage{}
  950. service TestService {
  951. rpc Foo(FooRequest) returns (FooResponse);
  952. rpc Bar(BarRequest) returns (BarResponse);
  953. }
  954. message BarRequest {}
  955. message BarResponse {}
  956. message TestJsonName {
  957. optional int32 field_name1 = 1;
  958. optional int32 fieldName2 = 2;
  959. optional int32 FieldName3 = 3;
  960. optional int32 _field_name4 = 4;
  961. optional int32 FIELD_NAME5 = 5;
  962. optional int32 field_name6 = 6 [json_name = "@type"];
  963. optional int32 fieldname7 = 7;
  964. }
  965. message TestHugeFieldNumbers {
  966. optional int32 optional_int32 = 536870000;
  967. optional int32 fixed_32 = 536870001;
  968. repeated int32 repeated_int32 = 536870002 [packed = false];
  969. repeated int32 packed_int32 = 536870003 [packed = true];
  970. optional ForeignEnum optional_enum = 536870004;
  971. optional string optional_string = 536870005;
  972. optional bytes optional_bytes = 536870006;
  973. optional ForeignMessage optional_message = 536870007;
  974. optional group OptionalGroup = 536870008 {
  975. optional int32 group_a = 536870009;
  976. }
  977. map<string, string> string_string_map = 536870010;
  978. oneof oneof_field {
  979. uint32 oneof_uint32 = 536870011;
  980. TestAllTypes oneof_test_all_types = 536870012;
  981. string oneof_string = 536870013;
  982. bytes oneof_bytes = 536870014;
  983. }
  984. extensions 536860000 to 536869999;
  985. }
  986. extend TestHugeFieldNumbers {
  987. optional TestAllTypes test_all_types = 536860000;
  988. }
  989. message TestExtensionInsideTable {
  990. optional int32 field1 = 1;
  991. optional int32 field2 = 2;
  992. optional int32 field3 = 3;
  993. optional int32 field4 = 4;
  994. extensions 5 to 5;
  995. optional int32 field6 = 6;
  996. optional int32 field7 = 7;
  997. optional int32 field8 = 8;
  998. optional int32 field9 = 9;
  999. optional int32 field10 = 10;
  1000. }
  1001. extend TestExtensionInsideTable {
  1002. optional int32 test_extension_inside_table_extension = 5;
  1003. }
  1004. // NOTE(b/202996544): Intentionally nested to mirror go/glep.
  1005. message TestNestedGroupExtensionOuter {
  1006. optional group Layer1OptionalGroup = 1 {
  1007. repeated group Layer2RepeatedGroup = 2 {
  1008. extensions 3
  1009. // NOTE: extension metadata is not supported due to targets such as
  1010. // `//third_party/protobuf_legacy_opensource/src:shell_scripts_test`,
  1011. // eee https://screenshot.googleplex.com/Axz2QD8nxjdpyFF
  1012. //[metadata = {
  1013. // NOTE: can't write type there due to some clever build gen code at
  1014. // http://google3/net/proto2/internal/BUILD;l=1247;rcl=411090862
  1015. // type: "protobuf_unittest.TestNestedGroupExtensionInnerExtension",
  1016. // name: "inner",
  1017. // }]
  1018. ;
  1019. optional string another_field = 6;
  1020. }
  1021. repeated group Layer2AnotherOptionalRepeatedGroup = 4 {
  1022. optional string but_why_tho = 5;
  1023. }
  1024. }
  1025. }
  1026. message TestNestedGroupExtensionInnerExtension {
  1027. optional string inner_name= 1;
  1028. }
  1029. extend TestNestedGroupExtensionOuter.Layer1OptionalGroup.Layer2RepeatedGroup {
  1030. optional TestNestedGroupExtensionInnerExtension inner = 3;
  1031. }
  1032. enum VeryLargeEnum {
  1033. ENUM_LABEL_DEFAULT = 0;
  1034. ENUM_LABEL_1 = 1;
  1035. ENUM_LABEL_2 = 2;
  1036. ENUM_LABEL_3 = 3;
  1037. ENUM_LABEL_4 = 4;
  1038. ENUM_LABEL_5 = 5;
  1039. ENUM_LABEL_6 = 6;
  1040. ENUM_LABEL_7 = 7;
  1041. ENUM_LABEL_8 = 8;
  1042. ENUM_LABEL_9 = 9;
  1043. ENUM_LABEL_10 = 10;
  1044. ENUM_LABEL_11 = 11;
  1045. ENUM_LABEL_12 = 12;
  1046. ENUM_LABEL_13 = 13;
  1047. ENUM_LABEL_14 = 14;
  1048. ENUM_LABEL_15 = 15;
  1049. ENUM_LABEL_16 = 16;
  1050. ENUM_LABEL_17 = 17;
  1051. ENUM_LABEL_18 = 18;
  1052. ENUM_LABEL_19 = 19;
  1053. ENUM_LABEL_20 = 20;
  1054. ENUM_LABEL_21 = 21;
  1055. ENUM_LABEL_22 = 22;
  1056. ENUM_LABEL_23 = 23;
  1057. ENUM_LABEL_24 = 24;
  1058. ENUM_LABEL_25 = 25;
  1059. ENUM_LABEL_26 = 26;
  1060. ENUM_LABEL_27 = 27;
  1061. ENUM_LABEL_28 = 28;
  1062. ENUM_LABEL_29 = 29;
  1063. ENUM_LABEL_30 = 30;
  1064. ENUM_LABEL_31 = 31;
  1065. ENUM_LABEL_32 = 32;
  1066. ENUM_LABEL_33 = 33;
  1067. ENUM_LABEL_34 = 34;
  1068. ENUM_LABEL_35 = 35;
  1069. ENUM_LABEL_36 = 36;
  1070. ENUM_LABEL_37 = 37;
  1071. ENUM_LABEL_38 = 38;
  1072. ENUM_LABEL_39 = 39;
  1073. ENUM_LABEL_40 = 40;
  1074. ENUM_LABEL_41 = 41;
  1075. ENUM_LABEL_42 = 42;
  1076. ENUM_LABEL_43 = 43;
  1077. ENUM_LABEL_44 = 44;
  1078. ENUM_LABEL_45 = 45;
  1079. ENUM_LABEL_46 = 46;
  1080. ENUM_LABEL_47 = 47;
  1081. ENUM_LABEL_48 = 48;
  1082. ENUM_LABEL_49 = 49;
  1083. ENUM_LABEL_50 = 50;
  1084. ENUM_LABEL_51 = 51;
  1085. ENUM_LABEL_52 = 52;
  1086. ENUM_LABEL_53 = 53;
  1087. ENUM_LABEL_54 = 54;
  1088. ENUM_LABEL_55 = 55;
  1089. ENUM_LABEL_56 = 56;
  1090. ENUM_LABEL_57 = 57;
  1091. ENUM_LABEL_58 = 58;
  1092. ENUM_LABEL_59 = 59;
  1093. ENUM_LABEL_60 = 60;
  1094. ENUM_LABEL_61 = 61;
  1095. ENUM_LABEL_62 = 62;
  1096. ENUM_LABEL_63 = 63;
  1097. ENUM_LABEL_64 = 64;
  1098. ENUM_LABEL_65 = 65;
  1099. ENUM_LABEL_66 = 66;
  1100. ENUM_LABEL_67 = 67;
  1101. ENUM_LABEL_68 = 68;
  1102. ENUM_LABEL_69 = 69;
  1103. ENUM_LABEL_70 = 70;
  1104. ENUM_LABEL_71 = 71;
  1105. ENUM_LABEL_72 = 72;
  1106. ENUM_LABEL_73 = 73;
  1107. ENUM_LABEL_74 = 74;
  1108. ENUM_LABEL_75 = 75;
  1109. ENUM_LABEL_76 = 76;
  1110. ENUM_LABEL_77 = 77;
  1111. ENUM_LABEL_78 = 78;
  1112. ENUM_LABEL_79 = 79;
  1113. ENUM_LABEL_80 = 80;
  1114. ENUM_LABEL_81 = 81;
  1115. ENUM_LABEL_82 = 82;
  1116. ENUM_LABEL_83 = 83;
  1117. ENUM_LABEL_84 = 84;
  1118. ENUM_LABEL_85 = 85;
  1119. ENUM_LABEL_86 = 86;
  1120. ENUM_LABEL_87 = 87;
  1121. ENUM_LABEL_88 = 88;
  1122. ENUM_LABEL_89 = 89;
  1123. ENUM_LABEL_90 = 90;
  1124. ENUM_LABEL_91 = 91;
  1125. ENUM_LABEL_92 = 92;
  1126. ENUM_LABEL_93 = 93;
  1127. ENUM_LABEL_94 = 94;
  1128. ENUM_LABEL_95 = 95;
  1129. ENUM_LABEL_96 = 96;
  1130. ENUM_LABEL_97 = 97;
  1131. ENUM_LABEL_98 = 98;
  1132. ENUM_LABEL_99 = 99;
  1133. ENUM_LABEL_100 = 100;
  1134. };
  1135. message TestExtensionRangeSerialize {
  1136. optional int32 foo_one = 1;
  1137. extensions 2 to 2;
  1138. extensions 3 to 4;
  1139. optional int32 foo_two = 6;
  1140. optional int32 foo_three = 7;
  1141. extensions 9 to 10;
  1142. optional int32 foo_four = 13;
  1143. extensions 15 to 15;
  1144. extensions 17 to 17;
  1145. extensions 19 to 19;
  1146. extend TestExtensionRangeSerialize {
  1147. optional int32 bar_one = 2;
  1148. optional int32 bar_two = 4;
  1149. optional int32 bar_three = 10;
  1150. optional int32 bar_four = 15;
  1151. optional int32 bar_five = 19;
  1152. }
  1153. }
  1154. message TestVerifyInt32Simple {
  1155. optional int32 optional_int32_1 = 1;
  1156. optional int32 optional_int32_2 = 2;
  1157. optional int32 optional_int32_63 = 63;
  1158. optional int32 optional_int32_64 = 64;
  1159. }
  1160. message TestVerifyInt32 {
  1161. optional int32 optional_int32_1 = 1;
  1162. optional int32 optional_int32_2 = 2;
  1163. optional int32 optional_int32_63 = 63;
  1164. optional int32 optional_int32_64 = 64;
  1165. optional TestAllTypes optional_all_types = 9;
  1166. repeated TestAllTypes repeated_all_types = 10;
  1167. }
  1168. message TestVerifyMostlyInt32 {
  1169. optional int64 optional_int64_30 = 30;
  1170. optional int32 optional_int32_1 = 1;
  1171. optional int32 optional_int32_2 = 2;
  1172. optional int32 optional_int32_3 = 3;
  1173. optional int32 optional_int32_4 = 4;
  1174. optional int32 optional_int32_63 = 63;
  1175. optional int32 optional_int32_64 = 64;
  1176. optional TestAllTypes optional_all_types = 9;
  1177. repeated TestAllTypes repeated_all_types = 10;
  1178. }
  1179. message TestVerifyMostlyInt32BigFieldNumber {
  1180. optional int64 optional_int64_30 = 30;
  1181. optional int32 optional_int32_300 = 300;
  1182. optional int32 optional_int32_1 = 1;
  1183. optional int32 optional_int32_2 = 2;
  1184. optional int32 optional_int32_3 = 3;
  1185. optional int32 optional_int32_4 = 4;
  1186. optional int32 optional_int32_63 = 63;
  1187. optional int32 optional_int32_64 = 64;
  1188. optional TestAllTypes optional_all_types = 9;
  1189. repeated TestAllTypes repeated_all_types = 10;
  1190. }
  1191. message TestVerifyUint32Simple {
  1192. optional uint32 optional_uint32_1 = 1;
  1193. optional uint32 optional_uint32_2 = 2;
  1194. optional uint32 optional_uint32_63 = 63;
  1195. optional uint32 optional_uint32_64 = 64;
  1196. }
  1197. message TestVerifyUint32 {
  1198. optional uint32 optional_uint32_1 = 1;
  1199. optional uint32 optional_uint32_2 = 2;
  1200. optional uint32 optional_uint32_63 = 63;
  1201. optional uint32 optional_uint32_64 = 64;
  1202. optional TestAllTypes optional_all_types = 9;
  1203. repeated TestAllTypes repeated_all_types = 10;
  1204. }
  1205. message TestVerifyOneUint32 {
  1206. optional uint32 optional_uint32_1 = 1;
  1207. optional int32 optional_int32_2 = 2;
  1208. optional int32 optional_int32_63 = 63;
  1209. optional int32 optional_int32_64 = 64;
  1210. optional TestAllTypes optional_all_types = 9;
  1211. repeated TestAllTypes repeated_all_types = 10;
  1212. }
  1213. message TestVerifyOneInt32BigFieldNumber {
  1214. optional int32 optional_int32_65 = 65;
  1215. optional int64 optional_int64_1 = 1;
  1216. optional int64 optional_int64_2 = 2;
  1217. optional int64 optional_int64_63 = 63;
  1218. optional int64 optional_int64_64 = 64;
  1219. optional TestAllTypes optional_all_types = 9;
  1220. repeated TestAllTypes repeated_all_types = 10;
  1221. }
  1222. message TestVerifyInt32BigFieldNumber {
  1223. optional int32 optional_int32_1000 = 1000;
  1224. optional int32 optional_int32_65 = 65;
  1225. optional int32 optional_int32_1 = 1;
  1226. optional int32 optional_int32_2 = 2;
  1227. optional int32 optional_int32_63 = 63;
  1228. optional int32 optional_int32_64 = 64;
  1229. optional TestAllTypes optional_all_types = 9;
  1230. repeated TestAllTypes repeated_all_types = 10;
  1231. }
  1232. message TestVerifyUint32BigFieldNumber {
  1233. optional uint32 optional_uint32_1000 = 1000;
  1234. optional uint32 optional_uint32_65 = 65;
  1235. optional uint32 optional_uint32_1 = 1;
  1236. optional uint32 optional_uint32_2 = 2;
  1237. optional uint32 optional_uint32_63 = 63;
  1238. optional uint32 optional_uint32_64 = 64;
  1239. optional TestAllTypes optional_all_types = 9;
  1240. repeated TestAllTypes repeated_all_types = 10;
  1241. }
  1242. message TestVerifyBigFieldNumberUint32 {
  1243. message Nested {
  1244. optional uint32 optional_uint32_5000 = 5000;
  1245. optional uint32 optional_uint32_1000 = 1000;
  1246. optional uint32 optional_uint32_66 = 66;
  1247. optional uint32 optional_uint32_65 = 65;
  1248. optional uint32 optional_uint32_1 = 1;
  1249. optional uint32 optional_uint32_2 = 2;
  1250. optional uint32 optional_uint32_63 = 63;
  1251. optional uint32 optional_uint32_64 = 64;
  1252. optional Nested optional_nested = 9;
  1253. repeated Nested repeated_nested = 10;
  1254. }
  1255. optional Nested optional_nested = 1;
  1256. }
  1257. // This message contains different kind of enums to exercise the different
  1258. // parsers in table-driven.
  1259. message EnumParseTester {
  1260. enum SeqSmall0 {
  1261. SEQ_SMALL_0_DEFAULT = 0;
  1262. SEQ_SMALL_0_1 = 1;
  1263. SEQ_SMALL_0_2 = 2;
  1264. };
  1265. optional SeqSmall0 optional_seq_small_0_lowfield = 1;
  1266. optional SeqSmall0 optional_seq_small_0_midfield = 1001;
  1267. optional SeqSmall0 optional_seq_small_0_hifield = 1000001;
  1268. repeated SeqSmall0 repeated_seq_small_0_lowfield = 2;
  1269. repeated SeqSmall0 repeated_seq_small_0_midfield = 1002;
  1270. repeated SeqSmall0 repeated_seq_small_0_hifield = 1000002;
  1271. repeated SeqSmall0 packed_seq_small_0_lowfield = 3 [packed = true];
  1272. repeated SeqSmall0 packed_seq_small_0_midfield = 1003 [packed = true];
  1273. repeated SeqSmall0 packed_seq_small_0_hifield = 1000003 [packed = true];
  1274. enum SeqSmall1 {
  1275. SEQ_SMALL_1_DEFAULT = 1;
  1276. SEQ_SMALL_1_2 = 2;
  1277. SEQ_SMALL_1_3 = 3;
  1278. };
  1279. optional SeqSmall1 optional_seq_small_1_lowfield = 4;
  1280. optional SeqSmall1 optional_seq_small_1_midfield = 1004;
  1281. optional SeqSmall1 optional_seq_small_1_hifield = 1000004;
  1282. repeated SeqSmall1 repeated_seq_small_1_lowfield = 5;
  1283. repeated SeqSmall1 repeated_seq_small_1_midfield = 1005;
  1284. repeated SeqSmall1 repeated_seq_small_1_hifield = 1000005;
  1285. repeated SeqSmall1 packed_seq_small_1_lowfield = 6 [packed = true];
  1286. repeated SeqSmall1 packed_seq_small_1_midfield = 1006 [packed = true];
  1287. repeated SeqSmall1 packed_seq_small_1_hifield = 1000006 [packed = true];
  1288. enum SeqLarge {
  1289. SEQ_LARGE_DEFAULT = -1;
  1290. SEQ_LARGE_0 = 0;
  1291. SEQ_LARGE_1 = 1;
  1292. SEQ_LARGE_2 = 2;
  1293. SEQ_LARGE_3 = 3;
  1294. SEQ_LARGE_4 = 4;
  1295. SEQ_LARGE_5 = 5;
  1296. SEQ_LARGE_6 = 6;
  1297. SEQ_LARGE_7 = 7;
  1298. SEQ_LARGE_8 = 8;
  1299. SEQ_LARGE_9 = 9;
  1300. SEQ_LARGE_10 = 10;
  1301. SEQ_LARGE_11 = 11;
  1302. SEQ_LARGE_12 = 12;
  1303. SEQ_LARGE_13 = 13;
  1304. SEQ_LARGE_14 = 14;
  1305. SEQ_LARGE_15 = 15;
  1306. SEQ_LARGE_16 = 16;
  1307. SEQ_LARGE_17 = 17;
  1308. SEQ_LARGE_18 = 18;
  1309. SEQ_LARGE_19 = 19;
  1310. SEQ_LARGE_20 = 20;
  1311. SEQ_LARGE_21 = 21;
  1312. SEQ_LARGE_22 = 22;
  1313. SEQ_LARGE_23 = 23;
  1314. SEQ_LARGE_24 = 24;
  1315. SEQ_LARGE_25 = 25;
  1316. SEQ_LARGE_26 = 26;
  1317. SEQ_LARGE_27 = 27;
  1318. SEQ_LARGE_28 = 28;
  1319. SEQ_LARGE_29 = 29;
  1320. SEQ_LARGE_30 = 30;
  1321. SEQ_LARGE_31 = 31;
  1322. SEQ_LARGE_32 = 32;
  1323. SEQ_LARGE_33 = 33;
  1324. };
  1325. optional SeqLarge optional_seq_large_lowfield = 7;
  1326. optional SeqLarge optional_seq_large_midfield = 1007;
  1327. optional SeqLarge optional_seq_large_hifield = 1000007;
  1328. repeated SeqLarge repeated_seq_large_lowfield = 8;
  1329. repeated SeqLarge repeated_seq_large_midfield = 1008;
  1330. repeated SeqLarge repeated_seq_large_hifield = 1000008;
  1331. repeated SeqLarge packed_seq_large_lowfield = 9 [packed = true];
  1332. repeated SeqLarge packed_seq_large_midfield = 1009 [packed = true];
  1333. repeated SeqLarge packed_seq_large_hifield = 1000009 [packed = true];
  1334. enum Arbitrary {
  1335. ARBITRARY_DEFAULT = -123123;
  1336. ARBITRARY_1 = -123;
  1337. ARBITRARY_2 = 213;
  1338. ARBITRARY_3 = 213213;
  1339. ARBITRARY_MIN = -2147483648;
  1340. ARBITRARY_MAX = 2147483647;
  1341. };
  1342. optional Arbitrary optional_arbitrary_lowfield = 10;
  1343. optional Arbitrary optional_arbitrary_midfield = 1010;
  1344. optional Arbitrary optional_arbitrary_hifield = 1000010;
  1345. repeated Arbitrary repeated_arbitrary_lowfield = 11;
  1346. repeated Arbitrary repeated_arbitrary_midfield = 1011;
  1347. repeated Arbitrary repeated_arbitrary_hifield = 1000011;
  1348. repeated Arbitrary packed_arbitrary_lowfield = 12 [packed = true];
  1349. repeated Arbitrary packed_arbitrary_midfield = 1012 [packed = true];
  1350. repeated Arbitrary packed_arbitrary_hifield = 1000012 [packed = true];
  1351. // An arbitrary field we can append to to break the runs of repeated fields.
  1352. optional int32 other_field = 99;
  1353. };
  1354. // This message contains different kind of bool fields to exercise the different
  1355. // parsers in table-drived.
  1356. message BoolParseTester {
  1357. optional bool optional_bool_lowfield = 1;
  1358. optional bool optional_bool_midfield = 1001;
  1359. optional bool optional_bool_hifield = 1000001;
  1360. repeated bool repeated_bool_lowfield = 2;
  1361. repeated bool repeated_bool_midfield = 1002;
  1362. repeated bool repeated_bool_hifield = 1000002;
  1363. repeated bool packed_bool_lowfield = 3 [packed = true];
  1364. repeated bool packed_bool_midfield = 1003 [packed = true];
  1365. repeated bool packed_bool_hifield = 1000003 [packed = true];
  1366. // An arbitrary field we can append to to break the runs of repeated fields.
  1367. optional int32 other_field = 99;
  1368. };
  1369. message Int32ParseTester {
  1370. optional int32 optional_int32_lowfield = 1;
  1371. optional int32 optional_int32_midfield = 1001;
  1372. optional int32 optional_int32_hifield = 1000001;
  1373. repeated int32 repeated_int32_lowfield = 2;
  1374. repeated int32 repeated_int32_midfield = 1002;
  1375. repeated int32 repeated_int32_hifield = 1000002;
  1376. repeated int32 packed_int32_lowfield = 3 [packed = true];
  1377. repeated int32 packed_int32_midfield = 1003 [packed = true];
  1378. repeated int32 packed_int32_hifield = 1000003 [packed = true];
  1379. // An arbitrary field we can append to to break the runs of repeated fields.
  1380. optional int32 other_field = 99;
  1381. };
  1382. message Int64ParseTester {
  1383. optional int64 optional_int64_lowfield = 1;
  1384. optional int64 optional_int64_midfield = 1001;
  1385. optional int64 optional_int64_hifield = 1000001;
  1386. repeated int64 repeated_int64_lowfield = 2;
  1387. repeated int64 repeated_int64_midfield = 1002;
  1388. repeated int64 repeated_int64_hifield = 1000002;
  1389. repeated int64 packed_int64_lowfield = 3 [packed = true];
  1390. repeated int64 packed_int64_midfield = 1003 [packed = true];
  1391. repeated int64 packed_int64_hifield = 1000003 [packed = true];
  1392. // An arbitrary field we can append to to break the runs of repeated fields.
  1393. optional int32 other_field = 99;
  1394. };
  1395. message StringParseTester {
  1396. optional string optional_string_lowfield = 1;
  1397. optional string optional_string_midfield = 1001;
  1398. optional string optional_string_hifield = 1000001;
  1399. repeated string repeated_string_lowfield = 2;
  1400. repeated string repeated_string_midfield = 1002;
  1401. repeated string repeated_string_hifield = 1000002;
  1402. };
  1403. message BadFieldNames{
  1404. optional int32 OptionalInt32 = 1;
  1405. optional int32 for = 2;
  1406. }
  1407. message RedactedFields{
  1408. optional string optional_redacted_string = 1 [debug_redact = true];
  1409. }