• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Protocol Buffers - Google's data interchange format
2// Copyright 2008 Google Inc.  All rights reserved.
3//
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file or at
6// https://developers.google.com/open-source/licenses/bsd
7
8// Author: kenton@google.com (Kenton Varda)
9//
10// This is like unittest.proto but with optimize_for = LITE_RUNTIME.
11
12edition = "2023";
13
14package protobuf_unittest;
15
16import "google/protobuf/unittest_import_lite.proto";
17
18option features.enum_type = CLOSED;
19option features.repeated_field_encoding = EXPANDED;
20option features.utf8_validation = NONE;
21option cc_enable_arenas = true;
22option optimize_for = LITE_RUNTIME;
23option java_package = "com.google.protobuf";
24
25// Same as TestAllTypes but with the lite runtime.
26message TestAllTypesLite {
27  message NestedMessage {
28    int32 bb = 1;
29    int64 cc = 2;
30    repeated int32 dd = 3 [features.repeated_field_encoding = PACKED];
31  }
32
33  message NestedMessage2 {
34    int32 dd = 1;
35  }
36
37  enum NestedEnum {
38    FOO = 1;
39    BAR = 2;
40    BAZ = 3;
41  }
42
43  // Singular
44  int32 optional_int32 = 1;
45  int64 optional_int64 = 2;
46  uint32 optional_uint32 = 3;
47  uint64 optional_uint64 = 4;
48  sint32 optional_sint32 = 5;
49  sint64 optional_sint64 = 6;
50  fixed32 optional_fixed32 = 7;
51  fixed64 optional_fixed64 = 8;
52  sfixed32 optional_sfixed32 = 9;
53  sfixed64 optional_sfixed64 = 10;
54  float optional_float = 11;
55  double optional_double = 12;
56  bool optional_bool = 13;
57  string optional_string = 14;
58  bytes optional_bytes = 15;
59
60  message OptionalGroup {
61    int32 a = 17;
62  }
63
64  OptionalGroup optionalgroup = 16 [features.message_encoding = DELIMITED];
65
66  NestedMessage optional_nested_message = 18;
67  ForeignMessageLite optional_foreign_message = 19;
68  protobuf_unittest_import.ImportMessageLite optional_import_message = 20;
69  NestedEnum optional_nested_enum = 21;
70  ForeignEnumLite optional_foreign_enum = 22;
71  protobuf_unittest_import.ImportEnumLite optional_import_enum = 23;
72  string optional_string_piece = 24 [ctype = STRING_PIECE];
73
74  string optional_cord = 25 [ctype = CORD];
75  bytes optional_bytes_cord = 86 [ctype = CORD];
76
77  // Defined in unittest_import_public.proto
78  protobuf_unittest_import.PublicImportMessageLite
79      optional_public_import_message = 26;
80  NestedMessage optional_lazy_message = 27 [lazy = true];
81
82  NestedMessage optional_unverified_lazy_message = 28 [unverified_lazy = true];
83
84  // Repeated
85  repeated int32 repeated_int32 = 31;
86  repeated int64 repeated_int64 = 32;
87  repeated uint32 repeated_uint32 = 33;
88  repeated uint64 repeated_uint64 = 34;
89  repeated sint32 repeated_sint32 = 35;
90  repeated sint64 repeated_sint64 = 36;
91  repeated fixed32 repeated_fixed32 = 37;
92  repeated fixed64 repeated_fixed64 = 38;
93  repeated sfixed32 repeated_sfixed32 = 39;
94  repeated sfixed64 repeated_sfixed64 = 40;
95  repeated float repeated_float = 41;
96  repeated double repeated_double = 42;
97  repeated bool repeated_bool = 43;
98  repeated string repeated_string = 44;
99  repeated bytes repeated_bytes = 45;
100
101  message RepeatedGroup {
102    int32 a = 47;
103  }
104
105  repeated RepeatedGroup repeatedgroup = 46
106      [features.message_encoding = DELIMITED];
107
108  repeated NestedMessage repeated_nested_message = 48;
109  repeated ForeignMessageLite repeated_foreign_message = 49;
110  repeated protobuf_unittest_import.ImportMessageLite repeated_import_message =
111      50;
112  repeated NestedEnum repeated_nested_enum = 51;
113  repeated ForeignEnumLite repeated_foreign_enum = 52;
114  repeated protobuf_unittest_import.ImportEnumLite repeated_import_enum = 53;
115  repeated string repeated_string_piece = 54 [ctype = STRING_PIECE];
116
117  repeated string repeated_cord = 55 [ctype = CORD];
118
119  repeated NestedMessage repeated_lazy_message = 57;
120
121  // Singular with defaults
122  int32 default_int32 = 61 [default = 41];
123
124  int64 default_int64 = 62 [default = 42];
125
126  uint32 default_uint32 = 63 [default = 43];
127
128  uint64 default_uint64 = 64 [default = 44];
129
130  sint32 default_sint32 = 65 [default = -45];
131
132  sint64 default_sint64 = 66 [default = 46];
133
134  fixed32 default_fixed32 = 67 [default = 47];
135
136  fixed64 default_fixed64 = 68 [default = 48];
137
138  sfixed32 default_sfixed32 = 69 [default = 49];
139
140  sfixed64 default_sfixed64 = 70 [default = -50];
141
142  float default_float = 71 [default = 51.5];
143
144  double default_double = 72 [default = 5.2e4];
145
146  bool default_bool = 73 [default = true];
147
148  string default_string = 74 [default = "hello"];
149
150  bytes default_bytes = 75 [default = "world"];
151
152  NestedEnum default_nested_enum = 81 [default = BAR];
153
154  ForeignEnumLite default_foreign_enum = 82 [default = FOREIGN_LITE_BAR];
155
156  protobuf_unittest_import.ImportEnumLite default_import_enum = 83
157      [default = IMPORT_LITE_BAR];
158
159  string default_string_piece = 84 [ctype = STRING_PIECE, default = "abc"];
160
161  string default_cord = 85 [ctype = CORD, default = "123"];
162
163  // For oneof test
164  oneof oneof_field {
165    uint32 oneof_uint32 = 111;
166    NestedMessage oneof_nested_message = 112;
167    string oneof_string = 113;
168    bytes oneof_bytes = 114;
169    NestedMessage oneof_lazy_nested_message = 115 [lazy = true];
170
171    NestedMessage2 oneof_nested_message2 = 117;
172  }
173
174  // Tests toString for non-repeated fields with a list suffix
175  int32 deceptively_named_list = 116;
176}
177
178message ForeignMessageLite {
179  int32 c = 1;
180}
181
182enum ForeignEnumLite {
183  FOREIGN_LITE_FOO = 4;
184  FOREIGN_LITE_BAZ = 6;
185  FOREIGN_LITE_BAR = 5;
186}
187
188message TestPackedTypesLite {
189  repeated int32 packed_int32 = 90 [features.repeated_field_encoding = PACKED];
190
191  repeated int64 packed_int64 = 91 [features.repeated_field_encoding = PACKED];
192
193  repeated uint32 packed_uint32 = 92
194      [features.repeated_field_encoding = PACKED];
195
196  repeated uint64 packed_uint64 = 93
197      [features.repeated_field_encoding = PACKED];
198
199  repeated sint32 packed_sint32 = 94
200      [features.repeated_field_encoding = PACKED];
201
202  repeated sint64 packed_sint64 = 95
203      [features.repeated_field_encoding = PACKED];
204
205  repeated fixed32 packed_fixed32 = 96
206      [features.repeated_field_encoding = PACKED];
207
208  repeated fixed64 packed_fixed64 = 97
209      [features.repeated_field_encoding = PACKED];
210
211  repeated sfixed32 packed_sfixed32 = 98
212      [features.repeated_field_encoding = PACKED];
213
214  repeated sfixed64 packed_sfixed64 = 99
215      [features.repeated_field_encoding = PACKED];
216
217  repeated float packed_float = 100 [features.repeated_field_encoding = PACKED];
218
219  repeated double packed_double = 101
220      [features.repeated_field_encoding = PACKED];
221
222  repeated bool packed_bool = 102 [features.repeated_field_encoding = PACKED];
223
224  repeated ForeignEnumLite packed_enum = 103
225      [features.repeated_field_encoding = PACKED];
226}
227
228message TestAllExtensionsLite {
229  extensions 1 to max;
230}
231
232extend TestAllExtensionsLite {
233  // Singular
234  int32 optional_int32_extension_lite = 1;
235  int64 optional_int64_extension_lite = 2;
236  uint32 optional_uint32_extension_lite = 3;
237  uint64 optional_uint64_extension_lite = 4;
238  sint32 optional_sint32_extension_lite = 5;
239  sint64 optional_sint64_extension_lite = 6;
240  fixed32 optional_fixed32_extension_lite = 7;
241  fixed64 optional_fixed64_extension_lite = 8;
242  sfixed32 optional_sfixed32_extension_lite = 9;
243  sfixed64 optional_sfixed64_extension_lite = 10;
244  float optional_float_extension_lite = 11;
245  double optional_double_extension_lite = 12;
246  bool optional_bool_extension_lite = 13;
247  string optional_string_extension_lite = 14;
248  bytes optional_bytes_extension_lite = 15;
249  OptionalGroup_extension_lite optionalgroup_extension_lite = 16
250      [features.message_encoding = DELIMITED];
251
252  TestAllTypesLite.NestedMessage optional_nested_message_extension_lite = 18;
253  ForeignMessageLite optional_foreign_message_extension_lite = 19;
254  protobuf_unittest_import.ImportMessageLite
255      optional_import_message_extension_lite = 20;
256  TestAllTypesLite.NestedEnum optional_nested_enum_extension_lite = 21;
257  ForeignEnumLite optional_foreign_enum_extension_lite = 22;
258  protobuf_unittest_import.ImportEnumLite optional_import_enum_extension_lite =
259      23;
260  string optional_string_piece_extension_lite = 24 [ctype = STRING_PIECE];
261
262  // TODO: ctype=CORD is not supported for extension. Add
263  // ctype=CORD option back after it is supported.
264  string optional_cord_extension_lite = 25;
265  bytes optional_bytes_cord_extension_lite = 86;
266  protobuf_unittest_import.PublicImportMessageLite
267      optional_public_import_message_extension_lite = 26;
268  TestAllTypesLite.NestedMessage optional_lazy_message_extension_lite = 27
269      [lazy = true];
270
271  TestAllTypesLite.NestedMessage
272      optional_unverified_lazy_message_extension_lite = 28
273      [unverified_lazy = true];
274
275  // Repeated
276  repeated int32 repeated_int32_extension_lite = 31;
277  repeated int64 repeated_int64_extension_lite = 32;
278  repeated uint32 repeated_uint32_extension_lite = 33;
279  repeated uint64 repeated_uint64_extension_lite = 34;
280  repeated sint32 repeated_sint32_extension_lite = 35;
281  repeated sint64 repeated_sint64_extension_lite = 36;
282  repeated fixed32 repeated_fixed32_extension_lite = 37;
283  repeated fixed64 repeated_fixed64_extension_lite = 38;
284  repeated sfixed32 repeated_sfixed32_extension_lite = 39;
285  repeated sfixed64 repeated_sfixed64_extension_lite = 40;
286  repeated float repeated_float_extension_lite = 41;
287  repeated double repeated_double_extension_lite = 42;
288  repeated bool repeated_bool_extension_lite = 43;
289  repeated string repeated_string_extension_lite = 44;
290  repeated bytes repeated_bytes_extension_lite = 45;
291  repeated RepeatedGroup_extension_lite repeatedgroup_extension_lite = 46
292      [features.message_encoding = DELIMITED];
293
294  repeated TestAllTypesLite.NestedMessage
295      repeated_nested_message_extension_lite = 48;
296  repeated ForeignMessageLite repeated_foreign_message_extension_lite = 49;
297  repeated protobuf_unittest_import.ImportMessageLite
298      repeated_import_message_extension_lite = 50;
299  repeated TestAllTypesLite.NestedEnum repeated_nested_enum_extension_lite = 51;
300  repeated ForeignEnumLite repeated_foreign_enum_extension_lite = 52;
301  repeated protobuf_unittest_import.ImportEnumLite
302      repeated_import_enum_extension_lite = 53;
303  repeated string repeated_string_piece_extension_lite = 54
304      [ctype = STRING_PIECE];
305
306  // TODO: ctype=CORD is not supported for extension. Add
307  // ctype=CORD option back after it is supported.
308  repeated string repeated_cord_extension_lite = 55;
309  repeated TestAllTypesLite.NestedMessage repeated_lazy_message_extension_lite =
310      57 [lazy = true];
311
312  // Singular with defaults
313  int32 default_int32_extension_lite = 61 [default = 41];
314
315  int64 default_int64_extension_lite = 62 [default = 42];
316
317  uint32 default_uint32_extension_lite = 63 [default = 43];
318
319  uint64 default_uint64_extension_lite = 64 [default = 44];
320
321  sint32 default_sint32_extension_lite = 65 [default = -45];
322
323  sint64 default_sint64_extension_lite = 66 [default = 46];
324
325  fixed32 default_fixed32_extension_lite = 67 [default = 47];
326
327  fixed64 default_fixed64_extension_lite = 68 [default = 48];
328
329  sfixed32 default_sfixed32_extension_lite = 69 [default = 49];
330
331  sfixed64 default_sfixed64_extension_lite = 70 [default = -50];
332
333  float default_float_extension_lite = 71 [default = 51.5];
334
335  double default_double_extension_lite = 72 [default = 5.2e4];
336
337  bool default_bool_extension_lite = 73 [default = true];
338
339  string default_string_extension_lite = 74 [default = "hello"];
340
341  bytes default_bytes_extension_lite = 75 [default = "world"];
342
343  TestAllTypesLite.NestedEnum default_nested_enum_extension_lite = 81
344      [default = BAR];
345
346  ForeignEnumLite default_foreign_enum_extension_lite = 82
347      [default = FOREIGN_LITE_BAR];
348
349  protobuf_unittest_import.ImportEnumLite default_import_enum_extension_lite = 83
350      [default = IMPORT_LITE_BAR];
351
352  string default_string_piece_extension_lite = 84
353      [ctype = STRING_PIECE, default = "abc"];
354
355  // TODO: ctype=CORD is not supported for extension. Add
356  // ctype=CORD option back after it is supported.
357  string default_cord_extension_lite = 85 [default = "123"];
358
359  // For oneof test
360  uint32 oneof_uint32_extension_lite = 111;
361  TestAllTypesLite.NestedMessage oneof_nested_message_extension_lite = 112;
362  string oneof_string_extension_lite = 113;
363  bytes oneof_bytes_extension_lite = 114;
364}
365
366message OptionalGroup_extension_lite {
367  int32 a = 17;
368}
369
370message RepeatedGroup_extension_lite {
371  int32 a = 47;
372}
373
374message TestPackedExtensionsLite {
375  extensions 1 to max;
376}
377
378extend TestPackedExtensionsLite {
379  repeated int32 packed_int32_extension_lite = 90
380      [features.repeated_field_encoding = PACKED];
381
382  repeated int64 packed_int64_extension_lite = 91
383      [features.repeated_field_encoding = PACKED];
384
385  repeated uint32 packed_uint32_extension_lite = 92
386      [features.repeated_field_encoding = PACKED];
387
388  repeated uint64 packed_uint64_extension_lite = 93
389      [features.repeated_field_encoding = PACKED];
390
391  repeated sint32 packed_sint32_extension_lite = 94
392      [features.repeated_field_encoding = PACKED];
393
394  repeated sint64 packed_sint64_extension_lite = 95
395      [features.repeated_field_encoding = PACKED];
396
397  repeated fixed32 packed_fixed32_extension_lite = 96
398      [features.repeated_field_encoding = PACKED];
399
400  repeated fixed64 packed_fixed64_extension_lite = 97
401      [features.repeated_field_encoding = PACKED];
402
403  repeated sfixed32 packed_sfixed32_extension_lite = 98
404      [features.repeated_field_encoding = PACKED];
405
406  repeated sfixed64 packed_sfixed64_extension_lite = 99
407      [features.repeated_field_encoding = PACKED];
408
409  repeated float packed_float_extension_lite = 100
410      [features.repeated_field_encoding = PACKED];
411
412  repeated double packed_double_extension_lite = 101
413      [features.repeated_field_encoding = PACKED];
414
415  repeated bool packed_bool_extension_lite = 102
416      [features.repeated_field_encoding = PACKED];
417
418  repeated ForeignEnumLite packed_enum_extension_lite = 103
419      [features.repeated_field_encoding = PACKED];
420}
421
422message TestNestedExtensionLite {
423  extend TestAllExtensionsLite {
424    int32 nested_extension = 12345;
425  }
426}
427
428// Test that deprecated fields work.  We only verify that they compile (at one
429// point this failed).
430message TestDeprecatedLite {
431  int32 deprecated_field = 1 [deprecated = true];
432
433  int32 deprecated_field2 = 2
434      [features.field_presence = LEGACY_REQUIRED, deprecated = true];
435
436  string deprecated_field3 = 3 [deprecated = true];
437
438  TestDeprecatedLite deprecated_field4 = 4 [deprecated = true];
439}
440
441// See the comments of the same type in unittest.proto.
442message TestParsingMergeLite {
443  message RepeatedFieldsGenerator {
444    repeated TestAllTypesLite field1 = 1;
445    repeated TestAllTypesLite field2 = 2;
446    repeated TestAllTypesLite field3 = 3;
447
448    message Group1 {
449      TestAllTypesLite field1 = 11;
450    }
451
452    repeated Group1 group1 = 10 [features.message_encoding = DELIMITED];
453
454    message Group2 {
455      TestAllTypesLite field1 = 21;
456    }
457
458    repeated Group2 group2 = 20 [features.message_encoding = DELIMITED];
459
460    repeated TestAllTypesLite ext1 = 1000;
461    repeated TestAllTypesLite ext2 = 1001;
462  }
463
464  TestAllTypesLite required_all_types = 1
465      [features.field_presence = LEGACY_REQUIRED];
466
467  TestAllTypesLite optional_all_types = 2;
468  repeated TestAllTypesLite repeated_all_types = 3;
469
470  message OptionalGroup {
471    TestAllTypesLite optional_group_all_types = 11;
472  }
473
474  OptionalGroup optionalgroup = 10 [features.message_encoding = DELIMITED];
475
476  message RepeatedGroup {
477    TestAllTypesLite repeated_group_all_types = 21;
478  }
479
480  repeated RepeatedGroup repeatedgroup = 20
481      [features.message_encoding = DELIMITED];
482
483  extensions 1000 to max;
484
485  extend TestParsingMergeLite {
486    TestAllTypesLite optional_ext = 1000;
487    repeated TestAllTypesLite repeated_ext = 1001;
488  }
489}
490
491// Test that the correct exception is thrown by parseFrom in a corner case
492// involving merging, extensions, and required fields.
493message TestMergeExceptionLite {
494  TestAllExtensionsLite all_extensions = 1;
495}
496
497// TestEmptyMessageLite is used to test unknown fields support in lite mode.
498message TestEmptyMessageLite {}
499
500// Like above, but declare all field numbers as potential extensions.  No
501// actual extensions should ever be defined for this type.
502message TestEmptyMessageWithExtensionsLite {
503  extensions 1 to max;
504}
505
506enum V1EnumLite {
507  V1_FIRST = 1;
508}
509
510enum V2EnumLite {
511  V2_FIRST = 1;
512  V2_SECOND = 2;
513}
514
515message V1MessageLite {
516  int32 int_field = 1 [features.field_presence = LEGACY_REQUIRED];
517
518  V1EnumLite enum_field = 2 [default = V1_FIRST];
519}
520
521message V2MessageLite {
522  int32 int_field = 1 [features.field_presence = LEGACY_REQUIRED];
523
524  V2EnumLite enum_field = 2 [default = V2_FIRST];
525}
526
527message TestHugeFieldNumbersLite {
528  int32 optional_int32 = 536870000;
529  int32 fixed_32 = 536870001;
530  repeated int32 repeated_int32 = 536870002;
531  repeated int32 packed_int32 = 536870003
532      [features.repeated_field_encoding = PACKED];
533
534  ForeignEnumLite optional_enum = 536870004;
535  string optional_string = 536870005;
536  bytes optional_bytes = 536870006;
537  ForeignMessageLite optional_message = 536870007;
538
539  message OptionalGroup {
540    int32 group_a = 536870009;
541  }
542
543  OptionalGroup optionalgroup = 536870008
544      [features.message_encoding = DELIMITED];
545
546  map<string, string> string_string_map = 536870010;
547
548  oneof oneof_field {
549    uint32 oneof_uint32 = 536870011;
550    TestAllTypesLite oneof_test_all_types = 536870012;
551    string oneof_string = 536870013;
552    bytes oneof_bytes = 536870014;
553  }
554
555  extensions 536860000 to 536869999 [declaration = {
556    number: 536860000
557    full_name: ".protobuf_unittest.test_all_types_lite"
558    type: ".protobuf_unittest.TestAllTypesLite"
559  }];
560}
561
562extend TestHugeFieldNumbersLite {
563  TestAllTypesLite test_all_types_lite = 536860000;
564}
565
566message TestOneofParsingLite {
567  oneof oneof_field {
568    int32 oneof_int32 = 1;
569    TestAllTypesLite oneof_submessage = 2;
570    string oneof_string = 3;
571    bytes oneof_bytes = 4 [default = "default bytes"];
572
573    string oneof_string_cord = 5 [ctype = CORD, default = "default Cord"];
574
575    bytes oneof_bytes_cord = 6 [ctype = CORD];
576
577    string oneof_string_string_piece = 7 [ctype = STRING_PIECE];
578
579    bytes oneof_bytes_string_piece = 8
580        [ctype = STRING_PIECE, default = "default StringPiece"];
581
582    V2EnumLite oneof_enum = 9;
583  }
584}
585
586message TestMessageSetLite {
587  option message_set_wire_format = true;
588
589  extensions 100 to max;
590}
591
592// The following four messages are set up to test for wire compatibility between
593// packed and non-packed repeated fields. We use the field number 2048, because
594// that is large enough to require a 3-byte varint for the tag.
595message PackedInt32 {
596  repeated int32 repeated_int32 = 2048
597      [features.repeated_field_encoding = PACKED];
598}
599
600message NonPackedInt32 {
601  repeated int32 repeated_int32 = 2048;
602}
603
604message PackedFixed32 {
605  repeated fixed32 repeated_fixed32 = 2048
606      [features.repeated_field_encoding = PACKED];
607}
608
609message NonPackedFixed32 {
610  repeated fixed32 repeated_fixed32 = 2048;
611}
612
613// Test an enum that has multiple values with the same number.
614message DupEnum {
615  enum TestEnumWithDupValueLite {
616    option allow_alias = true;
617
618    FOO1 = 1;
619    BAR1 = 2;
620    BAZ = 3;
621    FOO2 = 1;
622    BAR2 = 2;
623  }
624}
625
626message RecursiveMessage {
627  RecursiveMessage recurse = 1;
628  bytes payload = 2;
629}
630
631message RecursiveGroup {
632  RecursiveGroup recurse = 1 [features.message_encoding = DELIMITED];
633}
634